我有一个超级实体类,在我的EJB项目中定义了继承策略TABLE_PER_CLASS。我尝试使用EJB3Unit进行单元测试,但只是意识到EJB3Unit尚不支持继承策略TABLE_PER_CLASS。还有其他支持它的测试库吗?我试着谷歌但没有出现......
Testsuite: entity.DepartmentTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
------------- Standard Error -----------------
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/NetBeans/glassfish-3.1.1/glassfish/modules/weld-osgi-bundle.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Applications/NetBeans/glassfish-3.1.1/glassfish/modules/bean-validator.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: The requested version 1.5.10 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
------------- ---------------- ---------------
Null Test: Caused an ERROR
null
null
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
Caused by: java.lang.RuntimeException: Inheritance strategy TABLE_PER_CLASS not (yet) supported.
at com.bm.introspectors.EntityBeanIntrospector.processInheritance(EntityBeanIntrospector.java:475)
at com.bm.introspectors.EntityBeanIntrospector.processAnnotations(EntityBeanIntrospector.java:160)
at com.bm.introspectors.EntityBeanIntrospector.getEntityBeanIntrospector(EntityBeanIntrospector.java:90)
at com.bm.introspectors.relations.RelationPropertyResolver.findAttributeForRelationAtOtherSide(RelationPropertyResolver.java:67)
at com.bm.introspectors.AbstractPersistentClassIntrospector.processNonIdAnnotations(AbstractPersistentClassIntrospector.java:373)
at com.bm.introspectors.AbstractPersistentClassIntrospector.processAnnotations(AbstractPersistentClassIntrospector.java:254)
at com.bm.introspectors.AbstractPersistentClassIntrospector.processAccessTypeField(AbstractPersistentClassIntrospector.java:91)
at com.bm.introspectors.EntityBeanIntrospector.processAccessTypeField(EntityBeanIntrospector.java:177)
at com.bm.introspectors.EntityBeanIntrospector.processAnnotations(EntityBeanIntrospector.java:154)
at com.bm.introspectors.EntityBeanIntrospector.getEntityBeanIntrospector(EntityBeanIntrospector.java:90)
at com.bm.datagen.relation.BeanCollectionGenerator.<init>(BeanCollectionGenerator.java:94)
at entity.DepartmentTest$MyEmoloyeeCreator.<init>(DepartmentTest.java:30)
at entity.DepartmentTest$MyEmoloyeeCreator.<init>(DepartmentTest.java:27)
at entity.DepartmentTest.<clinit>(DepartmentTest.java:19)
Test entity.DepartmentTest FAILED
test:
Deleting: /var/folders/xb/xbJfmQ0UGrCP0lmSoZFT4E+++TI/-Tmp-/TEST-entity.DepartmentTest.xml
BUILD SUCCESSFUL (total time: 8 seconds)
答案 0 :(得分:1)
也许看看OpenEJB。这是一个example that uses JPA。我不知道它是否涵盖了您的具体情况,但应该足够接近。
请注意,download page上有一个示例zip文件,其中包含大约二十多个这样的示例。所有这些都是单元测试,它们涵盖了EJB API的全部范围,包括MDB,Web服务,事务,安全性,当然还有基本的东西,如JPA,DataSources等。
答案 1 :(得分:0)
现在呢。你应该检查:
Table per Class inheritance in EJB3 Entities on docs.jboss.org
代码示例:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Pet implements java.io.Serializable
{
...
}
我希望我能帮忙。