-->
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: persistent instance not saved after obtaining a lock
PostPosted: Wed Feb 07, 2007 4:52 am 
Newbie

Joined: Mon Jan 22, 2007 10:23 am
Posts: 3
Hibernate version:3.0

Hi this is my first post for this forum.

The persistant instance is not saved to data base .when i am using session.lock(persistent object ,LockMode.READ).

Please give me some explanation on this .

Thanks a lot


Top
 Profile  
 
 Post subject: session.lock() used for persisted records only.
PostPosted: Wed Feb 07, 2007 6:29 am 
Beginner
Beginner

Joined: Wed Nov 15, 2006 4:25 am
Posts: 21
Hai

The method session.lock() is used for only persisted records in the tables.That means it cannot be used for transient objects.This method mainly is used to check the version as the api stated.When loading of the object from the table this method is used .


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 6:46 am 
Newbie

Joined: Mon Jan 22, 2007 10:23 am
Posts: 3
Thanks Shanta,

I am checking for versionging. Here is how i am using .but it is not updating the database.I am trying to use the same persistant instance to check how th versioning works with multiple Hibernate sessions.

Any more additions for checking ?.

Code:
Session session = HibernateSessionFactory.getInstance().getHibernateSession();
      department = (Department)session.createCriteria(Department.class)
         .add(Expression.eq("deptId",new Long("3")))
            .uniqueResult();
      session.close();

      Session session2 = HibernateSessionFactory.getInstance().getHibernateSession();
      Department department2 = (Department)session2.createCriteria(Department.class)
                           .add(Expression.eq("deptId",new Long("3")))
                           .uniqueResult();
      department2.setDeptName("LOGISTICS");
      Transaction transaction = session2.beginTransaction();
      session2.saveOrUpdate(department2);
      transaction.commit();      
      session2.close();
      
      department.setDeptName("ACCOUNTS");
      Session session3 = HibernateSessionFactory.getInstance().getHibernateSession();
      Transaction transaction2 = session3.beginTransaction();
      session3.lock(department,LockMode.READ);
      session3.saveOrUpdate(department);
      transaction2.commit();
      session3.close();


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.