Configure hibernate.reveng.xml to detect PK generator sequence with hibernate3-maven-plugin and Postgre

is there any way to configure hibernate3-maven-plugin so that the sequence generator is detected for primary-key ? I use a bottom-up approach for hibernate configuration (which means that hibernate-tools generates a hibernate configuration using jdbc-connection for you via reverse-engineering in an existing database schema). I read this one , but also this already (the two may be unrelated, but may also leave a hint). My hibernate.reveng.xml as follows:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" > <hibernate-reverse-engineering> <table name="ORDERS"> <primary-key> <!-- setting up a specific id generator for a table --> <generator class="sequence"> <param name="sequence">ORDERS_ORDER_ID_seq</param> </generator> <key-column name="ORDER_ID"/> </primary-key> </table> </hibernate-reverse-engineering> 

And I expect it to generate the Orders.hbm.xml file as follows:

 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2010-06-06 18:55:42 by Hibernate Tools 3.2.2.GA --> <hibernate-mapping> <class name="some.package.Orders" table="orders" schema="public"> <id name="orderId" type="long"> <column name="order_id" /> <generator class="sequence"> <param name="sequence">ORDERS_ORDER_ID_seq</param> </generator> </id> ... </class> </hibernate-mapping> 

... but getting this instead:

 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2010-06-06 18:55:42 by Hibernate Tools 3.2.2.GA --> <hibernate-mapping> <class name="some.package.Orders" table="orders" schema="public"> <id name="orderId" type="long"> <column name="order_id" /> <generator class="assigned" /> </id> ... </class> </hibernate-mapping> 

I know that my hibernate.reveng.xml is read by hibernate3-maven-plugin since I am experiencing maven errors when syntax errors occur in the file, so pom.xml seems to be correct and hibernate.reveng.xml syntactically correct.

Any clues?

+4
source share
2 answers

Below is the code that worked for me in the end. I just had to pass the name of the order table in lower case (I used capital letters in my DDL, so I really don't understand, but it works). You must also specify the schema attribute. <key-column name="pkey"/> is optional (if you follow the hibernation naming convention).

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" > <hibernate-reverse-engineering> <table name="orders" schema="public"> <primary-key> <!-- setting up a specific id generator for a table --> <generator class="sequence"> <param name="sequence">ORDERS_ORDER_ID_seq</param> </generator> </primary-key> </table> </hibernate-reverse-engineering> 
+4
source

Could you try with <param name="table">...</param> (this is what I see in the documentation or in this thread ). So something like this:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" > <hibernate-reverse-engineering> <table name="ORDERS"> <primary-key> <!-- setting up a specific id generator for a table --> <generator class="sequence"> <param name="table">ORDERS_ORDER_ID_seq</param> </generator> <key-column name="ORDER_ID"/> </primary-key> </table> </hibernate-reverse-engineering> 
+3
source

Source: https://habr.com/ru/post/1312011/


All Articles