Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

is there a way to configure hibernate3-maven-plugin so that a sequence generator is detected for a primary-key? I'm using a bottom-up approach for hibernate configuration (which means letting hibernate-tools generate the hibernate configuration using a jdbc-connection for you via reverse-engineering on an existing database schema). I've read this, but also this already (those two can be unrelated, but can also leave a hint). My hibernate.reveng.xml is the following:

<?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'm expecting it to generate an Orders.hbm.xml file like this:

<?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 receiving 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 my hibernate.reveng.xml is being read by hibernate3-maven-plugin, as I experience maven errors whenever syntax errors appear in the file, so pom.xml seems to be correct and hibernate.reveng.xml syntactically correct.

Any clues?

like image 749
mmm Avatar asked Jun 06 '10 17:06

mmm


1 Answers

Below the code that worked for me eventually. I just had to pass the order table name in lower-case (I used capital letters in my DDL so I actually don't understand, but this works). Also the schema attribute needs to be provided. The <key-column name="pkey"/> is optional (if you follow the hibernate 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>
like image 159
mmm Avatar answered Sep 30 '22 08:09

mmm