• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

"type" in mapping

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all....i am new to hibernate as well as to this forum...
please clarify me:
what is the need to mention hibernate-type in mapping as we have already declared type in class attributes and columns of the table.

thanks for your support.
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "type" attribute is used in a variety of scenarios ... such as mapping custom data types you've created. Also, some times can be mapped to many different SQL types (consider java.util.Date being mapped to either "date" or "timestamp"). Etc ....
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A little more detail is that that type is just a String for Hibernate to use to map the Java Type to the Database Type. So when you say type="date" there is a mapping file for Hibernate to see what database you are using and it tells how to convert a Java type to that database type that matches. So for different databases, the database type for the same java type might be different, but they are all using the same hibernate type.

For instance a type



So the type you use in your mapping file is "date" but the Java Type and the Database type might need to be different for different database.

The example above is made up to demonstrate what we mean and are not the exact mappings that Hibernate does.

Mark
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic