<?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