-->
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.  [ 8 posts ] 
Author Message
 Post subject: Is there away to allow UserTypes to read configuration?
PostPosted: Thu Apr 22, 2004 2:54 pm 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
In our projects we use a variety of data type classes as the attributes for the business classes. As an example we might have a ZipCode class that we use obviously enough to store US postal codes. In order to use this class with Hibernate we started creating UserTypes that we can declare in the mapping file to properly extract the zip code and store it in the database as a character field.

All of this works well enough but these classes sometimes have extra meta data setup for them. In the zipcode case we might have a flag on the ZipCode type that instructs it to only accept in-state zips. The issue then is that we might have a class, say InStateLocation, that only holds in state zips so the ZipCode instance held by every instance of InStateLocation should have this flag set. It seems a waste to store the flag in the database since the flag never changes. We'd also rather not have a UserType specially created for this case.

What we were hoping to do was embedded extra data in the mapping file as meta tags that would convey this kind information of information to the UserType. So in the above example the property line would read like :

<property column="zip" name="zip" type="eg.ZipCode" length="5">
<meta attribute="inState">true</meta>
</property>

I've looked through the code and could not find any straight forward method for the UserType instance to get access to information from the mapping file for the field it's handling. So I went back into the code to look for a likely place for this to reside. The solution I created basically creates a new interface a UserType can implement called ConfigurableUserType with a extra method called configure. Either in the binder or the TypeFactory a new UserType can be checked to see if it implements this interface and if it does a call to it's configure method is made passing the dom4j element node representing this properties entry in mapping file.

Ok. Now to the question. Is there a better way to do this and if so how? If there is not a better method, would there be any interest in the patch to allow this. I'm kind of concerned that some time in the future the one to one mapping between UserType instances and property tags having that UserType as the declared type might change.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I have just implemented that yesterday, it will be in the next major release. You can parameterize types, make typedefs with parameters, override those and all kinds of nice things.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 3:31 pm 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
Is this in the CVS or will it be shortly? I'm wondering if I'd be able to back port this to 2.1.2 with out destablizing things and without a enormous about of work?

If you don't think that's possible perhaps I can make my little hack work enough like what your doing that I can easily switch over to your once a stable release with this work in it appears. I hate to ask but any idea when it might make it into a stable release?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 3:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The changes were not too difficult, they are in v22branch now. Take a look at TypeParameterTest to see how they are used. Backporting it should be doable, it won't get into any official 2.1.x release though. No timeline for any major release yet.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 24, 2004 3:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
PS: If you don't want to get into backporting, I'd suggest you at leat adapt the ParameterizableType interface, so you can reuse your types after an upgrade easily.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 10:06 am 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
Any update on this? I think I need this ;-)

Also, what is ParameterizableType? It's not in the 2.1.5 javadocs.

michael wrote:
PS: If you don't want to get into backporting, I'd suggest you at leat adapt the ParameterizableType interface, so you can reuse your types after an upgrade easily.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 10:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This will be in Hibernate 3


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 11:05 am 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
Thanks, I'll look forward to it. Meanwhile I'll figure something out.


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