How to cancel Hibernate Hbm2ddl.auto automatically create foreign keys

Source: Internet
Author: User
Tags jbpm

When you use HBM2DDL to automatically create a database table, you create a foreign key association for the table at the same time. The configuration is as follows.

<prop key= "Hibernate.hbm2ddl.auto" >create</prop>

To cancel the automatic creation of foreign keys, you need to configure foreign-key= "None".

The update log for Hibernate has the following description:

Changes in version 2.1.9 (xx.x.xxxx)------------------------------------* foreign-key= "None" can is used to disable Gener Ation of a foreign key.

As a result, the configuration of Hibernate ORM in the project can be annotated or used as a configuration file.

The configuration file can be configured as follows in the XML corresponding entity class (note the foreign-key= "None"):

<class name= "Org.jbpm.identity.User"  table= "Jbpm_id_user"  discriminator-value= "U" >     <id name= "id"  column= "id_" >      <generator  class= "native"  />    </id>    <discriminator  type= "char"  column= "Class_"  />    <property name= "name"   Column= "name_"  />    <property name= "email"  column= "EMAIL_"  / >    <property name= "Password"  column= "Password_"  />     <set name= "Memberships"  cascade= "All" >      <key  column= "User_"  />      <one-to-many class= " Org.jbpm.identity.Membership " />    </set>    <set  name= "Permissions"  cascade= "all " table=" Jbpm_id_permissions ">      <key column=" ENTITY_ "  foreign-key= "None"  />      <element type= " Org.jbpm.identity.hibernate.PermissionUserType ">        <column  name= "Class_"  />        <column name= "NAME_"  />        <column name= "ACTION_"  />       </element>    </set>  </class>

Annotations can be used to configure annotations before the Get method of the corresponding class field as follows:

@JoinColumn (name= "parent_id") @ForeignKey (name = "None")

Above.

How to cancel Hibernate Hbm2ddl.auto automatically create foreign keys

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.