My Student tables in database erlier 60 entries.
every time i call session.save(object) ,data stored previously
in table gets deleted.
Only one row remains with fresh data .why ?
Hibernate version: --3.1
Mapping documents:--
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.mypackage.beans.Student" table="STUDENT"
>
<id name="studentID">
<column name="STUDENT_ID" />
<type name="integer" />
<generator class="increment" />
</id>
<property name="studentFirstName">
<column name="FIRST_NAME" />
</property>
<property name="studentMiddleName">
<column name="MIDDLE_NAME">
</column>
</property>
<property name="studentLastName">
<column name="LAST_NAME"></column>
</property>
<property name="classID">
<column name="CLASS_ID"></column>
</property>
<property name="dateOfAdmission">
<column name="DATE_OF_ADMISSION"></column>
<type name="timestamp"></type>
</property>
<property name="dateOfLeaving">
<column name="DATE_OF_LEAVING"></column>
<type name="date"></type>
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
this.student=student;
session.save(this.student);
session.getTransaction().commit();
if( session.isOpen() == true) {
System.out.println( "closing session");
session.close();
} else {
System.out.println("session is already closed");
}
Full stack trace of any exception that occurs:
No Exception
Name and version of the database you are using:
MySQL- 5.0.37
The generated SQL (show_sql=true):
Hibernate: select max(STUDENT_ID) from STUDENT
Hibernate: insert into STUDENT (FIRST_NAME, MIDDLE_NAME, LAST_NAME, CLASS_ID, DATE_OF_ADMISSION, DATE_OF_LEAVING, STUDENT_ID) values (?, ?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
Logging disabled.
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html