-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: previously stored data gets deleted after session.save cal'd
PostPosted: Sat Mar 01, 2008 3:47 pm 
Newbie

Joined: Sun Aug 26, 2007 2:09 pm
Posts: 4
Location: INDIA
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


Top
 Profile  
 
 Post subject: Re: previously stored data gets deleted after session.save c
PostPosted: Sat Mar 01, 2008 5:43 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
There should be something else. There is not even a DELETE sql on the output. May be you have something else that drops and creates the schema each time you start your test. Do you have a hbm2ddl.auto in the mapping file?

Farzad-


Top
 Profile  
 
 Post subject: I have reset hbm2ddl.auto to validate
PostPosted: Sun Mar 02, 2008 12:56 am 
Newbie

Joined: Sun Aug 26, 2007 2:09 pm
Posts: 4
Location: INDIA
@FARZAD


Actually i've set hbm2ddl.auto to create erlier,that's why it is
creating new schema every time new session factory is created.

Now i have set it to validate.

well hbm2ddl.auto have four values:

validate | update | create | create-drop
--
validate- will validate the schema already defined in DB.
update- will update the schema
create- will export and create new schema every time
create-drop- will export and create and drop the schema everytime
session factroy is opened and closed.

Just trying check my understanding of this attribute.

some one plz confirm


Top
 Profile  
 
 Post subject: Re: I have reset hbm2ddl.auto to validate
PostPosted: Sun Mar 02, 2008 11:10 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Quote:
validate- will validate the schema already defined in DB.


right and throws exception if any mismatch is encountered.


Quote:
update- will update the schema


Yes and it is only useful if your jdbc driver provides enough meta data information. Many jdbc drivers don't.

Quote:
create- will export and create new schema every time


Drops and creates the whole schema at sessionfactory create.

Quote:
create-drop- will export and create and drop the schema everytime
session factroy is opened and closed.


drops and creates database at sessionfactory create and drops the database at sessionfactory close.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.