-->
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.  [ 5 posts ] 
Author Message
 Post subject: Multi-Column User Types
PostPosted: Wed Oct 27, 2004 11:21 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
Hibernate version: 2.1.6

I've seen the DoubleString type, as an example of a UserType implementation which deals with more than one column. What I don't understand is how to communicate which of the columns each name relates to. This is important if I have two columns of different types.

Is the order of the names guaranteed to be the order they appear in the passed array of column names? Is that how to do this?

Essentially I have an Integer and a String which I would like to fetch within the same implementation of UserType. Suggestions?

Thanks,
Phill


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The property names returned by getPropertyNames() are just for querying in an HQL query. They have no relation to the column names passed to the nullSafeGet() method, which come from the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 1:15 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
That's okay. My question is about the 'names' array passed to nullSafeGet. If I expect two values in that array, and one should reference an Integer column, and one should reference a String column... how do I know which is which?

I suppose for some people, the order of even two String columns might be important. One might be english and one might be spanish (an awful approach to localization, but you get my point :))

The DoubleString example doesn't care about this stuff because both strings mean the same thing, essentially. They're interchangeable.

So is there a solution to this? Should I depend on the order in which the properties were defined in the mapping to be retained in the names[] array?

Am I making sense?

Thanks for your help, Michael.

Phill


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It's the same order as in the getPropertyType() array you return


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 5:25 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
Okay. That makes sense to me now. I think the main reason this has been so confusing is because the types of the individual properties of my returnedClass() aren't both basic hibernate types. Now I'm a bit confused as to how to implement getPropertyValue() and setPropertyValue().

I'm trying to create a CompositeUserType that handles the persistence of the following class:

Code:
public class CommandParameterData implements Serializable {

   private CommandParameterDataTypeEnum type = null;
   private Object data = null;

   public CommandParameterDataTypeEnum getType() {
      return type
   }

   public void setType(CommandParameterDataTypeEnum type) {
      this.type = type;
   }

   public Object getData() {
      return data;
   }

   public void setData(Object data) {
      this.data = data;
   }
}


The getType() method on this class returns an Enum class (which serializes to an integer). My CompositeUserType stuff seems fairly straight forward except for the getPropertyValue() and setPropertyValue() implementations. For the Type property, should I return an integer or the Enum value? Right now I'm returning the type Hibernate.INTEGER for that column, is that correct or do I need yet another UserType implementation for this?

I have a similar issue with my getData() property also. I'm storing it as a string in the database.

What are setPropertyValue() and getPropertyValue() used for?

Thanks
Phill


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