views:

938

answers:

4

when i run my hibernate tools it reads from the db and create java classes for each tables, and a java class for composite primary keys. that's great.

the problem is this line

@Table(name="tst_feature"
    ,catalog="tstdb"
)

while the table name is required, the "catalog" attribute is not required. sometimes i want to use "tstdb", sometimes i want to use "tstdev"

i thought which db was chosen depends on the jdbc connection url but when i change the jdbc url to point to "tstdev", it is still using "tstdb"

so, i know what must be done, just don't know how its is done my options are

  • suppress the generation of the "catalog" attribute currently i'm doing this manually (not very productive) or i could write a program that parses the java file and remove the attribute manually but i'm hoping i don't have to

OR

  • find a way to tell hibernate to ignore the "catalog" attribute and use the schema that is explicitly specified. i don't know the exact setting i have to change to achive this, or even if the option is available.
A: 

There is a customization to the generation, that will tell what tables to put in what catalog.

You can specify the catalogue manually (in reveng file, <table> element), or programmatically (in your custom ReverseEngineeringStrategy class if I remember well).

Also, I recently had to modify the generation templates.

See the reference documentation :

Sorry, this could get more precise, but I don't have access to my work computer right now.

KLE
table element selects tables from the catalogs,yes.but that's not i want.i want the entity to be generated without the "catalog" attributeif the catalog attribute is there, no matter what my jdbc url is, it would still point to the same schema,i want to be able to switch schema without re-generating the entities.
Titi Wangsa bin Damhore
i took a look at the ftl filesthere is a line that says<#if clazz.table.catalog?exists> ,catalog="${clazz.table.catalog}"</#if>any idea on how do i set this to false?
Titi Wangsa bin Damhore
i figured it outuse<property name="default_catalog">xxx</property>in you hibernate.cfg.xml file
Titi Wangsa bin Damhore
A: 

Hey dude,

I have the exact same issue as you but using <property name="default_catalog">xxx</property>

in my hibernate config did not make a difference - the catalog specified in the auto-generated

hibernate mapping xmls is still being used. Anyone else have any suggestions?

Boris
i think "default_catalog" works only for MySQL, for DB2, it still displays the "catalog".This is my experience.
Titi Wangsa bin Damhore
it would be great if i could figure out where to get hibernate-tools source code, but i don't know where to get them.
Titi Wangsa bin Damhore
A: 

You need to follow 3 steps -

1) In the hibernate.cfg.xml, add this property

hibernate.default_catalog = MyDatabaseName (as specified in above post)

2) In the hibernate.reveng.xml, add all the table filters like this

table-filter match-name="MyTableName" (just this, no catalog name here)

3) Regenerate hibernate code

You will not see any catalog name in any of the *.hbm.xml files.

I have used Eclipse Galileo and Hibernate-3.2.4.GA.

dassoug
A: 

The attribute catalog is a "connection" attribute and should be specified in "connection" config file hibernate.cfg.xml and NOT in "data" config file *.hbm.xml.

I generate hibernate code via ant task and I put this replace task after regeneration (replace schema-name with your database).

<replace dir='../src' token='catalog="schema-name"' value=''/>

So, after generation, attribute catalog has been removed.

This is a workaround, but code generated works in my development a production environment with different schema-name

michele