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.  [ 1 post ] 
Author Message
 Post subject: No StaleObjectException with union-subclass inheritance
PostPosted: Fri Jul 15, 2005 2:33 pm 
Newbie

Joined: Wed May 25, 2005 7:24 am
Posts: 11
Location: Austria
I just have two classes, Being and Alien. Alien is derived from Being and I am using table per concrete class with union-subclass tag.
After creating two aliens in the setUp() from my testcase I use two different sessions (s1 and s2) to load one and the same object. Now I change something in session s1 and commit. Everthing is fine until here.
At next I change something in session s2 and commit...Now there should be an StaleObjectException...but there is NONE?!?!. I also tried this with joined-subclass inheritance but it also doesn´t work. I don´t have any idea whats wrong. Maybe someone can help me out of that mess.
I also tried optimistic-locking with just one class (I mean there was no inheritance) and it worked perfect, but with inheritance..no chance!

Thanks, Al

Hibernate version: 3.0.5

Mapping documents:
Code:
<hibernate-mapping>
   <class name="persistent.Being" abstract="true" dynamic-update="true" optimistic-lock="all">
   
      <id name="id" unsaved-value="0" column="ID">
         <generator class="increment"/>
      </id>
      
      <property name="identity" not-null="true" column="IDENT"/>
      
      <set name="friends" table="BEINGS_FRIENDS_US">
         <key column="BEINGID"/>
         <many-to-many column="ID" class="persistent.Being"/>
      </set>
      
   </class>
</hibernate-mapping>

Code:
<hibernate-mapping>

   <union-subclass name="persistent.Alien" extends="persistent.Being" dynamic-update="true" table="ALIENUS">
      <property name="species" not-null="true" column="SPECIES"/>
   </union-subclass>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
protected void setUp() throws Exception
  {
    super.setUp();

    try
    {
      tx = session.beginTransaction();
      Alien a1 = new Alien();
      a1.setIdentity("c3po");
      a1.setSpecies("Translator");
         
      Alien a2 = new Alien();
      a2.setIdentity("R2");
      a2.setSpecies("Fighter");
         
      session.save(a1);
      session.save(a2);
      tx.commit();
    }
    catch (Exception ex)
    {
      tx.rollback();
      fail("Exception thrown: " + ex.getMessage() + ", " + ex.toString());
    }
  }

public void testConcurrencyUpdateFail()
  {
    try
    {
      tx = s1.beginTransaction();
      Query q1 = s1.createQuery("FROM Alien alien WHERE alien.identity = ?");
      q1.setString(0, "c3po");
      Alien a1 = null;
      a1 = (Alien)q1.uniqueResult();
      tx.commit();
      assertNotNull(a1);
     
      tx = s2.beginTransaction();
      Query q2 = s2.createQuery("FROM Alien alien WHERE alien.identity = ?");
      q2.setString(0, "c3po");
      Alien a2 = null;
      a2 = (Alien)q2.uniqueResult();
      tx.commit();
      assertNotNull(a2);
     
      tx = s1.beginTransaction();
      a1.setIdentity("c4po");
      s1.update(a1);
      tx.commit();
     
      tx = s2.beginTransaction();
      a2.setIdentity("c5po");
      s2.update(a2);
      tx.commit();
      fail("NO StaleObjectStateException thrown!!!");
    }
    catch (StaleObjectStateException ex)
    {
      tx.rollback();
    }
  }

  protected void tearDown() throws Exception
  {
    super.tearDown();
   
    try
    {
      tx = session.beginTransaction();
      Query q = session.createQuery("FROM Alien");
      List l = q.list();
     
      Iterator i = l.iterator();
      while (i.hasNext()) {
          Alien a = (Alien)i.next();
          session.delete(a);
      }
      tx.commit();
     
      tx = session.beginTransaction();
      l = q.list();
      tx.commit();
      assertFalse(l.iterator().hasNext());
    }
    catch (Exception ex)
    {
      tx.rollback();
      fail("Exception thrown: " + ex.getMessage() + ", " + ex.toString());
    }
    finally
    {
      session.connection().close();
      session.close();
    }
  }


Full stack trace of any exception that occurs:
There is no exception...that´s my problem ;-)

Name and version of the database you are using:
Oracle9i Enterprise Edition Release 9.2.0.1.0
JDBC driver: Oracle JDBC driver, version: 9.2.0.5.0

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Code:
Hibernate: insert into ALIENUS (IDENT, SPECIES, ID) values (?, ?, ?)
Hibernate: insert into ALIENUS (IDENT, SPECIES, ID) values (?, ?, ?)
Hibernate: select alien0_.ID as ID, alien0_.IDENT as IDENT0_, alien0_.SPECIES as SPECIES2_ from ALIENUS alien0_ where alien0_.IDENT=?
Hibernate: select alien0_.ID as ID, alien0_.IDENT as IDENT0_, alien0_.SPECIES as SPECIES2_ from ALIENUS alien0_ where alien0_.IDENT=?
Hibernate: update ALIENUS set IDENT=? where ID=?
Hibernate: update ALIENUS set IDENT=? where ID=?
Hibernate: select alien0_.ID as ID, alien0_.IDENT as IDENT0_, alien0_.SPECIES as SPECIES2_ from ALIENUS alien0_
Hibernate: delete from ALIENUS where ID=?
Hibernate: delete from ALIENUS where ID=?
Hibernate: select alien0_.ID as ID, alien0_.IDENT as IDENT0_, alien0_.SPECIES as SPECIES2_ from ALIENUS alien0_
[/i][/u]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.