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

Hibernate filter on ManytoOne mapping

@FilterDef(name = CommonConstants.PRODUCT_FILTER, parameters = {@ParamDef(name="products", type = "long")}) @Filter(name = CommonConstants.PRODUCT_FILTER, condition = "alert.product in (:products)") @NoArgsConstructor @SuperBuilder public class…
0
votes
0 answers

Hibernate Session: How to always get the latest state of my entity before making changes

I am developing a multi-threaded application and therefore I am currently trying to figure out a way to always fetch latest state of my entity instances from the database before making changes to any of their fields. From the hibernate documentation…
elsamuray7
  • 79
  • 1
  • 10
0
votes
1 answer

Why hibernate is saving values without transaction?

i'm using spring boot(2.1.4) with hibernate(5.3.9). public class BaseDao{ @Autowired private SessionFactory sessionFactory; private Session session; private Transaction transaction; @Autowired private EntityManagerFactory…
0
votes
4 answers

Do I need to enclose all saveOrUpdate methods with try-catch?

Do I always need to enclose the saveOrUpdate or delete on Session in DAOs with try-catch block like this bellow? public void save(Inventory object) { try { factory.getCurrentSession().saveOrUpdate(object); } catch (Exception e) { …
Rihards
  • 10,241
  • 14
  • 58
  • 78
0
votes
0 answers

collection is not associated with any session

Can anyone help me with this exception, tried every way mentioned online but still it is getting failed in the server. This is to find all user with pagination based on the specs. pasting the exception for your reference. Exception…
Demolition
  • 138
  • 1
  • 1
  • 10
0
votes
0 answers

When to use transaction.rollback() in hibernate

When we call transaction.rollback(), Hibernate rolls-back the database transaction. Database handles rollback, thus removing newly created object. But I am not able to understand if we should use rollback in catch block even if we have only one row…
Shivakumar N.R
  • 170
  • 1
  • 12
0
votes
1 answer

Hibernate Session Factory is expensive-to-create

I read everywhere that Hibernate SessionFactory is expensive-to-create operation. But there is no clarity on what is the expensive part ? Can anyone please explain.
0
votes
1 answer

ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Exhausted Resultset , hey i am getting this exception in my hibernate code?

WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 17011, SQLState: 99999 ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Exhausted Resultset org.hibernate.exception.GenericJDBCException: could not execute query at…
yash
  • 51
  • 1
  • 9
0
votes
1 answer

How to properly manage session in Hibernate while dealing with OneToMany relationship?

I have these two classes with OneToMany relationship : Post.java : @OneToMany(mappedBy = "post") private List comments; Comment.java : @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "idPost") private Post post; I am trying to get…
Farouk
  • 136
  • 1
  • 10
0
votes
1 answer

Hibernate session cache behavior in clustered environment?

I was asked the following question in one of the interviews I attended - Let's say we have multi-clustered application servers, where each has created its own SessionFactory (pointing to same single DB). One server retrieves a record [Person with…
sanbhat
  • 17,522
  • 6
  • 48
  • 64
0
votes
2 answers

I want to remove completed orders from a list

In my App I have List of Orders. I want to remove completed orders from that list. that means the status = Completed.There are more two status. so I try this. Session s = HibernateSession.getSession(); Criteria c = HibernateSession.createCriteria(s,…
0
votes
1 answer

Transaction management in JSP with Springboot

Is there a way to simply obtain detached entities in a Springboot application? In order to illustrate (I leave the strict minimum) : Here a repository of entity A: public interface ARepository extends JpaRepository { (...) } Here a manager…
Mohicane
  • 302
  • 2
  • 15
0
votes
1 answer

How Hibernate/Jpa differs transient and detached instance/object?

Actually these two are very good questions: How Hibernate differs transient and detached entities? Check for detached entity in Hibernate I have actually read this many time, and check some posts in stackoverflow. A lot of answers are just copied…
Sam YC
  • 10,725
  • 19
  • 102
  • 158
0
votes
0 answers

Hibernate insert and select operation fail when executed in a single method

I am using hibernate to do CRUD operations with mySQL DB server. I am running into a weird problem where when I do an insert operation, the operation is successful. I even can check the values in the DB using a DB editor. Now if I try to fire a…
Vicky
  • 104
  • 1
  • 9
0
votes
1 answer

Not able to access one transaction session data in other transaction

I am using Spring transaction with hibernate jpa. I have one active transaction inside which i created a transaction using Propogation.RequiredNew how to make first transaction session data available in next transaction
1 2 3
8 9