-->
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.  [ 12 posts ] 
Author Message
 Post subject: Generator class in mapping file
PostPosted: Tue Jan 23, 2007 5:50 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi,
When I generate my mapping files using the reverse engineering my files looks something like this:

Code:
<hibernate-mapping>
    <class name="com.myCompany.business.model.Foo" table="Foo">
        <id name="userName" type="string">
            <column name="USER_NAME" length="8" />
            <generator class="assigned" />
        </id>
        ....
    </class>
</hibernate-mapping>


and this is fine for some tables but most of my tables is using a sequence number to get the next value on the primary key. And therefor I want to be able to specify what tables is using "assigned" and what tables are using the sequence...

Code:
<hibernate-mapping>
    <class name="com.myCompany.business.model.Foo" table="Foo">
        <id name="userName" type="string">
            <column name="USER_NAME" length="8" />
            <generator class="sequence">
               <param name="sequence">FOO_SEQ</param>
            </generator>
        </id>
        ....
    </class>
</hibernate-mapping>


Is there any way to specify this in the cfg.xml or the reveng.xml?

Cheers
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes in reveng.xml ....look in the tool docs for generator.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 12:39 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi Max,
I read the documentation and this is the closest I get:

Code:
   <table schema="JACOB" name="APP_USER_ROLE">
      <primary-key>
         <generator class="sequence">
            <param name="table">APP_USER_ROLE_SEQ</param>
         </generator>
         <column name="APP_USER_ROLE_ID"/>
      </primary-key>
   </table>


but now I get an error in the page stating:
"The content of element type 'primary-key' must match '(generator?, key-column)'"

What am I doing wrong?

Cheers,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 12:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
column should be key-column

where did you read it is column ? (this was in the *old old* days ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
doh ...docs have a bug...fixed in svn. thanks ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 1:08 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi again,
I have done the update now and now the error is gone. This is how part of my reveng.xml looks like:

Code:
   <table schema="JACOB" name="APP_USER_ROLE">
      <primary-key>
         <generator class="sequence">
            <param name="table">APP_USER_ROLE_SEQ</param>
         </generator>
         <key-column name="AppUserRoleId"/>
      </primary-key>
      <foreign-key constraint-name="FK_APP_USER_APP_USER_ROLE">
         <many-to-one property="AppUser" exclude="true" />
      </foreign-key>
   </table>


But still my generated file look like this:

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">
<!-- Generated Jan 24, 2007 12:03:28 PM by Hibernate Tools 3.2.0.beta7 -->
<hibernate-mapping>
    <class name="com.myCompany.business.model.AppUserRole" table="APP_USER_ROLE">
        <id name="appUserRoleId" type="java.lang.Long">
            <column name="APP_USER_ROLE_ID" precision="22" scale="0" />
            <generator class="assigned" />
        </id>
         .....
    </class>
</hibernate-mapping>


Is there anything I am still missing?
BTW: I am running on a Oracle 10 database with Hibernate tools 3.2.0.beta7

Cheers,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 1:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
is your schema really named JACOB ?

...and why are you usign beta7 when i just released beta9 ? :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 1:36 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Yes, my schema name is JACOB and I have not had time to do the update.... so you think it will work if I use the latest version?

I will start downloading the latest version right now...

Cheers, Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 2:08 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi Max,
I have done the update and now the result file looks like this:
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">
<!-- Generated Jan 24, 2007 1:02:58 PM by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
    <class name="com.myCompany.business.model.AppUserRole" table="APP_USER_ROLE">
        <id name="appUserRoleId" type="java.lang.Long">
            <column name="APP_USER_ROLE_ID" precision="22" scale="0" />
            <generator class="assigned" />
        </id>
        .....
    </class>
</hibernate-mapping>


Still no luck with using the settings in the reveng.xml to change the generator to sequence.
Code:
<table schema="JACOB" name="APP_USER_ROLE">
      <primary-key>
         <generator class="sequence">
            <param name="table">APP_USER_ROLE_SEQ</param>
         </generator>
         <key-column name="APP_USER_ROLE_ID"/>
      </primary-key>
      <foreign-key constraint-name="FK_APP_USER_APP_USER_ROLE">
         <many-to-one property="AppUser" exclude="true" />
      </foreign-key>
   </table>


The key-column I tried both <key-column name="APP_USER_ROLE_ID"/> and <key-column name="AppUserRoleId"/>

but the result is still the same as above... any suggestions?

Cheers,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 2:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
leave schema out and tell me what the result is

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 2:32 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Thank Max, that fixed it... now the result comes out really nice...

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">
<!-- Generated Jan 24, 2007 1:29:52 PM by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
    <class name="com.myCompany.business.model.AppUserRole" table="APP_USER_ROLE">
        <id name="appUserRoleId" type="java.lang.Long">
            <column name="APP_USER_ROLE_ID" precision="22" scale="0" />
            <generator class="sequence">
                <param name="sequence">APP_USER_ROLE_SEQ</param>
            </generator>
        </id>
        .....
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 2:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so the schema name was *not* JACOB :)

_________________
Max
Don't forget to rate


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