0

当我尝试使用 UUID 字段映射类时出现以下异常。日期类型的字段也是如此。我的实体需要具有这些值的字段,有什么可能的解决方案?

java.lang.RuntimeException: Failure scanning class(see chained exception)=class com.s1mbi0se.dmp.da.bean.User
    at com.alvazan.orm.layer0.base.MyClassAnnotationDiscoveryListener.scanClass(MyClassAnnotationDiscoveryListener.java:44)
    at com.alvazan.orm.layer0.base.BaseEntityManagerFactoryImpl.rescan(BaseEntityManagerFactoryImpl.java:83)
    at com.alvazan.orm.layer0.base.BaseEntityManagerFactoryImpl.setup(BaseEntityManagerFactoryImpl.java:131)
    at com.alvazan.orm.impl.bindings.BootstrapImpl.createInstance(BootstrapImpl.java:51)
    at com.alvazan.orm.api.base.Bootstrap.create(Bootstrap.java:53)
    at com.alvazan.orm.api.base.Bootstrap.create(Bootstrap.java:48)
    at com.alvazan.orm.api.base.Bootstrap.create(Bootstrap.java:45)
    at com.alvazan.orm.api.base.Bootstrap.create(Bootstrap.java:41)
    at com.s1mbi0se.dmp.da.dao.PlayOrmConfiguration.init(PlayOrmConfiguration.java:39)
    at com.s1mbi0se.dmp.da.dao.TestUserDao.testUserOperations(TestUserDao.java:18)
    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:601)
    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.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: java.lang.RuntimeException: Failure scanning field=private java.util.Date com.s1mbi0se.dmp.da.bean.User.birthDate for class=User
    at com.alvazan.orm.impl.meta.scan.ScannerForClass.inspectField(ScannerForClass.java:179)
    at com.alvazan.orm.impl.meta.scan.ScannerForClass.scanFields(ScannerForClass.java:172)
    at com.alvazan.orm.impl.meta.scan.ScannerForClass.scanSingle(ScannerForClass.java:111)
    at com.alvazan.orm.impl.meta.scan.ScannerForClass.addClass(ScannerForClass.java:67)
    at com.alvazan.orm.layer0.base.MyClassAnnotationDiscoveryListener.scanClass(MyClassAnnotationDiscoveryListener.java:42)
    ... 32 more
Caused by: java.lang.IllegalArgumentException: No converter found for field='birthDate' in class=class com.s1mbi0se.dmp.da.bean.User.  You need to either add one of the @*ToOne annotations, @Embedded, @Transient or add your own converter calling EntityMgrFactory.setup(Map<Class, Converter>) which will then work for all fields of that type OR add @Column(customConverter=YourConverter.class) or finally if we missed a standard converter, we need to add it in file InspectorField.java in the constructor and it is trivial code(and we can copy the existing pattern)
    at com.alvazan.orm.impl.meta.scan.ScannerForField.processColumn(ScannerForField.java:173)
    at com.alvazan.orm.impl.meta.scan.ScannerForClass.inspectFieldImpl(ScannerForClass.java:205)
    at com.alvazan.orm.impl.meta.scan.ScannerForClass.inspectField(ScannerForClass.java:177)
    ... 36 more
4

2 回答 2

1

对于日期,我们使用 joda-time,因为日期和日历非常有问题。Jdk7 应该集成 joda-time,因为它修复了所有错误。您可以使用 LocalDate 和 LocalDateTime 等。

对于任何东西,您都可以添加自己的转换器。第一次通过Bootstrap创建NoSqlEntityManagerFactory时,有一个Map

public synchronized static NoSqlEntityManagerFactory create(DbTypeEnum type, Map<String, Object> properties, Map<Class, Converter> converters, ClassLoader cl)

那里要填写的重要地图是

Map<Class, Converter> converters

您可以提供 Class=Date.class 和 Converter=new YourConverterForDate()

您也可以为 UUID 提供一个。如果我们在转换器的标准映射中找不到转换器,则使用此转换器映射。同时,为 Date 和 TimeUUID 打开两个问题,我将添加它们。另外,请注意 java 的 TimeUUID,因为它不是 X 类型(我不记得 X 应该是 1 还是 4),这使得它不是唯一的:(.....还有另一个创建唯一 TimeUUID 的 java 库在网上....等我有空的时候再看看。

院长

于 2012-10-17T22:45:45.920 回答
0

Playorm 的 1.4.1 版本现在支持 UUID (com.eaio.uuid)。

https://github.com/deanhiller/playorm/wiki/Release-details

于 2012-11-09T07:11:33.053 回答