- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在保存过程中,我收到 UnsupportedOperationException。我假设这是由于 lombok 正在创建不可变对象(immutable对象),因此在 build() 之后我们可以保存
这是我的类
@Entity
@Data
@Builder(toBuilder = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
@NoArgsConstructor
@AllArgsConstructor
public class Classroom {
@Id
@GeneratedValue
Long id;
String name;
@JsonIgnore
@OneToMany(cascade = CascadeType.ALL)
@Singular("words")
List<LanguageWord> words;
@Singular("tests")
@OneToMany(cascade = CascadeType.ALL)
List<Test> tests;
}
以下代码被剪断导致错误
public Test createAndSaveConfiguration(TestConfiguration config, Classroom classroom) {
Test test = createTest(config, classroom.getWords());
List<Test> tests = new ArrayList<>();
tests.add(test);
tests.addAll(classroom.getTests());
Classroom clazz = classroom.toBuilder().tests(tests).build();
classRepo.save(clazz);
return test;
}
波纹管是堆栈跟踪
java.lang.UnsupportedOperationException
at java.base/java.util.AbstractList.add(AbstractList.java:153)
at java.base/java.util.AbstractList.add(AbstractList.java:111)
at org.hibernate.collection.internal.PersistentBag.add(PersistentBag.java:324)
at org.hibernate.type.CollectionType.replaceElements(CollectionType.java:551)
at org.hibernate.type.CollectionType.replace(CollectionType.java:699)
at org.hibernate.type.TypeHelper.replace(TypeHelper.java:163)
at org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:393)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:327)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:170)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:901)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:887)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:308)
at com.sun.proxy.$Proxy114.merge(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:492)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy126.save(Unknown Source)
at org.owozniak.selfestem.language2.LanguageController.createAndSaveConfiguration(Unknown Source)
at org.owozniak.selfestem.language2.LanguageController.startTest(Unknown Source)
at org.owozniak.selfestem.language2.LanguageController$startTest$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at org.owozniak.selfestem.language2.LanguageControllerTest.$spock_feature_0_0(LanguageControllerTest.groovy:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
最佳答案
根据lombok builder documentation (@单数部分):
When invoking build(), the produced collection will be immutable.
换句话说,在 build() 对象之后,您无法从相应的带注释的集合中添加或删除元素,这打破了 hibernate 的期望
关于java - Spring Data JPA + Lombok = 保存期间出现 UnsupportedOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55090541/
我一直在开发搜索功能,该功能使我能够在 RecyclerView 中搜索数据。当我单击搜索图标时,我的应用程序崩溃了。经过一些调试后,我发现了问题,似乎无法清除信息或将信息添加到新列表。 Adapte
我已经创建了一个 ContainerRequestfilter 并成功触发了它。现在我想访问我之前在 grizzly HttpServerProbe 中设置的 UserPrincipal,如下所示:
我试图获取特定于区域设置的百分比符号。我的崩溃日志在尝试从 DecimalFormatSymbols 获取百分比时显示“UnsupportedOperationException”。 我使用给定区域设
我在下面编写了代码,我不知道出了什么问题,但 validDatesIterator.remove() 给了我 UnsupportedOperationException 异常。使用java 1.6 L
我正在尝试制作一个包含名称的列表。该列表应该是可修改的(添加、删除、排序等)。但是,每当我尝试更改 ArrayAdapter 中的项目时,程序都会崩溃,并出现 java.lang.Unsupporte
所以,我目前正在编写一个方法来迭代目录以及该目录内的所有目录: public static Set iterateDirectory(String dir){ Set children = n
我正在开发一个滑雪追踪器应用程序,但我在第一个任务上失败了:)秒表 这是我的服务: public class TrackerService extends Service { private
当运行以下代码时,我遇到一个异常,它简单地说:线程“LWJGL Application”中出现异常 java.lang.UnsupportedOperationException // Declare
这个问题已经有答案了: remove() on List created by Arrays.asList() throws UnsupportedOperationException (3 个回答)
String[] aArr = ...; String[] bArr = ...; List images = Arrays.asList(aArr); images.addA
我是 facebook sdk 的新手,所以我不太确定为什么会收到此错误。我已将其缩小到此部分: List permissions = session.getPermissions()
调用 add() 时出现 UnsupportedOperationException在以下代码中: Collection myClass = method(); MyClass newObject =
代码如下: private static Map> merge(Map> m1, Map> m2) { Map> mx = new HashMap>(); for (Entry> en
我有这个代码: public static String SelectRandomFromTemplate(String template,int count) { String[] split
所以其中一个方法的描述如下: public BasicLinkedList addToFront(T data) This operation is invalid for a sorted list
我正在使用 Grails 2.3.11 并使用 MongoDb 插件 mongodb:3.0.3。 我的代码是这样的: def home() { List abcs = ABC.list()
我正在尝试创建一个自定义 ListView 来保存自定义对象的 View ,在这种情况下,自定义对象将是 Data 类的实例 Java 代码如下: import android.app.ListAct
我不太明白在哪里可以抛出这个异常。 例如,我正在实现 Future接口(interface)并且不希望任何人调用该方法: Future#get(long, TimeUnit) . 那么,我可以直接扔掉
我有下面的示例代码: String[] patternArray = {"1","2","3"}; List patternCheck = Arrays.asList(patternArray); p
在研究 Collection API 时,我们发现某些方法(add、remove、...)可能会抛出 java.lang.UnsupportedOperationException 如果 Collec
我是一名优秀的程序员,十分优秀!