-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with combination of generated-class and composite-id
PostPosted: Mon Apr 18, 2005 4:20 pm 
Newbie

Joined: Mon Apr 18, 2005 3:24 pm
Posts: 2
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: HibernateExt module from CVS as of Apr 18

Mapping documents: see below

Code between sessionFactory.openSession() and session.close(): Not applicable

Full stack trace of any exception that occurs: Not applicable

Name and version of the database you are using: SQLServer 2000

The generated SQL (show_sql=true): Not applicable

Debug level Hibernate log excerpt: Not applicable

I'm trying to set up a project with ant generating all the POJOs to one package, and me "hand-coding" sub-classes in another package, where each hand-coded class inherits from a generated POJO. This way I can separate generated code from hand-written business logic.

I reverse engineered the following hbm.xml file from an existing database (using the contents of JBossIDE-1.5M1-Hibernate-Tools.zip), and added a generated-class meta (I changed the package name to hide my client's name):

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
        Auto-generated mapping file from
        the hibernate.org cfg2hbm engine
-->
  <class name="com.junk.model.ActionPage" table="action_page" schema="dbo" >
    <meta attribute="generated-class">com.junk.model.generated.ActionPage</meta>
    <composite-id name="id" class="com.junk.model.generated.ActionPageId">
      <key-many-to-one name="RoleAction" class="com.junk.model.RoleAction">
        <column name="action_id" scale="10" precision="0" not-null="false" />
      </key-many-to-one>
      <key-property name="Status" type="java.lang.String">
        <column name="status" scale="30" precision="0" not-null="true" sql-type="varchar" />
      </key-property>
    </composite-id>
    <property name="Page" type="java.lang.String">
      <column name="page" scale="100" precision="0" not-null="true" sql-type="varchar" />
    </property>
  </class>
</hibernate-mapping>


I'm using the following ant target to generate the code

Code:
  <target name="hibernate-codegen">
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"/>
      <hibernatetool destdir="${basedir}/topdown">
      <configuration>
        <fileset dir="${src}" id="id">
          <include name="**/ActionPage.hbm.xml"/>
          <include name="**/RoleAction.hbm.xml"/>
        </fileset>
      </configuration>
      <hbm2java/>
    </hibernatetool>
  </target>


I was expecting the generator to produce three files: one for ActionPage, one for ActionPageId, and one for RoleAction. However, it produced only two: one called ActionPage.java which contained the fields for ActionPageId (not ActionPage), and one for RoleAction.

Stepping through the debugger, I isolated it to the following method in org.hibernate.tool.hbm2x.Cfg2JavaTool

Code:
   public String getQualifiedDeclarationName(Component component) {
      String generatedName = getMetaAsString(component, "generated-class");
      if(generatedName==null || generatedName.trim().length()==0) {
         generatedName = component.getComponentClassName();
      }
      
      generatedName  = generatedName.replace('$', '.');
      String qualifier = StringHelper.qualifier(component.getComponentClassName());
      if("".equals(qualifier)) {
         return qualifier + "." + generatedName;
      } else {
         return generatedName;
      }   
   }



It seems that when the generator is writing the code for the composite ID, it picks up the generated-class attribute from the enclosing class entity. The generator overwrites ActionPage.java with a file of the same name, containing the fields from ActionPageId.

I tried adding a generated-class meta to the composite-id, but the generator concatenated the two generated-class attributes and created a whole new set of sub-packages.

Is there some other way to achieve what I want, or is there a bug in the above method?

Thanks,
Jon.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 3:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
looks like a bug (even though I have a test for it ;)...but please report it to the jira. thank you

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 10:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sorry - didnt notice that you were using meta attribute generated-class here!

Add inherit="false" to the meta tag and you will be fine.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 10:25 am 
Newbie

Joined: Mon Apr 18, 2005 3:24 pm
Posts: 2
That worked, thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.