-->
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.  [ 5 posts ] 
Author Message
 Post subject: @ForeignKey ist ignored from hbm2ddl
PostPosted: Mon Nov 30, 2015 12:34 pm 
Newbie

Joined: Mon Nov 30, 2015 12:15 pm
Posts: 2
Hello,

following javax.persistence.@ForeignKey Annotation is ignored by hbm2ddl:

Code:
   @JoinColumn(name = "oem_FK", nullable = false, foreignKey = @ForeignKey(name = "parttooem", foreignKeyDefinition = "FOREIGN KEY (oem_FK) references oem (id) ON DELETE RESTRICT"))
   @ManyToOne(targetEntity = OEM.class, fetch = FetchType.EAGER, optional = false)
   public OEM getOem() {
      return oem;
   }


Hibernatetool generates:
Code:
    alter table Part
        add constraint FK25D8138CB60A16
        foreign key (oem_FK)
        references OEM;

my target is "ON DELETE RESTRICT"

Here is the maven plugin configuration:
Code:
            <plugin>
            <!-- run "mvn hibernate3:hbm2ddl" to generate a schema -->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <dependencies>
               <dependency>
                  <groupId>org.hibernate.javax.persistence</groupId>
                  <artifactId>hibernate-jpa-2.0-api</artifactId>
                  <version>1.0.0.Final</version>
               </dependency>
            </dependencies>
            <configuration>
               <hibernatetool>
                  <annotationconfiguration
                     configurationfile="src/main/resources/META-INF/persistence.xml" />

                  <hbm2ddl update="true" create="true" export="false"
                     outputfilename="schema.dll" format="true" console="true" />
               </hibernatetool>
               <components>
                  <component>
                     <name>hbm2ddl</name>
                     <implementation>jpaconfiguration</implementation>
                  </component>
               </components>
               <componentProperties>
                  <detail>true</detail>
                  <persistenceunit>my_PU</persistenceunit>
                  <outputfilename>schema.ddl</outputfilename>
                  <drop>true</drop>
                  <create>true</create>
                  <export>false</export>
                  <format>true</format>
               </componentProperties>
            </configuration>
         </plugin>


hibernate.cfg.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
                                         "hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <!-- a SessionFactory instance listed as /jndi/name -->
   <session-factory name="MySessionFactory">
      <!-- properties -->
      <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
      <property name="show_sql">false</property>
      <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
      <property name="hibernate.connection.username">username</property>
      <property name="hibernate.connection.password">password</property>
      <property name="current_session_context_class">thread</property>
   </session-factory>
</hibernate-configuration>



Versions: hibernate-tools-3.2.4.GA
hibernate-entitymanager-4.3.7.Final
hibernate-core-4.3.7.Final
hibernate-commons-annotations-4.0.5.Final

best regards

Heiko


Top
 Profile  
 
 Post subject: Re: @ForeignKey ist ignored from hbm2ddl
PostPosted: Mon Nov 30, 2015 1:12 pm 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Don't use hibernate3 plugin, please use hibernate 4 plugin, such as

Standard plugin:
Code:
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-maven-plugin</artifactId>
    <version>4.3.1.Final</version>
</dependency>

or
3rd-party plugin
Code:
<dependency>
    <groupId>de.juplo</groupId>
    <artifactId>hibernate4-maven-plugin</artifactId>
    <version>1.1.0</version>
</dependency>

or
3rd-party plugin
Code:
<dependency>
    <groupId>net.leadware</groupId>
    <artifactId>hibernate4-maven-plugin</artifactId>
    <version>1.0.2</version>
</dependency>


Last edited by babyfish on Mon Nov 30, 2015 1:35 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: @ForeignKey ist ignored from hbm2ddl
PostPosted: Mon Nov 30, 2015 1:30 pm 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Or you can try this

(1) link about how to generate DDL by Hibernate 4.3: http://docs.jboss.org/hibernate/orm/4.3/devguide/en-US/html_single/#envers-generateschema
(2) link about how to embed ant task in Maven: https://maven.apache.org/plugins/maven-antrun-plugin/examples/tasksAttributes.html


Top
 Profile  
 
 Post subject: Re: @ForeignKey ist ignored from hbm2ddl
PostPosted: Mon Nov 30, 2015 5:19 pm 
Newbie

Joined: Mon Nov 30, 2015 12:15 pm
Posts: 2
juplo's hibernate4-maven-plugin does unfortunately not work too.

cascade restrict is ignored too.

best regards

Heiko


Top
 Profile  
 
 Post subject: Re: @ForeignKey ist ignored from hbm2ddl
PostPosted: Tue Dec 01, 2015 10:42 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
OK, it looks like a bug, please submit ticket on https://hibernate.atlassian.net/projects/HHH/issues,

You'd better create a maven project to reproduce the issue/bug and upload it to be the attachment of your ticket,
this project should be as small as possible so that the Hibernate Team can handle it as fast as possible.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.