When you call session.save() your object is not necessarily getting
sent to the database, and thus database constraint violations may not
be thrown. If you want to ensure the object is sent to the database at
that point call session.flush() which "...is the process of
synchronizing the underlying persistent store with persistable state
held in memory."
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#flush()

Josh

On Fri, Mar 14, 2008 at 2:17 AM, Angelo Chen <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> Following code is trying to save a new record with an email which already
> exists, after running, then try to update the same record in another progam,
> I got:
>
> Lock wait timeout exceeded; try restarting transaction
>
> un comment out //sessionManager.Abort, above problem fixed. but I still get
> this error in the log, looks like after abort, hibernate still trying to
> save:
>
> [ERROR] JDBCExceptionReporter Duplicate entry '[EMAIL PROTECTED]' for key
> 2
> [INFO] TimingFilter Request time: 42 ms
> [ERROR] AssertionFailure an assertion failure occured (this may indicate a
> bug in Hibernate, but is more likely due to unsafe use of the session)
> org.hibernate.AssertionFailure: null id in org.bfe.istudio.t5.entities.Usr
> entry (don't flush the Session after an exception occurs)
>        at
> org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
>        at
> org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157)
>        ...
>
>
> @Inject private Session session;
>
> @Inject
> private HibernateSessionManager sessionManager;
>
> public void onActivate() {
>
> Usr usr = new Usr();
> usr.setName("123");
> usr.setEmail("[EMAIL PROTECTED]");
>
> try {
>        session.save(usr);
> } catch (HibernateException e) {
>        //sessionManager.abort();
> }
>
> <property name="hibernate.connection.autocommit">false</property>
>
>
> --
> View this message in context: 
> http://www.nabble.com/t5%3A-handling-of-hibernate-exceptions-tp16047005p16047005.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to