-->
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.  [ 2 posts ] 
Author Message
 Post subject: SchemaExport of calendar types - overriding the types
PostPosted: Tue Sep 08, 2009 10:31 am 
Newbie

Joined: Wed Jan 23, 2008 8:07 am
Posts: 6
I'm using the SchemaExportTask ANT task in Hibernate 3.1.3 to export a schema for MySQL and Oracle.

The MySQL create DDL generated maps hibernate calendar types (or java.util.Calendar) to DATETIME SQL fields

Code:
CREATEDDATE datetime not null


whereas the Oracle create DDL maps the same types to TIMESTAMP SQL fields

Code:
CREATEDDATE timestamp not null


I want MySQL to use timestamp as well. This mapping appears to be defined in the org.hibernate.dialect.MySQLDialect and org.hibernate.dialect.Oracle9Dialect classes, which contain

Code:
registerColumnType( Types.TIMESTAMP, "datetime" );


and

Code:
registerColumnType( Types.TIMESTAMP, "timestamp" );


respectively.

Is there a way of overriding these default mapping types, so that MySQL will use a SQL TIMESTAMP for hibernate calendar types, and probably SQL DATETIME for hibernate timestamp types (or java.util.Date)?


Top
 Profile  
 
 Post subject: Re: SchemaExport of calendar types - overriding the types
PostPosted: Tue Sep 08, 2009 10:45 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
DATE vs. TIME vs. TIMESTAMP

It's noteworthy to point out how the registrationDate column, which is annotated to be TemporalType.DATE, simply gets a year-month-day value, whereas the lastAccessTime column is populated with a full timestamp, including both the day and the time (TemporalType.TIME is the third option which would have simply saved the time, and not the calendar day). By the way, TemporalType.TIMESTAMP is the default if it isn't otherwise specified in your code.


You can read more about column mapping here:

http://jpa.ezhibernate.com/Javacode/lea ... ingwithjpa

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.