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.  [ 3 posts ] 
Author Message
 Post subject: Component vs UserType
PostPosted: Tue Sep 01, 2009 3:25 pm 
Newbie

Joined: Wed Aug 12, 2009 10:45 am
Posts: 16
Hi all;
I am relatively new to hibernate. I was reading the book and saw that you can have user types, of arbitrary classes, saved by hibernate. I was thinking why would not one use a component which also allows for saving any arbitrary class? I tried java.io.File and the only problem I got was the file does not implement a default constructor. I created a dummy File class with same attribute but with default constructor and it seems to be working.

My question is that: besides constructor, getter and setters, what other reasons are there to create a UserType and not use <component> ?
THanks


Top
 Profile  
 
 Post subject: Re: Component vs UserType
PostPosted: Tue Sep 01, 2009 8:43 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, Hibernate is really just about object-relational mappings. So, the idea is to just create your Java classes as you normally would, and then map them. There's really no need to complicate things beyond that.

_________________
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  
 
 Post subject: Re: Component vs UserType
PostPosted: Thu Sep 03, 2009 11:24 am 
Newbie

Joined: Wed Aug 12, 2009 10:45 am
Posts: 16
Cameron McKenzie wrote:
Well, Hibernate is really just about object-relational mappings. So, the idea is to just create your Java classes as you normally would, and then map them. There's really no need to complicate things beyond that.


Hello;
Thanks fro the note. I know I am supposed to create my 'usual' java classes. But look at my example here:
I have a class that has a member imageFile which is of type java.awt.File. I tried to create a component for the File class in my class but it gave me an error later telling me that java.io.File does not implement a no-arg constructor. I created a dummy class named File with the same attributes but provided a default constructor, this time; I had two options:

I was able to use the <component> sub element of my class mapping
I was able to Create a user type implementation that extends UserType and used that type instead of <component>

So, my question is where to use which? Except for classes that you don't own the source and do not have no-arg, what are the pros and cons of using one not the other?

Kamal


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