-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate tools reverse define generator class
PostPosted: Mon Nov 21, 2005 9:08 am 
Newbie

Joined: Mon Nov 21, 2005 8:55 am
Posts: 1
Location: FRANCE
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:from hibernate-tools-3.1.0.alpha5

Name and version of the database you are using:Informix Dynamic Server Version 9.30.UC2
Name and version of the database you are using:IBM Informix Dynamic Server Version 9.40.FC4W2X1

Hi everybody,

after long, tedious and unsuccessful research on this forum and google, i somehow succeeded in changing the default
Code:
generator class="assigned"
to
Code:
generator class="native"
which I needed for my legacy database schema.

I finally used a modified id.hbm.vm velocity template in cfg2hbm, in the following ugly way (sessionid is the PK column) :

Code:
....
#if(! $c2h.isIdentifierGeneratorProperties($property))
   #set( $sessionproperty = "sessionid" )
   #if ( $sessionproperty == "$property.name" )
      <generator class="native" />
   #else
       <generator class="$property.Value.identifierGeneratorStrategy" />
   #end
#else
       <generator class="$property.Value.identifierGeneratorStrategy">
#set ($parameters = $c2h.getIdentifierGeneratorProperties($property))
....



Here is the except from the generated Session.hbm.xml :

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="dao.Session" table="session">
        <id name="sessionid" type="long">
            <column name="sessionid" />
            <generator class="native" />
        </id>
        <many-to-one name="actor" class="dao.Actor">
            <column name="actorid" not-null="true" />
        </many-to-one>
...



I'd love for somebody to tell me that there is another way to do what I did...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 1:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
from tools.hibernate.org docs:

<table name="ORDERS"> <!-- table allows you to override/define how reverse engineering are done for a specific table -->
<primary-key>
<generator class="native">
<param name="table">seq_table</param>
</generator>
</primary-key>
</table>

currently you need to do it per table.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 1:29 pm 
Newbie

Joined: Wed Nov 23, 2005 1:04 pm
Posts: 3
Hi max,

I've been trying to change the generator class through the hibernate.reveng.xml file using the eclipse plugin.
(HibernateTools-3.1.0.beta1). The tool definitely reads the reveng file(I can cause errors by putting in bad tags in the reveng file), but there is no effect on the generated mapping file. Here is what I put in the reveng file:

<table name="MyTable">
<primary-key>
<generator class="sequence">
<param name="table">seq_table</param>
</generator>
</primary-key>
</table>

Here is part of the result:
<id name="MyTableId" type="integer">
<column name="MyID" />
<generator class="assigned" />
</id>

I was expecting class="sequence".

More details:
- using postgresql
- generating mapping files using the Artifact Generator interface
- reverse engineering through jdbc connection


Maybe I'll try a different version of the tool?

Thanks for any help you can give.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 2:06 pm 
Newbie

Joined: Wed Nov 23, 2005 1:04 pm
Posts: 3
I added the 'schema' attribute and now it works. Why is that?
I can keep or omit this part: <param name="table">seq_table</param>

<table name="MyTable" schema="public">
<primary-key>
<generator class="sequence">
</generator>
</primary-key>
</table>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 8:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
probably because you dont have default schema set.

_________________
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.  [ 5 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.