• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Hibernate & JScience together?

 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I'm curious if anyone has used the JScience library in conjunction with Hibernate? JScience is a great library for representing different types of units. Ideally I would like to be able to persist data objects that contain both a value (as a float) and a unit (as a JScience Unit object). Any suggestions or known reference material?

Thanks,
Dave
[ December 29, 2005: Message edited by: David Irwin ]
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After poking around the JScience code-base and reading about Hibernate's UserType interface, I was able to create a custom UserType definition for storing JScience Units in a database. It works pretty well. I've included the class below:



You can then define an object variable in the corresponding Hibernate mapping file as follows:



There may indeed be better ways to implement this functionality. I'd love to hear people's thoughts.

Thanks,
Dave
[ January 05, 2006: Message edited by: David Irwin ]
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
thanks for following up with a solution for all of us to benefit from.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic