-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Failed to generate scripts with hbm2ddl for Oracle and MSSQL
PostPosted: Wed Nov 04, 2009 8:10 am 
Newbie

Joined: Wed Nov 04, 2009 7:54 am
Posts: 2
Hi,
I am trying to generate the DDL scripts with hibernatetool/hbm2ddl for Oracle and MS SQLServer. I use Hibernate Entity Manager as JPA provider and my classes are annotated using JPA (no hibernate-specific stuff, just plain JPA).

Generation of mssql passes without any problems, but when it comes to oracle, the following error is issued:
Code:
[hibernatetool] Nov 4, 2009 1:42:22 PM org.hibernate.dialect.Dialect <init>
[hibernatetool] INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.MappingException: Dialect does not support identity key generation


Any suggestions how to make Oracle DDL export work with @GeneratedValue(strategy = GenerationType.AUTO)?

Below you can find more details.

I have the basic entity as:
Code:
@MappedSuperclass
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "name", length = 100, nullable = false, unique = true)
    private String name;
...

// here I have some entities like that:
@Entity
@Table(name = "clm_group")
@Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
@AttributeOverrides(
        value = {@AttributeOverride(
                name = "id", column = @Column(name = "group_id")
        )}
)
public class Group extends BaseEntity implements Serializable {
...
}


Ant task is defined as follows:
Code:
...
<macrodef name="ddl">
      <attribute name="db"/>
      <sequential>
      <hibernatetool destdir="scripts">
      <jpaconfiguration
         propertyfile="config/@{db}-hibernate.properties"
         persistenceunit="clm"/>
      <classpath>
         <fileset dir="${dist}"/>
         <path refid="tools.classpath"/>
      </classpath>
      <hbm2ddl
         export="false"
         outputfilename="@{db}.sql"
         format="true"
         haltonerror="true"/>
      </hibernatetool>         
      </sequential>
   </macrodef>
   
   <target name="generate-ddl" depends="jar">
      <ddl db="mssql"/>
      <ddl db="oracle"/>
   </target>
...


The property files named as mssql-hibernate.properties and oracle-hibernate.properties, and just set the hibernate.dialect=org.hibernate.dialect.SQLServerDialect and hibernate.dialect=org.hibernate.dialect.Oracle10gDialect respectively.

I supposed, that Hibernate and hbm2ddl MUST select appropriate ID generation strategy, but as I see this doesn't happen...


Top
 Profile  
 
 Post subject: Re: Failed to generate scripts with hbm2ddl for Oracle and MSSQL
PostPosted: Wed Nov 04, 2009 9:08 am 
Newbie

Joined: Wed Nov 04, 2009 7:54 am
Posts: 2
Ok. Never mind.

This was stupid mistake: some of the entities, which not inherit from BaseEntity, were using @GeneratedValue(strategy = GenerationType.IDENTITY) instead of @GeneratedValue(strategy = GenerationType.AUTO). So I changed all IDs to @GeneratedValue(strategy = GenerationType.AUTO), and it worked!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.