-->
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.  [ 36 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Tue Dec 13, 2005 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
whaot? i'm telling you how you map enums (by a customizable customtype) and if you dont want to write it your self you go look in the annotations and ejb3 project on how that is done.

I also explain why we can't rely on jdk5 features in the core because noone have showed or made something that allows us to be compatible which is extremely important.

What is the difference between *true* jdk5 support and you writing:

<property name="anEnum">
<type="org.hibernate.type.EnumType">
<param name="enumclass">YourEnumClass</param>
</type>
</property>

?!

as far as I know the enumtype can even be intelligent dependent on the underlying resultset.

And the UserType system have been here since hibernate were born (almost) so you can trust me when i say it will be around a long time yet ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 6:16 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
max wrote:
whaot? i'm telling you how you map enums (by a customizable customtype) and if you dont want to write it your self you go look in the annotations and ejb3 project on how that is done.


As I stated before, again with deference, we would like support for enums without having to write custom types.

I'm not trying to degrade the conversation here, but you're repeating what Michael said back in August.

This thread was picked up again because someone had hoped (as did I) that this was included in 3.1. Which it has not been.

I wanted to make sure a core issue of the thread (being that we would like support for enums without having to write custom types) is re-iterated.

I apologize if you took offense to my reply.

Code:
What is the difference between *true* jdk5 support and you writing:
<property name="anEnum">
<type="org.hibernate.type.EnumType">
  <param name="enumclass">YourEnumClass</param>
</type>
</property>


If that's all it takes, hoorah. But as I understand org.hibernate.type.EnumType, that's not all that has to be done. I may be completely mistaken, which happens often. I'll review and try to get it to work new school vanilla style.

Quote:
And the UserType system have been here since hibernate were born (almost) so you can trust me when i say it will be around a long time yet ;)


Noted. As I hope you note the nature of my post above.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 8:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
lukasbradley wrote:
In short, please be aware that many of us still desire true enum support with Hibernate. Honestly, it's one of the only reasons I migrated to JDK 5.

Use Hibernate Annotations for native support

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 2:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...and that mapping code I have shown have been available out of the box for months and have *always* been possible. We just dont put jdk 1.5 deps into Hibernate3 core, only annotations and HEM

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 2:57 am 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
What would be helpfull is to allow a usertype to be registered against an interface or a base class. That way you woudl not have to declare the user type in each property explicitly. (just like hibernate does internally when it registers the native type handlers).

Additionally if the type could be given the reflected type of the property to further customize itself then you could create very robust handlers.

For example the EnumUserType could be registered against the base Enum type. Then when it gets constructed by the Configuration object it would be given the class of the spefic Enum. Now you have only to make one little registration once, and all enums are supported.

I currently have something like this implemented as a post process on the configuration that "upgrades" types to my registered type list (as hibernate exposes no way to register new types to its stock class->type mapping system). Its just that my solution to the problem is fragile as i have to understand about all the different types and how to iterate thourhg thier inner properties (ie Components, Entities etc).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 3:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you can do that without breaking compatibility and seperation of concerns then please do...but please take a good look at <typedef> since it allows you to package this up so you just need to specify the typename.

Yes; it wont be able to use reflection for validating it but it will definitly work.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:35 am 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
The problem i have with using typedef is it still requires me to explicitly specify the type on the definition of the property. Which is the main thing im trying to avoid.

This become especially usefully when combined with Hibernate Annotations, where there are sensable defaults for most types of mappings, so you document less.


What type of impact / would it be possible to extend the <typedef> definition so that it had an optional heuristic type. That way when the binder is runnign the heuristics code to determine an appropriate type it could also check all <typedef>s with defined heuristics. The type of a property could still be explicitly set and would not be impacted by the additional heuristics registered.

As an addon, the reflected type of the property could be auto-added as a parameter to the typedef. Combine that with the ability to match based on inheritance and you have what i had to implement manually.

Code:
<typedef class="org.mine.hibernate.EnumType" heuristicType="java.lang.Enum" matchDescendants="true"/>


This would signify that the type should be heuristically matched against all decendants of java.lang.Enum.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
create a patch and put it in jira...but I don't think its likely to be added to the core ...too much implied magic.

and how many enums do you actually have that makes it a problem to add type="ColorEnum" to the properties that needs it ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
also remember that types are normally viewed as immutable...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 1:07 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Currently we have around 20 different enums used in 200 or so classes.
Thats a lot of rote mapping work.
We also have 15 or so custom datatypes that are used throughout, which again need custom mappings. Hence why i wrote the code i wrote. It simplifies 90% of the mappings to just "this properties is or isnt persistent". The rest is handled by "teaching" hibernate how to handle new datatypes.

Its applicable for more than just enums. Its applicable to any custom types you need to use w/o the hassle of havign to know that there is a custom Type defined for it.

I am currently working with 8 modular projects (soon to be expanded) and its cumbersome to have to explicity define the Type for all the custom types. The ability to register it and use it (unless explicitly overriden) provides a more robust configuration. If its appropriate for native/stock types, I dont see why it wouldnt be for custom ones as well.


The types created would be immutable, it would be comparable to
Code:
<typedef class="org.mine.hibernate.EnumType" name="enum"/>

<property name="someEnum">
   <type name="enum">
       <param name="enumClass">org.enums.MyEnum</param>
   </param>
</property>


but you wouldnt not have to explicitly define it everywhere you used it. Thus simplifying the configuration.

Even a hook to allow an interceptor for the resolution of typeName/params to types would work. It would them remove the code that i have that needs to walk the Mappings and "upgrade" the datatypes.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Stop. You can use a <typedef> for each enum you have. It uses a single smart UserType that can persist enums (one for JDK 5.0 with auto-guessing is available in Hibernate Annotations). You then reference that new type by name in your property mappings. End of story. There is nothing to improve here.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I think what he is trying to accomplish is to provide a hook in hibernate that can allow him to just write:

<property name="value"/>

and let the mechanism detect this.

I think it could at least be worth considering a contribution that we may or may not adapt when we will go over some of the other issues we have with typedef.

to cmrudd - using interceptor is not possible here since the Interceptor is not active at configuration building time.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 3:18 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Such a mechanism would be completely unrelated to enums, its the "change the default mapping type" feature that has been discussed for ages. Someone provide a patch to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 3:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes christian but it is actually also a very nice solution for specifying enums as the user stated ;)

so cmrudd put a patch in jira.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 7:40 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Exaclty max, I'm just using enums as the example as its the simplest and one lots of people can relate to.

By "interceptor" i didnt mean the existing interceptor, i mean the concept of an interceptor. Ie

Code:
public interface TypeResolver
{
   public Type resolveType(String typeName, Properties parameters) throws MappingException;
}


A type resolver that can be registered with the configuration such that its consulted just before delegating to the TypeFactory.heuristicType method.

Ok. Ill do up a patch(s). A simple one using the TypeResolver concept. And a more complex one exapnding on my concept of adding extra data definition to the TypeDef constructs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 36 posts ]  Go to page Previous  1, 2, 3  Next

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.