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: user defined classes
PostPosted: Wed Nov 12, 2003 4:28 pm 
Newbie

Joined: Wed Nov 12, 2003 3:49 pm
Posts: 19
I am trying to use custom / user defined wrapper classes with Hibernate. For example, I have an immutable class that wraps a String. It has a default constructor as well as a constructor that accepts a String. But, it does not have a set() method. I modified the setters to do a new() to work around this:

private ExpIDCncr expID;
public ExpIDCncr getExpID() {return expID;}
public void setExpID(String expID) {
this.expID = new ExpIDCncr(expID);}

My wrapper classes work on simple operations, but throw a ClassCastException if they must participate as a property in a 1:M relationship or as part of a composite key.

Can anybody give me any tips on this, or are immutable classes simply incompatible with Hibernate? What are the rules for using user defined classes for bean properties in Hibernate? If I switch my wrapper class back to a String, everything works just fine.


Thanks,
Dave

PS - I have read, and re-read setion 4.2.4, Custom Value Types, of the doc. I can't seem to make the leap from documentation to code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 5:42 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
Custom types require accessors. Don't try anything fancy like your doing in the setter - asking for trouble. I don't understand what you are doing with composite keys but that sounds like trouble too. Composite keys must be defined in the mapping file and must point to a class definition. Wrapper classes that implement UserType are different animals. You are implementing UserType, right? Try setting some debug points in the methods like nullSafeSet & nullSafeGet.

Hope this helps,

Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 8:41 am 
Newbie

Joined: Wed Nov 12, 2003 3:49 pm
Posts: 19
If the problem is lack of accessor methods, then it doesn't make sense that the java wrapper classes, like Float, work but custom classes don't. Why would custom classes have to have set() methods but not java wrapper classes? A Class is a Class. I need to know the requirements that Hibernate puts on custom classes.

Re composite keys: I don't like them either but they are a fact of life with legacy databases. If Hibernate can't deal with them simply and efficiently, then Hibernate is not a viable solution for many of us. (at least IMHO)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) please don't post in this large font
(2) All Hibernate identifiers must implement equals()/hashCode()/serializable, no matter wether they are a composite-id, a custom type, or a plain vanilla type.
(3) Composite ids or user type ids work just fine
(4) Immutable classes work just fine


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.