OpenJPA中是否可以有String ID?
当我查看文档时,它看起来像是可能的,但是当我尝试时,我得到了这个例外:
the given value "86272843-bb2b-4dd4-bb98-11195bbcf04f" cannot be converted into an identity for "class com.dooapp.infiltrea.model.SimpleEntity". The value is the wrong type (java.lang.String).
<openjpa-2.1.1-r422266:1148538 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: The given value "86272843-bb2b-4dd4-bb98-11195bbcf04f" cannot be converted into an identity for "class com.dooapp.infiltrea.model.SimpleEntity". The value is the wrong type (java.lang.String).
at org.apache.openjpa.kernel.BrokerImpl.newObjectId(BrokerImpl.java:1278)
at org.apache.openjpa.kernel.DelegatingBroker.newObjectId(DelegatingBroker.java:316)
at org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:485)
at com.dooapp.infiltrea.model.io.ManagerIOImpl.read(ManagerIOImpl.java:112)
at com.dooapp.infiltrea.model.io.ManagerIOTest.testDelete(ManagerIOTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: java.lang.NumberFormatException: For input string: "bb2b-4dd4-bb98-11195bbcf04f"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Long.parseLong(Long.java:410)
at java.lang.Long.parseLong(Long.java:468)
at org.apache.openjpa.util.Id.<init>(Id.java:109)
at org.apache.openjpa.util.Id.newInstance(Id.java:48)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.newDataStoreId(JDBCStoreManager.java:808)
at org.apache.openjpa.kernel.DelegatingStoreManager.newDataStoreId(DelegatingStoreManager.java:156)
at org.apache.openjpa.kernel.BrokerImpl.newObjectId(BrokerImpl.java:1253)
我只是
@Id
String id;
@PrePersist
public void generateUUID() {
this.setId(UUID.randomUUID().toString());
}
当我删除String并将其放长时,它运行良好,但这不是我想要的。
这是JPA的错误,还是我做错了什么?
感谢的