Data Not inserting into Database JPA+Hibernate
raja_jan09 Nov 10, 2010 7:47 AMHi All,
actually I have created Entity Beans which are used to create tables in mysql database, everything is working fine with transaction classes using entityfactory.
Now I need this functionality...when I deploy the EAR file in application sever JBOSS..it have to check whether the tables are existing in the database or not..if they are not present..it have to create the tables automatically..of course I have specified this function hibernate.hbm2ddl.auto=update in persistence.xml..but still not creating any tables which are not present in the database and not throwing any error also when ever I run the application server its creating only mysql default tables..but not the developed ones and here I am give my code:
package com.ernst.persistenceImpl.beanImpl;
import com.ernst.persistenceAPI.beanAPI.NrKreiseBeanAPI;
import com.ernst.persistenceAPI.localBeanAPI.NrKreiseLocalBeanAPI;
import com.ernst.persistenceAPI.remoteBeanAPI.NrKreiseRemoteBeanAPI;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Basic;
import java.io.Serializable;
@Entity
@Table(name = "NR_KREISE")
public class NrKreiseBean implements NrKreiseBeanAPI, NrKreiseLocalBeanAPI, NrKreiseRemoteBeanAPI, Serializable {
@Id
private int nr_kreise_id;
@Basic
private int fk_nr_typ;
@Basic
private int data_ref_von;
@Basic
private int data_ref_bis;
@Basic
private int data_ref;
@Basic
private int msg_ref_von;
@Basic
private int msg_ref_bis;
@Basic
private int msg_ref;
@Basic
private String desc;
public int getNr_kreise_id() {
return nr_kreise_id;
}
public void setNr_kreise_id(int nr_kreise_id) {
this.nr_kreise_id = nr_kreise_id;
}
public int getFk_nr_typ() {
return fk_nr_typ;
}
public void setFk_nr_typ(int fk_nr_typ) {
this.fk_nr_typ = fk_nr_typ;
}
public int getData_ref_von() {
return data_ref_von;
}
public void setData_ref_von(int data_ref_von) {
this.data_ref_von = data_ref_von;
}
public int getData_ref_bis() {
return data_ref_bis;
}
public void setData_ref_bis(int data_ref_bis) {
this.data_ref_bis = data_ref_bis;
}
public int getData_ref() {
return data_ref;
}
public void setData_ref(int data_ref) {
this.data_ref = data_ref;
}
public int getMsg_ref_von() {
return msg_ref_von;
}
public void setMsg_ref_von(int msg_ref_von) {
this.msg_ref_von = msg_ref_von;
}
public int getMsg_ref_bis() {
return msg_ref_bis;
}
public void setMsg_ref_bis(int msg_ref_bis) {
this.msg_ref_bis = msg_ref_bis;
}
public int getMsg_ref() {
return msg_ref;
}
public void setMsg_ref(int msg_ref) {
this.msg_ref = msg_ref;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
Persistence.xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="DefaultDS" transaction-type="JTA">
<jta-data-source>java:/DefaultDS</jta-data-source>
<class>com.ernst.persistenceImpl.beanImpl.NrKreiseBean</class>
<properties>
<property name="jboss.entity.manager.factory.jndi.name" value="persistence-units/DefaultDS"/>
<property name="hibernate.ejb.cfgfile" value="WEB-INF.classes.META-INF.hibernate.cfg.xml"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/lagerstandnew"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="sekhar"/>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<!-- SQL stdout logging -->
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="use_sql_comments" value="true"/>
</properties>
</persistence-unit>
</persistence>
Can any one please give me an idea how to do this or please tell me if I have done anything wrong in above files.
Thanks in Advance.
Best Regards,
Raja.