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.  [ 1 post ] 
Author Message
 Post subject: Question about usage of Typedef/Type annotations
PostPosted: Mon Aug 10, 2009 10:42 pm 
Newbie

Joined: Mon Aug 10, 2009 10:14 pm
Posts: 3
Hello,

In our project, we have a number of custom types; According to the hibernate documentation, we would have to do something like this:
@TypeDef(
name="caster",
typeClass = CasterStringType.class,
)

public class Forest {
@Type(type="caster")
public String getSmallText() {
...
}

However, we wanted to do away with the need to specify @Type every time we use a custom type, and have Hibernate auto-detect the corresponding Hibernate UserType. A quick glance at the Hibernate source code tells us that we can indeed dispense with the @Type as follows:

import hello.Dog;

@TypeDef(name="hello.Dog", typeClass=hello.DogUserType.class) //'hello.Dog' is the fully-qualified class name of our custom class

class XX {
private Dog dog; //No @Type annotation necessary; Hibernate realizes it has to use DogUserType.

This is possible because of the following line in SimpleValueBinder:
String type = BinderHelper.isDefault( explicitType ) ? returnedClassName : explicitType;
org.hibernate.mapping.TypeDef typeDef = mappings.getTypeDef( type );

If 'explicitType' is not set (via the 'Type' attribute), it uses 'returnedClassName' as the key to look-up the associated Type info. Since we have previously registered the TypeDef with the same key (hello.Dog), it is able to retrieve the value correctly.

The question is, can I RELY on this undocumented behaviour? It would make our life a lot easier, but I want to make sure I dont run into any problems later...

Regards,
Sharath


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.