Thread:
 Not saving object to database 
 baaziabu   19 Jul 2007, 08:09 
 Re: Not saving object to database 
 lmc   16 Jan 2008, 16:17 
 Re: Not saving object to database 
 Nandem   22 Jan 2008, 17:15 
 Re: Not saving object to database 
 dragos_aluculesa   15 Feb 2008, 17:46 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: dragos_aluculesa (15 Feb 2008, 17:46) Replies: 0, Views: 845
Subject: Re: Not saving object to database
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!On 22 Jan 2008 17:15, Nandem wrote:

>what exactly are you guys saving ?
>just one object ?

>well...

>there a many reasons to nHibernate not saving new instances.

>maybe are in
>try { } catch(Exception) { }
>and you cant see the error throws,

>maybe (if u're using <many-to-one unique="true"> tag on hibernate, and
>this object will be saved if u use property (cascade="save-update").

>if in session.FlushMode is setted to FlushMode.Never
>call a session.flush() before call commitTransaction (maybe it works!)


>try change session.FlushMode options.


>are to many reasons for it not work.
>Post the code, and maybe some guy will help ya


>good luck!

I had a situation where althrough I called session.flush() the changes
weare not in the database. after some research i found that where I cal
session.flush() then the querys are runned against the jdbc driver. Here
rezides the problem (if this could be called problem) jdbc connection
was not autocomiting. so, as a hack, I wrote this:

 public Session getSession()
    {
        if(session == null)
        {
            session = sessionFactory.openSession();
            session.setFlushMode(FlushMode.ALWAYS);
            try {
//here my connection is autocomiting
                session.connection().setAutoCommit(true);
            } catch (SQLException e) {
                LOG.error("Can't set connection autocomit");
            }
        }
        return session;
    }

But I read that your data is dissapiring when ypu restart the
application. hmmm... maybe you set         
<property name="hibernate.hbm2ddl.auto">create</property>
on startup hibernate confiruration ...
just check!
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]