-->
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.  [ 2 posts ] 
Author Message
 Post subject: Schema Generator support for custom UserTypes?
PostPosted: Mon Mar 17, 2008 12:06 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Hi,

We have been having some troubles in our project consistently dealing with our mappings of BigDecimal values.

We have many numbers sprinkled throughout our domain model that represent distinct basic number types:
- Money
- Area
- Volume
- Percentage

Each of these numbers has a defined scale that we want to be applied consistently (2 for the cents in a dollar, 4 for the meters in a hectare, etc.)

I figured encapsulating these types in a custom domain value class and associated hibernate UserType would be a good way to do this.

The only problem is, I can't figure out how to affect the schema generation phase for a particular UserType.

Basically, each UserType just wraps around a BigDecimal and I'd like the Hibernate Schema Exporter to create the associated database column with the correct scale in the database.
At the moment, the schema exported seems to just default to precision=19, and scale=2 (Not sure if that's a database default or what).

Is there any way to control the column definition that Hibernate will issue for a custom type?

I've looked in the reference manual and the 2nd edition book, not much there that I can see.

Thanks,
Shorn.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 3:39 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Ok,

I found a way to do this, but it seems like a bit of a hack to me - I think Hibernate probably supports a more elegant mechanism, I just can't figure out what it is.

Basically, I make my custom user type return a non-standard, made-up value from it's "public int[] sqlTypes()" method.

Then in my custom Dialect subclass, in this constructor, I call the "registerColumnType()" method passing my special SQL code and the database column declaration I want used ("decimal 12, 2", for example);

This seems pretty dodgy, I'm binding my Dialect to my custom UserTypes pretty heavily.

It seems like Hibernate pretty much supports this kind of behaviour, I just seem to be missing the part where you hook up the custom user type to the dialect in a more robust way.

Is there something I've missed - or this pretty much the accepted way to do it?

_________________
Cheers,
Shorn.


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