-->
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.  [ 5 posts ] 
Author Message
 Post subject: Object not persisted despite calls to flush() and close()
PostPosted: Fri Dec 30, 2005 11:32 am 
Newbie

Joined: Fri Dec 30, 2005 10:51 am
Posts: 3
Greetings:

I am attempting to create and save a single object to a single database table. The object appears to be properly mapped, and after some difficulty I have been able to properly load and configure Hibernate to talk to my database.

I am using a Derby v10 database, and my Hibernate configration utilizes Derby's Client Driver (as opposed to the embedded one).

I am not using transactions, associations, or cascades. I am simply persisting one simple class to a single table in my database. My attempt to persist an object to this database uses the following procedure:

Session sess = sFactory.openSession();

sess.saveOrUpdate(nAccount);

sess.flush();
sess.close();

where nAccount is a newly created POJO whose properties are set to some values and whose identifier is set to the "unsaved" value (which, according to documentation, tells saveOrUpdate() that the object needs to be "saved").

According to the documentation and the "ask for help" page, (as well as several statements made in this forum) Hibernate is supposed to actually do the save to the database once the session object's flush() method is called. This, unfortunately, does not appear to be happening.

What is actually happening is that the saveOrUpdate(), flush(), and close() methods are executing without generating any messages or exceptions, but nothing is being saved to the database! I run my test application and everything works without apparent problems, but my database apparently remains untouched.

Have I found a bug in Hibernate's interface to Derby? Or am I missing something?

Someone please advise.

_________________
Factor Three


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 11:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
"I am not using transactions"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 11:49 am 
Newbie

Joined: Fri Dec 30, 2005 10:51 am
Posts: 3
christian:

Thank you for your reply (I think). Please elaborate.

_________________
Factor Three


Top
 Profile  
 
 Post subject: You need to use transactions
PostPosted: Fri Dec 30, 2005 1:02 pm 
Beginner
Beginner

Joined: Thu Dec 29, 2005 12:08 pm
Posts: 31
Location: Acton, MA
Try:

Session sess = sFactory.openSession();
Transaction t = sess.beginTransaction();

sess.saveOrUpdate(nAccount);
t.commit();
sess.close();

(Typed off the cuff; that's the general idea anyway.)

Best,
Laird


Top
 Profile  
 
 Post subject: Re: Object not persisted despite calls to flush() and close(
PostPosted: Sat Dec 31, 2005 10:58 am 
Newbie

Joined: Mon Dec 26, 2005 7:58 am
Posts: 9
Factor Three wrote:
Greetings:

Hibernate is supposed to actually do the save to the database once the session object's flush() method is called. This, unfortunately, does not appear to be happening.

What is actually happening is that the saveOrUpdate(), flush(), and close() methods are executing without generating any messages or exceptions, but nothing is being saved to the database! I run my test application and everything works without apparent problems, but my database apparently remains untouched.
....


It's depends: if you are using CMT i.e Container-Managed-Transaction and you code is running in some session bean you are not supposed to see any Hibernate logs after flushing the session or closing it. U should see H messages after the function has been terminated "by" the container.
If U are not using container-managed: i don't know. Sorry.


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