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: Add type in hbm.xml different than in .java
PostPosted: Fri Oct 05, 2007 8:44 am 
Newbie

Joined: Thu Aug 16, 2007 2:25 pm
Posts: 5
Hibernate version:
3.2

Name and version of the database you are using:
PostgreSQL 8.1

When I generate code using Hibernate Tools, I need to use the following types for TIMESTAMP columns:

a) Use org.joda.time.contrib.hibernate.PersistentDateTime in the .hbm.xml file (this class persists org.joda.time.DateTime in timestamp columns)

b) Use the org.joda.time.DateTime in the .java file

How I do it automatically using Reverse Engineering? I think in use an ReverseEngineeringStrategy to do this, but I don't know how.

_________________
Rodrigo Avila
rodrigo@avila.eti.br

http://www.avila.eti.br


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 07, 2007 5:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
You just need to inform hibernate tools during reverse engineering that when it sees a TIMESTAMP use the PersistentDateTime type; then when hbm2java runs it will consult PerstentDateTime (remember to have it in the classpath!) on which java type it should use (via the getReturnedClass() method)

so there is two options for this:

a) in a .reveng.xml file:

Code:
<type-mapping>
<sql-type jdbc-type="TIMESTAMP" hibernate-type="org.joda.time.contrib.hibernate.PersistentDateTime"/>
</type-mapping>


b) via custom reveng strategy where you implement something like:

Code:
public class CustomStrategy extends DelegatingReverseEngineeringStrategy {
   
   
   public CustomStrategy(ReverseEngineeringStrategy res) {
      super(res);
   }

        public String columnToHibernateTypeName(TableIdentifier table, String columnName, int sqlType, int length, int precision, int scale, boolean nullable, boolean generatedIdentifier) {
                 if(sqlType==Types.TIMESTAMP) {
                          return "org.joda.time.contrib.hibernate.PersistentDateTime";
                    }    else {
              super.columnToHibernateTypeName(...);
}
   }


_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 17, 2007 12:26 pm 
Newbie

Joined: Mon Dec 17, 2007 11:50 am
Posts: 14
Hi!
I have a similar problem. Can such a mapping be performed with annotations?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - but not sure if our code generation for hbiernate annotations spits out the custom type correctly. If not - a patch is very welcome ;)

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