Generate hibernation tool annotation without the directory attribute

when I run my hibernation tools it reads from db and creates java classes for each table, and a java class for composite primary keys. it's great.

the problem is in this line

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

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

I thought which db was selected depends on the jdbc connection url but when i change the jdbc url to "tstdev" it still uses "tstdb"

so, I know what to do, I just don’t know how my options are done

  • suppressing the generation of the directory attribute I am currently doing this manually (not very productively) or I could write a program that parses the java file and removes the attribute manually but I hope I don’t need

OR

  • find a way to tell hibernate to ignore the directory attribute and use the specified schema. I do not know the exact settings that I have to change in order to achieve this, or even if this option is available.
+6
java annotations hibernate code-generation
source share
3 answers

You need to complete 3 steps -

1) In hibernate.cfg.xml add this property

 hibernate.default_catalog = MyDatabaseName 

(as indicated in a previous post)

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

 table-filter match-name="MyTableName" 

(just this, without a directory name here)

3) Recover hibernation code

You will not see a single directory name in any of the *.hbm.xml files.

I used Eclipse Galileo and Hibernate.3.2.4.GA.

+7
source share

There is a setting in the generation that tells which tables should be placed in which directory.

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

In addition, I recently had to modify the generation patterns.

See the help documentation:

Sorry, this may be more accurate, but right now I do not have access to a working computer.

+1
source share

The attribute directory is the connection attribute and must be specified in the connection configuration file hibernate.cfg.xml and NOT in the configuration data file *.hbm.xml .

I will generate hibernation code through the ant task <hibernatetool> , and I set the replacement task after regeneration (replace the schema name with your database).

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

So, after generating the attribute catalog has been deleted.

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

0
source share

All Articles