For some reasons I would like to use orm.xml to define entity informations (table name, unique constraints, named queries, ...) and use annotations to define columns. I tried to define entities in orm.xml, for example something like that :
Code:
<entity class="t4.core.utils.process.internal.ProcessTemplate">
<table name="HQPRC_TEMPLATE"></table>
<named-query name="ProcessTemplate.findAll">
<query><![CDATA[select processTemplate from ProcessTemplate AS processTemplate]]></query>
</named-query>
<named-query name="ProcessTemplate.findByCode">
<query><![CDATA[from ProcessTemplate as processTemplate where processTemplate.code = :code]]></query>
</named-query>
</entity>
Columns are defined using annotations in Java class.
But when running unit tests on Open EJB, it can't deploy my application. I have this stack trace :
Code:
ERROR - Application could not be deployed: C:\Documents\t4\core\t4-core-utils\core\target\classes
org.apache.openejb.OpenEJBException: createApplication.failed [C:\Documents\t4\core\t4-core-utils\core\target\classes]: org.hibernate.AnnotationException: No identifier specified for entity: t4.core.utils.process.internal.ProcessTemplate: No identifier specified for entity: t4.core.utils.process.internal.ProcessTemplate
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:592)
at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:338)
at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:250)
at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:149)
at org.apache.openejb.OpenEJB.init(OpenEJB.java:288)
at org.apache.openejb.OpenEJB.init(OpenEJB.java:267)
at t4.core.utils.test.OpenEjbBootstrap.startAndDeployResources(OpenEjbBootstrap.java:22)
at t4.core.utils.test.OpenEjbSeamTest.startJbossEmbeddedIfNecessary(OpenEjbSeamTest.java:59)
at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:916)
at t4.core.utils.test.OpenEjbSeamTest.startSeam(OpenEjbSeamTest.java:35)
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:585)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:398)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:145)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:82)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:262)
at org.testng.SuiteRunner.run(SuiteRunner.java:191)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
at org.testng.TestNG.run(TestNG.java:701)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
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:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:334)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)
Caused by: org.apache.openejb.OpenEJBException: org.hibernate.AnnotationException: No identifier specified for entity: t4.core.utils.process.internal.ProcessTemplate: No identifier specified for entity: t4.core.utils.process.internal.ProcessTemplate
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:459)
... 31 more
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: t4.core.utils.process.internal.ProcessTemplate
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:627)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:407)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
at org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:183)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:454)
... 31 more
But I have this column defined in my Java class :
Code:
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
@javax.persistence.Column(name = "ID_", nullable = false, insertable = true, updatable = true)
public java.lang.Long getId()
{
return id;
}
So I wonder if it's possible to declare entity in orm.xml and use annotations in Java class to define columns. Anyone tried something like this ?