-->
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.  [ 7 posts ] 
Author Message
 Post subject: Row from Database getting deleted
PostPosted: Fri Dec 21, 2007 3:52 am 
Newbie

Joined: Fri Dec 21, 2007 3:24 am
Posts: 4
Hi There,

i have written a simple hibernate application to retrieve rows from a table. but whenever i run this application, the rows in the table are getting deleted. Can any one help in finding out the reason and suggest a solution!
i am putting the code below:
----------------------------------------------------------------
package test;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;


public class AssociateDetailsTest {

public static void main(String[] args) {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("from AssociateDetails assDtls");
List results = query.list();
System.out.println("results: " + results.size());
session.close();

}

}


---------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 1:24 pm 
Beginner
Beginner

Joined: Wed May 16, 2007 7:12 am
Posts: 41
Location: London
You need to say session.delete(object);
You need to read more documentation.

here http://www.hibernate.org/hib_docs/v3/reference/en/html/
You need to thank everyone for not flaming you :)

_________________
Dinesh Mahadevan

Visit me at http://www.yelani.com/


Top
 Profile  
 
 Post subject: Can u pls elaborate?
PostPosted: Wed Jan 02, 2008 10:19 am 
Newbie

Joined: Fri Dec 21, 2007 3:24 am
Posts: 4
Hey
Thanks for ur reply. I m new to hibernate and surely i do need to read more documentation. But can u pls elaborate, i really didn't get u....

regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 3:33 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
Check your hibernate configuration and make sure you DON'T have something like this set:

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>


Top
 Profile  
 
 Post subject: Hiberante errror!!!! InstantiationException:
PostPosted: Wed Jan 09, 2008 2:26 am 
Newbie

Joined: Fri Dec 21, 2007 3:24 am
Posts: 4
After i removed the

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

property tag from hibenate.cfg.xml file rows are not being deleted, but i got this new error. Can any one help???


----------------------------------------------------------------------------

Exception in thread "main" org.hibernate.InstantiationException: No default constructor for entity: associate.AssociateDetails
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:84)
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:100)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:351)
at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3606)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1275)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1264)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1206)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at test.AssociateDetailsTest.main(AssociateDetailsTest.java:18)

-----------------------------------------------------------------------

Complete code is in the previous post.


regards


Top
 Profile  
 
 Post subject: "no default constructor"
PostPosted: Wed Jan 09, 2008 8:14 am 
Beginner
Beginner

Joined: Thu Jun 21, 2007 9:24 pm
Posts: 20
Location: Lansing, Michigan, USA
Your AssociateDetails class needs to have a no-argument constructor:

Code:
public class AssociateDetails {
  AssociateDetails() {}
}


Top
 Profile  
 
 Post subject: Thank u all...
PostPosted: Thu Jan 10, 2008 3:57 am 
Newbie

Joined: Fri Dec 21, 2007 3:24 am
Posts: 4
I sincerely thank u all for ur help......
finally i solved the problem.

regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.