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
2
votes
1 answer

hibernate does not set aliases and oracle throw `ORA-00918: column ambiguously defined` error

I'm using hibernate 4.3.11.Final, and have this model and .hbm.xml file: Domain Class public class Dossier { private Long id; private Power power; private String dossierNumber; // getter and stters } Hibernate Mapping…
Rasool Ghafari
  • 4,128
  • 7
  • 44
  • 71
2
votes
1 answer

Hibernate - Could not obtain transaction-synchronized Session for current thread

I understand this question has been asked many time, but most can't explain my problem: @RequestMapping("/testing") public String testing(HttpServletRequest request, final ModelMap model) { Transaction ut =…
Sam YC
  • 10,725
  • 19
  • 102
  • 158
2
votes
0 answers

Why session.get(...) solve org.hibernate.NonUniqueObjectException?

I'm working with Hibernate 4, Struts2, to attempt the removal of an entity, the following exception was thrown: org.hibernate.NonUniqueObjectException: a different object With the same identifier value was Already Associated With the session I was…
SerchRac
  • 171
  • 1
  • 12
2
votes
0 answers

Hibernate + Spring: cannot filter lazy loaded collection

I'm implementing the soft delete logic for my entities using Spring and Hibernate. I use @Filter Hibernate annotation to perform this logic. But there is a problem I cannot resolve: the objects in lazy loaded collections are not being filtered. The…
iozee
  • 1,339
  • 1
  • 12
  • 24
2
votes
1 answer

@NaturalId only valid on root entity (or its @MappedSuperclasses), using Natural Id in Joined, Multiple Table Inheritance

basically I cant find in google some similar problems by just pasting the root exception "@NaturalId only valid on root entity (or its @MappedSuperclasses)" in the search tab. I'm using a Joined, Multiple Table inheritance strategy to map my…
2
votes
1 answer

Best practice for querying inside event listeners in Hibernate

We have a FlushEventListener to do audit functionality. While updating some entity, hibernate will callback our audit code just before flushing. The audit code needs to query the database. If we try to do it in the same session apparently we mess…
Victor Basso
  • 5,556
  • 5
  • 42
  • 60
2
votes
1 answer

Changing Hibernate Session.FlushMode during the Session

My Application uses FlushMode.AUTO . For a particular service method call I want to change Hibernate Session.FlushMode to FlushMode.COMMIT and revert back to FlushMode.AUTO when the method completes. Question:- Are there any problem/dangers of…
harrybvp
  • 2,445
  • 2
  • 22
  • 30
2
votes
1 answer

Hibernate Session Factory

In our web application we have a HibernateSessionFactory class, that is opening and closing connections. Everything is okay, but when we are updating data in the database, it doesn't change in our application. Unfortunately, we see old data from the…
Lilit Mkrtchyan
  • 135
  • 1
  • 2
  • 11
2
votes
2 answers

How to properly close and open a Hibernate session?

I have the following method that inserts a large batch of records every few seconds. After some time of running I get errors like the following: ERROR: Communications link failure The last packet successfully received from the server was 523 …
Atma
  • 29,141
  • 56
  • 198
  • 299
2
votes
2 answers

Grails withNewSession does not flush

In a grails Domain a have implemented the beforeDelete as follow class Shop { def beforeDelete() { Shop.withNewSession { Client.findAllByShop(this)*.shop = null } } } But the client shop null…
Fabiano Taioli
  • 5,270
  • 1
  • 35
  • 49
2
votes
1 answer

why is database call sleeping after some limited call

It is a Q&A-style. While using SessionFactoryUtils.getSession to get a session and doing my query, it can be call only limited count and will be waited in calling after that limit count. Why it happens? try { SessionFactory…
mirzaei
  • 363
  • 1
  • 3
  • 10
1
vote
2 answers

Check in-memory version of an object against the data in the database

I have a Hibernate project where a call to update() needs to compare the modified object in memory to the data that has already been saved to the database. For example, my business logic states that if a record is "effective" (the effective date is…
RustyTheBoyRobot
  • 5,891
  • 4
  • 36
  • 55
1
vote
1 answer

No Hibernate Session bound to thread with generic-hibernate-dao library

I'm working with Spring 3.0.5,Hibernate 3.3 and generic-hibernate-dao. I've configured Hibernate SessionFactory as below:
Deepak Marur
  • 537
  • 1
  • 13
  • 27
1
vote
0 answers

session.setFlushMode(FlushModeType.COMMIT) not working properly in Hibernate

In Hibernate setting FlushModeType.COMMIT on session object should flush the persistence context only when we explicitly commit the transaction right? Here I have set FlushModeType.COMMIT on session object and both query objects as well, so when I…
Abhi
  • 11
  • 3
1
vote
0 answers

Hibernate Returns Wrong List From Cache Even Expected List is Different Than the Cached One

In the code below if I don't clear current session, just the number of girls is returned from the method even if I want to return number of all children of this parent. It's clearly seen that parent with id 1 has three children (2 girls and 1 boy),…
H.Ç.T
  • 3,335
  • 1
  • 18
  • 37
1 2
3
8 9