views:

505

answers:

3

Hi,

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"&gt;
<!-- 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"&gt;
<!-- 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?

+1  A: 

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>
Pascal Thivent
@Pascal: thanks for your answer, it helped me finding the solution. The `name` attribute was not the problem, though. Both, i.e. `table` and `sequence` work fine depending on what you need. I updated my question with the code that worked for me.
mmm
@mmm: Well, not sure how my answer helped but... you're welcome :) Feel free to post your solution as answer and accept it (that's actually what you should do).
Pascal Thivent
@Pascal: ok, added the solution as answer. Your answer helped by pointing to yet another discussion where I finally noticed the `schema` attribute might be missing :).
mmm
A: 

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>
mmm
A: 

Thank you so much! For me the 'schema' did it, although I had to use uppercase schema name and table name.

Jan