-->
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.  [ 3 posts ] 
Author Message
 Post subject: Please advise: EJB can't synchronize db state with session
PostPosted: Mon Jan 05, 2004 2:36 pm 
Newbie

Joined: Mon Dec 22, 2003 2:39 pm
Posts: 8
I'm trying to use Hibernate in a session ejb in Oracle oc4j.

I've mapped the Cat class (no relationships)
and create/read/update/delete all work fine
in a java application using one Hibernate session.

In the session ejb, I get the Hibernate SessionFactory in
setSessionContext, then use it (or try to)
in the following remote methods:

List read(String hql)
Cat create(Cat cat)
void delete(Cat cat)
void update(Cat cat)

The read and create methods work great.

For delete and update I pass back to the ejb one of the Cats
previously found by read. These methods fail with the following
message:

04/01/05 12:10:40 Hibernate: delete from CAT where id=?
12:10:40,303 ERROR SessionImpl:2269 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)

I've tried doing session.load() before deleting - no go.
I'm sure I'm missing something basic ... can anyone point me to a clear
example of how this SHOULD work?

TIA,
Sandy

Code:
public abstract class CatSFBean implements SessionBean {
  SessionContext c = null;
  SessionFactory sessionFactory = null;
  public void setSessionContext(SessionContext ctx) {
    System.out.println("In setSessionContext()");
    this.c = ctx;
    try {
        this.sessionFactory = new Configuration().configure().buildSessionFactory();
    }
    catch (HibernateException he) {
      he.printStackTrace();
    }
  }
  public void unsetSessionContext() {
    System.out.println("In unsetSessionContext()");
    this.c = null;
  }
  public Cat deleteCat(Cat aCat) throws HibernateException {
    Session session;
    Transaction transaction;
    session = sessionFactory.openSession();
    Transaction tx = null;
    try {
      tx = session.beginTransaction();
      session.delete(aCat);
      tx.commit();
    }
    catch (HibernateException e) {
      if (tx != null)
        tx.rollback();
      throw e;
    }
    finally {
      session.close();
    }
    return aCat;
  }
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 4:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Is data in DB ?
Does id value properly set on cat ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:13 am 
Newbie

Joined: Mon Dec 22, 2003 2:39 pm
Posts: 8
Emmanuel:

I assumed my problem was in understanding
how to use Hibernate since it is so new to me.

Your questions prompted me to look elsewhere.
As it turns out, the key value WAS wrong
(our ui taglib was chopping it short).

Thanks VERY much for your help and fresh viewpoint,
Sandy


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