• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data deleted while getting data from table using hibernate.

 
prashantk patil
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem while retrieving data from User table.

Mapping in User.hbm.xml like this ::

<hibernate-mapping>
<class name="com.mcardio.entity.User" table="user" dynamic-update="true" catalog="mcardio">
<comment></comment>
<id name="userId" type="string" unsaved-value="sensible" length="30">
<column name="USER_ID" />
</id>
<property name="password" type="string" length="30">
<column name="PASSWORD">
<comment></comment>
</column>
</property>
......
</class>
</hibernate-mapping>

and I try to get data like this ::

User user = (User)currentSession.get(User.class, userId);

But when I try this already added data deleted by the hibernate.
How can I get the data without deleting it is there any mapping problem?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate doesn't delete data as part of a get. Are you using the schema creation stuff in your SessionFactory configuration?
 
prashantk patil
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No sir I am not using any shema my hibernate configuration is like this

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<!-- MySQL db connection -->
<property name="connection.url">jdbc:mysql://localhost:3306/mcardio</property>
<property name="connection.username">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.password">root</property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="hibernate/Patient.hbm.xml" />
<mapping resource="hibernate/Device.hbm.xml" />
<mapping resource="hibernate/PatientDevices.hbm.xml" />
<mapping resource="hibernate/User.hbm.xml" />
</session-factory>

</hibernate-configuration>

And Session is created such as

private static String HIBERNATE_CONFIG_LOCATION = "hibernate/mcardioHibernate.cfg.xml";

private static final Configuration cfg = new Configuration();

And fetch by using code

tx = currentSession.beginTransaction();
//User temp = new User(userId,"doctor","DOCTOR",new Integer(1));
//currentSession.save(temp);
User user = (User)currentSession.get(User.class, userId);
tx.commit();

If I use a commented code above I can save and retrieve it but when I restart tomcat and commenting code for save, the added data automatically deleted.


[ December 22, 2008: Message edited by: prashantk patil ]
[ December 22, 2008: Message edited by: prashantk patil ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No sir I am not using any shema my hibernate configuration is like this

I was meaning Hibernate's schema creation functionality (not an XML schema), and yes you are using it:

This will drop and recreate the schema everytime the SessionFactory is started.
 
prashantk patil
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry and thank you very much.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by prashantk patil:
sorry and thank you very much.


No need to apologize ! Glad you got it sorted
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic