-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hbm2Java & custom UserType problem in Hibernate-3
PostPosted: Tue Jun 20, 2006 5:51 pm 
Newbie

Joined: Thu Jun 08, 2006 11:57 am
Posts: 7
By mistake, I have posted the following problem in the Hibernate-Users mailing list. Not sure if it needs re-post here.. but here is the link to the thread.

http://forum.hibernate.org/viewtopic.php?t=960972

And, was there a reason why the tooling for hbm2java has changed the way it did from Hibernate-2.1.7 to Hibernate-3.1.0-beta4.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 3:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It works as expected as long as you remember to put that usertype in the classpath otherwise we cannot load the usertype and determine the returned class.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 5:12 pm 
Newbie

Joined: Thu Jun 08, 2006 11:57 am
Posts: 7
Just to clarify:
Are you saying that the following snippet from the hibernate-mapping file
Code:
        <property column="LAST_MODIFIED" length="11" name="lastModified"
            type="com.company.hibernate.usertypes.LastModifiedColumnType">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="default-value">new java.util.Date()</meta>
        </property>

will still produce the following code using the new hbm2java (hibernate-tool) task when we add the Custom UserType to the tooling class-path.
Code:
/** nullable persistent field */
protected Date lastModified = new java.util.Date();


Thanks for helping out..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes of course, just as was required in the old tools.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 3:04 pm 
Newbie

Joined: Thu Jun 08, 2006 11:57 am
Posts: 7
Max, .. the trick was Great. (adding the dependency to the tooling classpath) solved the problem with the usertype. Question: Does the trick also applies to the following ?
Code:
       <property column="UPDATE_DATE" length="11" name="updateDate" not-null="true"
          type="java.sql.Timestamp">
          <meta attribute="use-in-tostring">true</meta>
          <meta attribute="default-value">new java.util.Date()</meta>
       </property>

Here the java.sql.timestamp is from Sun's jav2sdk1.4.2/jre/lib/rt.jar. I added the rt.jar to the tooling classpath but I dont think hibernate is loading the class as it did for CustomUserType and produces the following code in pojo.
Code:
protected Timestamp updateDate = new java.util.Date();

Causing the following error:
Code:
/home/esyed/hibernate-migration/components/taxonomy/target/generated-src/hbm2java/com/company/portal/taxonomy/model/Link.java:[26,38] incompatible types
found   : java.util.Date
required: java.sql.Timestamp


In Hibernate-2, the same mapping snippet resulted in
Code:
protected Date updateDate = new java.util.Date();

I hope you have some trick that can solve this issue too..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 4:30 pm 
Newbie

Joined: Thu Jun 08, 2006 11:57 am
Posts: 7
fyi.. I fixed the posted problem by writing a new Custom UserType (UpdateDateUserType) and the pojo's generate the same code as in hibernate-2. For some reason, in the mapping file you cant pass the java.sql.Timestamp in type for a property. Here is how the modified snippet looks like:
Code:
       <property column="UPDATE_DATE" length="11" name="updateDate" not-null="true"
          type="com.company.hibernate.usertypes.UpdateDateUserType">
          <meta attribute="use-in-tostring">true</meta>
          <meta attribute="default-value">new java.util.Date()</meta>
       </property>

and the generated code in pojo..
Code:
     protected Date createDate = new java.util.Date();

Not sure, if there was any other way to accomplish the same. But, adding rt.jar from sun (has java.sql.Timestamp) to the tooling classpath didnt help. Going the route of creating a new CustomType fixed it. Max, might know the fix & suggest something else when he checks this. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
put that in jira - i'll need to check if it is correct behavior or not.

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