Questions tagged [hibernate-session]

A main Java interface to Hibernate persistence service.

A main Java interface to Hibernate persistence service. The Hibernate Session embodies the concept of a persistence service (or persistence manager) that can be used to query and perform insert, update, and delete operations on instances of a class mapped by Hibernate. Instances may exist in one of three states:

  • transient (never persistent, not associated with any Session)
  • persistent (associated with a unique Session)
  • detached (previously persistent, not associated with any Session)

The ORM tool allows to perform all of these interactions using object-oriented semantics by no longer referring to tables and columns, but using Java classes and object properties. As its name implies, the Session is a short-lived, lightweight object used as a bridge during a conversation between the application and the database. The Session wraps the underlying JDBC connection or Java EE data source, and it serves as a first-level cache for persistent objects bound to it.

The Session object is not intended to be thread-safe, instead a new/current Session should be obtained from the session factory for each thread/transaction.

A Session instance is serializable if its persistent classes are serializable.

126 questions
4
votes
2 answers

Hibernate, session, lazyloading

I am developing a Java web application using Hibernate and JSF/primefaces. am sometimes getting errors like 1) an object with same identifier is already associated with session. 2) failed to load lazy initialization *,no session exist or session is…
amFroz
  • 95
  • 1
  • 12
3
votes
3 answers

Hibernate session.load doesn't fill arraylist property of the object

I've got a problem using hibernate's session.load function. I try to get an object according to an ID, and it returns a good object, but only primitive properties are set in the instance. I have a property with is a set (mapped to some other…
Phil Woods
  • 331
  • 1
  • 3
  • 5
3
votes
2 answers

Hibernate: update same object in different session

I'm trying to do that but not working, can anyone suggest me what i'm wrong? In the end I lose the first update EntityManager entityManager1 = JPAUtil.getEntityManagerFactory().createEntityManager(); EntityManager entityManager2 =…
EvilKenny
  • 33
  • 4
3
votes
3 answers

Need I close hibernate session after select or not?

if I use SessionFactory private SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); public Session getSession() { return sessionFactory.openSession(); } And use it in my DAO class: public List
user5620472
  • 2,722
  • 8
  • 44
  • 97
3
votes
1 answer

Should I commit hibernate transaction before calling session.evict(obj)

When should I commit a transaction in hibernate after saving it. Is it before or after I call session.evict(obj). Currently my code looks like this(only required parts). Session session = connector.getSession(); Transaction tx =…
Sanal S
  • 1,105
  • 14
  • 27
3
votes
1 answer

Hibernate - the second query gives Unknown service requested

I'm trying to understand better how Hibernate works... I've a problem I cannot resolve. When the application starts, it makes a query Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); int…
MarioC
  • 2,934
  • 15
  • 59
  • 111
3
votes
0 answers

Closing Hibernate session does not release a lock on table - Hibernate, Derby

I'm trying to save an entity protected void initRequest(T data) { Request request = new Request(); data.setPosRequest(request); request.setTimeStamp(new DateTime()); request.setType(REQUEST); Session session =…
vlcik
  • 911
  • 4
  • 20
  • 33
3
votes
0 answers

Grails Hibernate session unavailable in quartz job?

I am working on an small Grails application which leverages the Quartz plugin for scheduled tasks. It seems that my quartz job does not have access to the hibernate session. Below is the exception. Caused by DataAccessResourceFailureException:…
Mike Croteau
  • 1,062
  • 2
  • 16
  • 43
3
votes
1 answer

Hibernate Session and thread safety

I am trying to understand the meaning of 'Hibernate session are not thread safe'. What I already know (please correct me if I am wrong): A session in non-JTA environment is saved in Thread Local. So it is bound to the current thread. Calling…
Asif
  • 1,288
  • 1
  • 16
  • 27
3
votes
3 answers

java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery - Hibernate Error

Above exception has been throwing While creating a hibernate session factory. In application lib folder have hibernate-jpa-2.1-api and javax.persistence.2.1.0. I can able to see the NamedStoredProcedureQuery class in both jar. But I am getting…
Evan
  • 128
  • 2
  • 9
3
votes
0 answers

How does Hibernate generate sql string from session.get queries

I am using Hibernate 4.2.4 and I am interested to know how Hibernate translate a session.get call to an equivalent sql query that is eventually used to retrieve rows from database. I do not want to log the generated sql in console. I want to use the…
3
votes
0 answers

After session.close() connection is still active with Database

I am working with swing and hibernate. Now for retrive connection, I am using sessionFactory.openSession(). Once I done with DB activity, I am closing same session by session.close(). Now the problem is, when I go on use my application, after some…
Navnath
  • 1,064
  • 4
  • 18
  • 34
2
votes
1 answer

Getting IllegalStateException: Session/EntityManager is closed on session.evict()

I'm getting the following exception : java.lang.IllegalStateException: Session/EntityManager is closed at org.hibernate.internal.AbstractSharedSessionContract.checkOpen(AbstractSharedSessionContract.java:357) at…
2
votes
1 answer

What is the difference between evict() and clear() methods in Hibernate?

I want to detach object from session so I written code like is shown below. But it is not detaching from session, instead it is saving to the database. How evict() and clear() methods work, can anybody answer…
2
votes
2 answers

Hibernate does not flush session when save object using session.save?

First of all take a look at below code, I have three main model to manage StoreHouseand StoreHouseInvetory's and have other model named StoreHouseInventoryLock to temporary lock/unlock some amount of StoreHouseInvetory's when other processes wants…
Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71
1
2
3
8 9