-->
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: How much flexibility in Hibernate<->SQL type mappings?
PostPosted: Fri Jan 14, 2005 9:13 pm 
Newbie

Joined: Fri Jan 14, 2005 8:30 pm
Posts: 11
Hibernate version: 2.1

I've got a bottom-up situation (I've inherited a database schema that I cannot change) and am wondering how much flexibility I have in my mapping documents when I indicate something like:


Code:
<property
    name="applyShipping"
    type="java.lang.Integer"
    column="ApplyShipping"
/>


and the underlying MySQL column is something like:

Code:
`ApplyShipping` SMALLINT UNSIGNED,



Better put, what is the mechanism that determines how the underlying SQL column is converted to the Integer type indicated above? Presumably I can't just specifiy *anything* for the hibernate type, it must have to conform to the underlying SQL columh type somehow.

So I guess my questions are:

* How does Hibernate convert between the types indicated in the mapping file and the underling SQL column types?

* What kind of flexibility do I have here? Can I take that MySQL SMALLINT and map it to an java.lang.Integer? For "reads" this should not be a problem (a mysql smallint fits inside a java.lang.Integer) but what happens during "writes" (when the Integer contains more data than will fit within the smallint)?

* Is there a document that lists the Hibernate types, the corresponding Mysql types, and the conversion behavior?

For direct JDBC use, this document (among others) answers these questions:

[url]
http://java.sun.com/j2se/1.3/docs/guide ... ml#1053867
[/url]

Does a similar document exist for Hibernate. Or perhaps Hibernate is simply using JDBC and the type mappings defined in the JDBC docs are what I should reference?

Thanks much,

- Gary[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 9:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Hibernate uses JDBC as the interface to the database so the type mappings, eg, Java -> SQL constraints are detemined by JDBC driver in use.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 15, 2005 3:34 am 
Newbie

Joined: Fri Jan 14, 2005 8:30 pm
Posts: 11
Quote:
Hibernate uses JDBC as the interface to the database so the type mappings, eg, Java -> SQL constraints are detemined by JDBC driver in use.


Excellent. Does Hibernate use JDBC's "SetObject/GetObject" and, thus, offer the type conversions described in 8.9.5 and 8.9.6 of the Sun JDBC document?

http://java.sun.com/j2se/1.3/docs/guide ... ml#1053867

That would be just nifty. I've got a database full of MySQL TINYINT and SMALLINT fields that I'd vastly prefer to map direclty to an java.lang.Integer. If I can just tell Hibernate that the fields map to an Integer and let JDBC deal with the type conversions my life will be much easier.

Can you confirm?

Thanks again,

- gary


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 15, 2005 5:29 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the documentation, source and check UserType. Its trivial.


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.