java - hibernate which naming strategy is default -


when researching how implement custom naming strategy (for table names only) stumbled upon inconsistency, can't resolve. (i'm using hibernate-core 3.6.6.final on jboss 6.1.0.final postgresql 9.1.9)

there seem 3 builtin implementations namingstrategy:

  1. defaultnamingstrategy
  2. ejb3namingstrategy
  3. improvednamingstrategy

the default seems set ejb3namingstrategy in org.hibernate.cfg.configuration.

however table names seem set according strategy, matches none of above.

example:
class name: package.classname
resulting table name: classname

strategies 1 , 2 call stringhelper.unqualify( classname ) removes package names , dots, result should classname.

strategy 3 removes package names , dots, puts underscore before each camelcased letter , converts lowercase, should yield class_name.

(source code of hibernate 4.1.0.final seems unchanged in these classes.)

could me clarify this?

very easy! because don't want spend time create toy environment hibernate-core 3.6.6.final give instruction how check instance used exactly in working application.

install visualvm on host. allow create heap dump local application. create heap dump on remove server - run on server:

jmap -dump:format=b,file=heap.dump $pid 

open dump in visualvm , run oql query:

map(heap.objects('org.hibernate.cfg.configuration'), "it.namingstrategydelegator") 

that your naming strategy. may use "instance" tab navigate across reference hierarchy known other actual types of hbm or jpa namingstrategy used.

different version of hibernate have different declared fields , types. if there no namingstrategydelegator field try digging instance:

heap.objects('org.hibernate.cfg.configuration') 

if class isn't in version of hibernate - try read docs , sources , find appropriate class.

with dependency org.hibernate:hibernate-entitymanager:jar:4.3.11.final have:

map(heap.objects('org.hibernate.cfg.configuration'), "it.namingstrategydelegator")       == org.hibernate.cfg.naming.legacynamingstrategydelegator 

and uses internally:

legacyhbmnamingstrategydelegate legacyjpanamingstrategydelegate 

depending on presents of jpa annotations. in cases instances reference legacynamingstrategydelegator (yea, cyclic references!) have field namingstrategy instance of org.hibernate.cfg.ejb3namingstrategy.

that all! spend 1 min find default naming strategy implementation in wepapp , 5 min write post ((

thanks watching, happy hacking!


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -