gpt4 book ai didi

javax.persistence.PersistenceException : org. hibernate.id.IdentifierGenerationException:

转载 作者:行者123 更新时间:2023-11-29 22:11:29 25 4
gpt4 key购买 nike

如何在BetRecordAgEBR中传递和设置ID?请帮助我:) 提前致谢。这是我遇到的唯一问题。 BetRecordAgEBR 类适用于使用 jpa 的数据库。

if ("GR".equals(dataType)) {
ByteArrayInputStream bis = new ByteArrayInputStream(
aw.getBytes());
StreamSource ss = new StreamSource(bis);
brElement = (JAXBElement<T>) jaxbUnmarshaller
.unmarshal(ss, BetRecordAgGR.class);

ret2 = brElement.getValue();
counter++;
if (counter > 100) {
return brList;
}
/*
*
* String uuid1 = java.util.UUID.randomUUID()
* .toString(); dataOpe.setEntityManager(em);
* ret2.setID(uuid1); dataOpe.add(ret2);
*/
brList.add((T) ret2);
System.out.println(brList);
}

异常(exception):

javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): us.kirin.bc.BetRecordAgGR
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881)
at us.kirin.bc.service.DataService.add(DataService.java:40)
at us.kirin.bc.service.AGServiceTest.BetHistoryAGIN(AGServiceTest.java:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): us.kirin.bc.BetRecordAgGR
at org.hibernate.id.Assigned.generate(Assigned.java:52)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:852)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:826)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:830)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875)
... 26 more

最佳答案

我将 ret2 更改为 BetRecordAgGR ret2;

  if ("GR".equals(dataType)) {
ByteArrayInputStream bis = new ByteArrayInputStream(
aw.getBytes());
StreamSource ss = new StreamSource(bis);
brElement = (JAXBElement<T>) jaxbUnmarshaller
.unmarshal(ss, BetRecordAgGR.class);

ret2= (BetRecordAgGR) brElement.getValue();
counter++;
if (counter > 100) {
return brList;
}

String uuid1 = java.util.UUID.randomUUID()
.toString();
ret2.setID(uuid1);
dataOpe.setEntityManager(em);
dataOpe.add(ret2);
brList.add((T) ret2);
System.out.println(brList);
}

关于javax.persistence.PersistenceException : org. hibernate.id.IdentifierGenerationException:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31603833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com