-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Bug with orm.xml, annotations and inheritance ?
PostPosted: Thu Oct 30, 2008 9:37 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
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 ?


Last edited by chawax on Fri Oct 31, 2008 5:09 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2008 10:22 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
I found where my problem comes from. But I have no idea how to workaround it ...

Actually my entities are generated from an UML model with AndroMDA (EJB3 cartridge). When I model an entity with a transient method, it creates two classes :
- One base class which defines entity properties with annotations. It is overriden everytime I run MDA process.
- One implementation that extends base class and just contains transient methods to write. This class is generated once and is never overriden later.

For example In my case, I have two classes :
- ProcessTemplateBase
- ProcessTemplate which extends ProcessTemplateBase.

When I define ProcessTemplate as an entity in orm.xml, Hibernate looks for annotations in ProcessTemplate class and not in ProcessTemplateBase class. And since my columns are defined in ProcessTemplateBase class, it can't find them and that's the reason why I get this erro :( Is it a bug with Hibernate or is it something expected ?

EDIT : I changed the topic title so that it tells more about the real problem I encounter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 5:55 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
There was no bug, I just misused Hibernate ... I added @javax.persistence.MappedSuperclass annotation to my base class and it works much better !


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.