0

I'm using JPA to implement my entity framework backed by Hibernate as an ORM to work with Oracle DB.

Everything is glued up (Autowired) with Spring.

To generate the DB schema I've added this to the jpa-context.xml

<bean id="h8JPAVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="false" />
        <property name="generateDdl" value="true" />
</bean>

I've used sequence-generator to generate IDs for entities but for some reason when the schema is beeing created\updated, Hibernate doesn't create the Sequences them selves.

This is my mapping.xml file which injects the identity field

<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
    version="1.0">

    <mapped-superclass class="com.myapp.entity.BaseModelEntity" access="FIELD">
        <attributes>
            <id name="id">
                <generated-value strategy="SEQUENCE" generator="MODEL_SEQ"/>
                <sequence-generator name="MODEL_SEQ" sequence-name="MYAPP_MODEL_SEQ"/>
            </id>
        </attributes>
    </mapped-superclass>
</entity-mappings>

Searching Google always give me results of how to use existing sequences, however I would like Hibernate to create them form me.

Thanks in advance for your help

ssedano
  • 8,322
  • 9
  • 60
  • 98
DuduO
  • 31
  • 5
  • Think you have to add `` `generateDdl` doesn't update schema – Ori Dar May 21 '13 at 21:08
  • Problem were described here: http://stackoverflow.com/questions/7171626/hibernate-with-oracle-sequence-doesnt-use-it – michal May 21 '13 at 21:30
  • Thank you michal for the answer, however my problem is different, When I manually create the sequence in the DB (i.e `CREATE SEQUENCE customers_seq START WITH 1000 INCREMENT BY 1`) everything is working perfect. I want hibernate to create the DB sequence for me. – DuduO May 21 '13 at 21:45
  • AFAIK, There is no provision in Hibernate to create the sequences as part of the DDL schema generation as of now. – Bhashit Parikh May 22 '13 at 03:08

0 Answers0