-->
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: Custom NamingStrategy that maintains state between calls
PostPosted: Fri Mar 12, 2010 5:53 am 
Newbie

Joined: Fri Mar 12, 2010 5:14 am
Posts: 1
Hi,

I'm working on a project where we use Hibernate and JBoss 5.1. We need our entity classes to be mapped to Oracle tables that follow a certain naming convention. I'd like to avoid having to specify each table and column name in annotations. Therefore, I'm currently considering implementing a custom implementation of org.hibernate.cfg.NamingStrategy.

The SQL naming conventions require the name of columns to have a suffix that is equivalent to a prefix of the table name. If there is a table "T100_RESOURCE", the ID column would have to be named "RES_ID_T100".

In order to implement this in a NamingStrategy, the implementation would have to maintain state, i.e. the current class name it is creating the mappings for. It would rely on Hibernate

* to always call classToTableName() before propertyToColumnName()
* and to determine all column names by calling propertyToColumnName() before the next call to classToTableName()

Is it safe to do that or are there situations where Hibernate will mix things up? I am not thinking of problems through multiple threads here (which can be solved by keeping the last class name in a ThreadLocal) but also of Hibernate deliberately calling this out of order in certain circumstances. For example Hibernate asking for mappings of three properties of class A, then one of class B, then again more attributes of class A.


Top
 Profile  
 
 Post subject: Re: Custom NamingStrategy that maintains state between calls
PostPosted: Fri Mar 12, 2010 8:44 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Is it safe to do that or are there situations where Hibernate will mix things up?


I think the best is, you get the sources of hibernate-annotations-<your-version>-sources.jar
at http://repository.jboss.org/maven2/ and take a look at the implementation (maybe also debugging).
But however, assuming that your actual hibernate versions is'nt mixing these things up,
it is not guaranteed that this would remain unchanged in newer versions.


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.