Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to automatic create table in jpa persistence xml file?

I am using eclipse IDE.I also try following two .but failed..when i manually create table in my mysql database then my complete program run fine... I want create table automatic with respect to entity class.

<property name="hibernate.hbm2ddl.auto" value="create"/>

<property name="hibernate.hbm2ddl.auto">update</property>

here my persistence file:

<?xml version="1.0" encoding="UTF-8"?>
  <persistence version="2.1" xmlns="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">
<persistence-unit name="JpaTest2" transaction-type="RESOURCE_LOCAL">

     <class>com.jpa.Employee</class>

    <properties>

        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hibernate"/>
        <property name="javax.persistence.jdbc.user" value="umar"/>
        <property name="javax.persistence.jdbc.password" value="umar"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>


    </properties>
</persistence-unit>

like image 596
Ummer Iqbal Avatar asked Sep 30 '15 19:09

Ummer Iqbal


1 Answers

Dont use Hibernate specific options. JPA 2.1 provides

javax.persistence.schema-generation.database.action

that can be set to "create", "drop", "drop-and-create", "none". That way you keep your code JPA implementation independent

like image 59
Neil Stockton Avatar answered Oct 04 '22 22:10

Neil Stockton