Org.hibernate.TransientObjectException:The instance is not associated with the this session workaround

Source: Internet
Author: User
Tags garbage collection

This exception occurs because a transient object is manipulated as a persistent object. The solution of course is to persist the object, you can call the session's save () or the Saveorupdate () method

Here's the science. Hibernate three states in an object:

In a nutshell, that's the way it is,

1. When an object is new, the object is in a transient state (Transient);
2. After the session's save () or Saveorupdate () method is executed on this object, the object is placed in the session's first-level cache into the persistent state.
2. This object enters a Free State (Detached) after the operation of evict ()/close ()/clear () is performed on this object.
4, Free State (Detached) and transient State (Transient) of the object is not managed by the session will be at the appropriate time by the Java garbage Collection station (garbage) recycling.
5, the execution session of Get ()/load ()/find ()/iternte () and other methods from the database to query the object, in a persistent state (persistent).
6, when the record in the database update ()/saveorupdate ()/lock () operation after the free State of the object will transition to the persistent state
7. Objects in persistent State (persistent) and Free State (Detached) have corresponding records in the database.
8, instantaneous State (Transient) and Free State (Detached) objects can be recycled but the instantaneous state of the object in the database does not have corresponding records, and the Free State of the object in the database has a record of use.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.