-->
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.  [ 9 posts ] 
Author Message
 Post subject: Specifying global generator class during revengr
PostPosted: Thu Jun 04, 2009 5:51 pm 
Is there a way to specify IDENTITY, for example, for all table PK's that will be revengr'd in the foo.reveng.xml file?

There is an example on pg. 90 of JPA/Hibernate book but it specifies for one table only. What if all my tables are using IDENTITY (auto-incrementing) PK?


Top
  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Sat Jun 06, 2009 1:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
No, but you can implement a custom reverse engineering strategy and apply all the global logic you want.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Mon Jun 08, 2009 12:41 pm 
where can I find examples of custom revengr strategies? I'm assuming you're referring to Java classes to do this?

btw, it should do this automatically if the JDBC driver detects there's an IDENTITY column/seed for the tables...


Top
  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Tue Jun 09, 2009 3:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
which db are you using ? We detect identify for i.e. mysql.

about custom reverse engineering strategies see the documentation - it describes how to do it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Tue Jun 09, 2009 11:03 am 
I'm using MSSQL 2005. What I mean by auto-detection is "auto-detect and auto-set property" so I don't have to configure it myself via custom revengr strategies.

Don't you think this would save time? Why would I not annotate with @GeneratedValue for my identity-generated PK properties/columns in my JPA entity classes?


Top
  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Tue Jun 09, 2009 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
of course it would be better to have this working - just need some implement a MetaDataDialect that detects identity for the columns.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Tue Jun 09, 2009 11:33 am 
I guess you are referring to the below:
Quote:
5.4. Custom Database Metadata

By default the reverse engineering is performed by reading using the JDBC database metadata API. This is done via the class org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect which is an implementation of org.hibernate.cfg.reveng.dialect.MetaDataDialect.

The default implementation can be replaced with an alternative implementation by setting the property hibernatetool.metadatadialect to a fully qualified classname for a class that implements JDBCMetaDataDialect.

This can be used to provide database specific optimized metadata reading. If you create an optimized/better metadata reading for your database it will be a very welcome contribution.


source: http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html/reverseengineering.html

So you are saying that a MSSQL-specific implementation of org.hibernate.cfg.reveng.dialect.MetaDataDialect will automatically place the required @GeneratedValue annotations on the entity classes' PK fields?


Top
  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Tue Jun 09, 2009 12:42 pm 
Max,

thanks for your help! I was able to accomplish what I needed with the following seam-gen.reveng.xml customized configuration. The only other question I have is how can the serialVersionUID be generated by hbm2java tool as well?

Code:
private static final long serialVersionUID = 8034732296116123826L;


None of my entity classes have the above line of code in them. So I must add that manually using JBDS. thx.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
 
  <!-- do not include EquipmentRecovery.sys.* objects from sys schema! -->
 
  <schema-selection match-schema="dbo"/>

   
  <table catalog="EquipmentRecovery"
         schema="dbo"
         name="ApplicationPermission">         
     <primary-key> 
         <generator class="identity"/> 
     </primary-key>
  </table>
   
  <table catalog="EquipmentRecovery"
           schema="dbo"
           name="ApplicationRole">         
       <primary-key> 
           <generator class="identity"/> 
       </primary-key>
  </table>
 
  <table catalog="EquipmentRecovery"
             schema="dbo"
             name="ApplicationSetting">         
         <primary-key> 
             <generator class="identity"/> 
         </primary-key>
   </table>
 
</hibernate-reverse-engineering>


Top
  
 
 Post subject: Re: Specifying global generator class during revengr
PostPosted: Fri Jun 12, 2009 6:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
1) There are two parts in reverse engineering. First one is MetaDataDialect which is doing the low level reading of metadata from the database and transforms it into a model similar to JDBC metadata but is not dependent on it. This is the *right* place to implement database specific identity implementation.

See http://fisheye.jboss.org/browse/Hiberna ... ng/dialect
and if you want to see a specific db identity example look at http://fisheye.jboss.org/browse/Hiberna ... alect.java

In case you don't want to do that, i.e. you don't know how to get it from the specific db and you dont want to specify it manually in reveng.xml you can control the id strategy in the ReverseEngineeringStrategy which abstraction is higher than MetaDataDialect and instead of raw data it is talking about id strategy, class and associations based on table,column and foreignkeys.

Using ReverseEngineeringStrategy is described here: http://docs.jboss.org/tools/3.0.1.GA/en ... g-strategy
and the method(s) to implement is getTableIdentifer*

2) Automatic serialVersionUID generation is evil :) Look in HBX jira for discussions on this....waiting for someone to come up with an algorithm that is not broken ;)

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