java - Hibernate + JodaTime mapping different types -


i using hibernate reverse engineering , trying timestamps map jodatime type.

i have setup hibernate.reveng.xml file properly

<sql-type jdbc-type="timestamp" hibernate-type="org.joda.time.contrib.hibernate.persistentdatetime" not-null="true"></sql-type> 

the issue when run rev-eng process java classes members created persistentdatetime objects, don't want because not usable. need java objects org.joda.time.datetime

so tried creating custom engineering strategy

public class c3customrevengstrategy extends delegatingreverseengineeringstrategy {  public c3customrevengstrategy(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.datetime";     }    else {         return super.columntohibernatetypename(table, columnname, sqltype, length, precision, scale, nullable, generatedidentifier);     } } 

}

my thought hibernate mapping files hibernate.reveng.xml file settings , java objects settings custom strategy file...but not case. both mapping file , object of type "org.joda.time.datetime" not want.

how can achieve goal? also, not using annotations.

  • hibernate 3.6
  • jodatime 2.3
  • jodatime-hibernate 1.3

thanks

edit: clarify issue is

after reverse engineering in mapping file , pojo class

<property name="timestamp" type="org.joda.time.contrib.hibernate.persistentdatetime"> private persistentdatetime timestamp; 

as pojo property, persistentdatetime useless me cannot such time manipulations or anything. want after reverse engineering

<property name="timestamp" type="org.joda.time.contrib.hibernate.persistentdatetime"> private org.joda.time.datetime timestamp; 

using jidira library suggested below gives me same result, pojo cannot use.

the jodatime-hibernate library deprecated, , source of problem. don't dispair there (better) alternative.

you need use jadiratypes library create correct jodatime objects hibernate. add library which can found here project classpath , change type org.jadira.usertype.dateandtime.joda.persistantdatetime. of jodatime objects have corresponding mapping in package, if decide change object update type.

this should ensure objects created correctly.

i should add caveat answer, have never used jadiratypes library hibernate 3. if supports hibernate 4 (i don't see why would, but...) let me know , i'll delete answer.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -