Persistent.xml Hibernate generating table tables using SQL script customization

Source: Internet
Author: User

<?XML version= "1.0" encoding= "UTF-8"?><Persistencexmlns= "Http://xmlns.jcp.org/xml/ns/persistence"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version= "2.1">    <Persistence-unitname= "PRIMARY">        <provider>Org.hibernate.ejb.HibernatePersistence</provider>        <exclude-unlisted-classes>False</exclude-unlisted-classes>        <Properties>            <!--<property name= "javax.persistence.schema-generation.database.action" value= "Drop-and-create"/>  -            < Propertyname= "Hibernate.dialect"value= "Org.hibernate.dialect.MySQLDialect" />            < Propertyname= "Javax.persistence.schema-generation.database.action"value= "Drop-and-create" />            < Propertyname= "Javax.persistence.schema-generation.create-source"value= "Script" />            < Propertyname= "Javax.persistence.schema-generation.create-script-source"value= "File:///e:/create.sql" />            < Propertyname= "Javax.persistence.schema-generation.drop-source"value= "Script" />            < Propertyname= "Javax.persistence.schema-generation.drop-script-source"value= "File:///e:/drop.sql" />            <!--<property name= "Javax.persistence.sql-load-script-source" value= "Meta-inf/data.sql"/> -            <!--<property name= "javax.persistence.schema-generation.scripts.action" value= "DROP-AND-CR Eate "/> <property name=" Javax.persistence.schema-generation.scripts.create-target "value                 = "./create.sql"/> <property name= "Javax.persistence.schema-generation.scripts.drop-target" Value= "./drop.sql"/> -        </Properties>    </Persistence-unit></Persistence>

Attention:

The SQL statement creates a table that corresponds to the entity bean. Otherwise, there will be an error.

Create TableSeat (IDbigint  not NULLAuto_increment, Bookedbit  not NULL, seat_idbigint, Zhibinvarchar( -),Primary Key(ID))Create TableSeat_type (IDbigint  not NULLAuto_increment, descriptionvarchar( -) not NULL, Positionvarchar(255), Priceinteger  not NULL, quantityinteger  not NULL,Primary Key(ID))Alter TableSeatAdd constraintFk9pohag9bkh1suwck1bxtr7cysForeign Key(seat_id)ReferencesSeat_type (ID)

The SQL file can be placed inside the Meta-inf:

<property name= "Javax.persistence.sql-load-script-source" value= "Meta-inf/data.sql"/>

The real path to: Src/main/resources/meta-inf/create.sql

./drop.sql is the current directory where widlfly runs from.

Persistent.xml Hibernate generating table tables using SQL script customization

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.