object « Transaction « JPA Q&A





1. How JPA (Hibernate) deal with transaction when fetching Object from database    stackoverflow.com

I'm currently developping an application in java using Hibernate as a persistence manager and JPA as an abstraction of the persistence manage hibernate. I'd like to know the impact of wrapping ...

2. Hibernate session keeping track of objects    stackoverflow.com

I solved my problem, but I just want to get a better understanding of how things are working. I am looping through a collection, creating/initializing a new Product, adding a category it ...

3. Does hibernate a default optimistic locking for detached objects?    stackoverflow.com

I have an application that does:

void deleteObj(id){
    MyObj obj = getObjById(id);
    if (obj == null) {
        throw new ...

4. How can I check whether an object is locked using JPA2?    stackoverflow.com

How can I check whether an object is locked using JPA2? If I'm correct entityManager.getLockMode() checks whether I have a lock, not whether someone else has a lock on the object. I can ...

5. Unable to commit to DB-org.hibernate.TransientObjectException: object references an unsaved transien    coderanch.com

Hi , Can anyone help onthis? I am getting the following error.. I googled through around this error found that adding the cascade="all" will solve this, but am still able to get this error. I am using hibernate to connect to DB. Actually there is a table called say-"ABC1" from which i take data and put into ABC2 table, the ABC2 ...

7. JPA Optimistic Concurrency for Detached Object    coderanch.com

Hi everyone, Is there a way to ask if a detached object is outdated or not? (within an EJB call where entity manager is available of course) My entity has a version column. Say I have a customer who ordered a product he saw on a web page. Upon submission of order, I would pass the detached product (which the customer ...

8. Detaching Objects and Transactions    forum.hibernate.org

I have a current issue with regards to an Object Model that I am using with an ORM model for persisting as well as annotated with JAXB to expose this DAO as a data service. So I have a war -> data service (cxf - interface) -> data service impl -> DAO (JPA/Hibernate). I am using Spring AOP and the transaction ...

9. How to lock newly created objects    forum.hibernate.org

Hi, guys. I'm using hibernate 3.6.0 as persistence provider for JPA inside JBoss AS 6. My scenario is: 1. Create Entity. 2. Persist Entity using EntityManager.persist(myEntity). 3. Call EntityManager.lock(myEntity). All the steps above are done inside the same transaction. As a result I get: Code: Caused by: javax.persistence.OptimisticLockException at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:1240) [:3.6.0.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1166) [:3.6.0.Final] ...





10. How can i lock an Object    forum.hibernate.org

Hi there! I'm trying to lock an object which i've read from the db so no one else can modify it, while i'm working on it. I tried the following: collection = hibernateSession.filter(myObject.getCollection(), "where this.date >= ?", dateFrom, Hibernate.DATE); Iterator iter = collection.iterator(); Transaction tx = hibernateSession.beginTransaction(); while (iter.hasNext()) { session.lock(iter.next(), LockMode.READ); } Now when i debug the code to the ...

11. Non-transactional access to Hibernate objects    forum.hibernate.org

What are the rules for reading Hibernate objects outside of transactions? I wrote a sample program that accesses objects after the transaction commits (but the session is still open) and it appears to work. Objects are loaded from the database and presumably cached. The behavior seems equivalent to JDO's non transactional reads and retainValues. Is this specified anywhere? Thanks.

12. Locking of object    forum.hibernate.org

Hello, What options are there of locking a persisted "object graph" on an application level (not DB) that would prevent people from accidently overwriting each others changes. I have been thinking of a few options: 1. Use a manual "edit-request-lock" by saving the primary key of the entity in a separate table with an expire time. Drawback is of course if ...

13. limit to session.lock(object, lm)?    forum.hibernate.org

I would like to reattach a session to an entity, and this entity has a one-to-many collection. During the transaction, the collection may have some add or update action, so it becomes dirty. But if this entity also has some other lazy loading properties, I will got the "collection is dirty" exception while I reattach Hibernate session to this entity. How ...

14. OJB manages locking objects with several JVM...    forum.hibernate.org

The OJB LockManager manages concurrency between several Threads and between several applications/JVM too! To realise that, it uses extra table in database. I know that hibernate manages concurrency between Threads but what about different JVMs? can hibernet do the same thing? If yes, how to use it? Does it uses extra tables too? Thanks

15. Locking objects with multiple sessions    forum.hibernate.org

Hello, i'm trying to keep the locking state of an hibernate object synchronized across two sessions. I want to lock an object in the first session and check in the second session whether this object is locked or not. The aim is to prevent multiple users to change the same object. Code to check / set lock: Code: if (HibernateAccessor.getInstance().getLockMode((Feld)getUserObject()) != ...

16. Why not implement optimistic lock using object-hashcode    forum.hibernate.org

Object has a extra field to store hashcode, while not add column to table, when object is loaded, hashcode will be computed and saved to hashcode field, when time to flush to database, the same record is loaded and computed hashcode and compare if it is styled, I think such implement is simple, and need not any database native support, even ...





17. hibernate transaction could be usefull with object rollback!    forum.hibernate.org

Team, Hibernate transaction could use object level rollback. I mean as far as i can see it would be easy to add to the framework. At session.transaction hibernate could know and set somewhere that now any saves or updates could be rolled back, and also set the con.setautocomit(false). Then at session.rollback hibernate could do a session.connection.rollback which will make sure that ...

18. two connected objects session.lock()    forum.hibernate.org

i have two objects that are connected (say object A can have reference to object B) i pass both these objects from higher layer into hibernate-enabled layer I do not know has A reference to B or has not, so i session.lock() both these objects. locking A object cascade locking B if there is reference, and lock only A if there ...

19. object retrieval and transactions    forum.hibernate.org

Hi Michael, thanks for the quick reply. I would like to understand this requirement. Up to now I thought I need no transaction as long as I do not change persistent objects. I know this behaviour from other O/R mappers. Why do I need a transaction and what could happen if I call a query without transaction. Could this cause serious ...

21. Object / Transaction state    forum.hibernate.org

Hi, I've written some code that inserts a few things in my database. A user, A course, and the relation between them. I've saved the objects, and commited the transaction. But when i try to loop over the courses of a newly added user, it traps. But afterwards when i retry it, without creating a new user, i nicly displays the ...

22. Reattaching detached objects using lock() and update()    forum.hibernate.org

I am working on a web application. We use Spring for transaction management, have an OpenSessionInView filter and use optimistic locking with Hibernate versioning. When a user edits a record we put the relevant object into the HTTP session and reattach it when they submit / save their changes. At this point we need access to some of the proxied objects ...

23. w to exclusive Lock object    forum.hibernate.org

Hi all. ! I have Hibernate cluster of two server with configure Second Level Cache using. So, I load some Object into Hibernate. This object will stored in Second Level Cache and replicate on cluster nodes. When I try to load this Object from cluster node the Object will load from Second Level Cache. How exclusive lock Object in my cluster ...

24. Optimistic locking in object graph    forum.hibernate.org

Hi all, Let's say I have a parent entity that has children entities, and I enable cascading. If I change one of the children and save the parent, then the child will be persisted, because of the cascade mechanism. All is well. However, Hibernate does not update the time-stamp (or version) column of the parent object - only the child's time-stamp ...

25. refresh and locking memory objects    forum.hibernate.org

Hi to all, For our two-tier Swing application, and having read the discussions found on hibernate.org and other java forums, we have decided to use a never closed entitymanager for read purposes(lazy load, refresh, find...), and all other write purposed operations we open&close temporary entity managers. The application has a tree from where new entities can be inserted or deleted. For ...

26. Does the session object have an INTRINSIC transaction?    forum.hibernate.org

I am getting errors from a PostgreSQL database when trying to programmatically create a new Database. The error I am getting is: ERROR: CREATE DATABASE cannot run inside a transaction block Hmm..the thing is that I did not set up any transaction objects in my code. Code: Session session = HibernateUtil.getSessionFactory().openSession(); Connection c = session.connection(); String databaseName = "TEST"; String user ...

27. Object database persistency / concurrency problem    forum.hibernate.org

Session2.beginTransaction(); MyObj obj3= session.get(MyObj.class, "obj3"); if(obj3==null){ obj3 = new MyObj("obj3",1); }else{ obj3.setMyValue("10"); } MyObj obj1 = session.get(MyObj.class, "obj1"); if(obj1==null){ obj1 = new MyObj("obj1",1); }else{ obj1.setMyValue("10"); } session2.saveOrUpdate(obj3); session2.saveOrUpdate(obj1); session1.commit(); session2.flush();