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
1
vote
0 answers

Hibernate createNativeQuery returning wrong result when adding entity mapping

I have an entity to map historic data on a system. @Entity @Table(name = "historicsview") @XmlRootElement public class ElementsHistorical implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional…
Juan
  • 1,949
  • 1
  • 15
  • 22
1
vote
0 answers

Issue in managing Hibernate transactions

I am using a thread based approach to poll the status of a specific task on AWS. For this, I use a while loop to constantly check the status as shown in below code. The issue is that when the code switches from one Service to another, it runs into…
1
vote
1 answer

Fortify Scan Issue Fix- Unreleased Resource: Database

How can i avoid this issue , for the below line Query query = getSession().createQuery("my sql query"); or Session session = getSession(); SQLQuery query = session.createSQLQuery(""); There are a couple of queries in my DAO implementation and I…
ak19
  • 35
  • 1
  • 5
1
vote
1 answer

org.hibernate.HibernateException: Current transaction is not in progress after migrate to Hibernate 5

I have a class file, CBRTask.java In this CBRTask.java, I have some code as follow: @Autowired private CbrService cbrService; public CBRPayment execute() { try { cbrService.sendCR( this.entity ); // If I manually throw Exception…
Panadol Chong
  • 1,793
  • 13
  • 54
  • 119
1
vote
2 answers

Which is the better way of using Hibernate seesion.delete() - Delete by Id or delete by object?

I am working on an application that is built using Spring MVC, it is using Hibernate to interact with the data store. While I was trying to implement delete functionality, I figured out that there are multiple ways to implement session.delete(). Out…
Dharita Chokshi
  • 1,133
  • 3
  • 16
  • 39
1
vote
2 answers

What collateral effect Propagation.REQUIRES_NEW will cause to my app

I was getting an error like this a different object with the same identifier value was already associated with the session: I've searched and found that it could be fixed with CascadeType.MERGE or refactoring a lot of code to prevent that a same…
Ramon Marques
  • 3,046
  • 2
  • 23
  • 34
1
vote
2 answers

Does the Hibernate Session save operation synchronize with the underlying DB transaction?

Came across this example at HIbernate commit() and flush() Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); for ( int i=0; i<100000; i++ ) { Customer customer = new Customer(.....); …
emilly
  • 10,060
  • 33
  • 97
  • 172
1
vote
1 answer

Can I update or set only one entity field via hibenrate Session.load without loading entire object?

The hibernate session has load method for retrieving a proxy without loading entire object, this is often uses when it is need to link parent and child entity. But what about updating proxy? For example: MyEntity entity =…
Cherry
  • 31,309
  • 66
  • 224
  • 364
1
vote
1 answer

How can I correctly implement an Hibernate SQL query starting from an SQL query that count the number of rows?

I am absolutly new in Hibernate and I have the following problem. I have this standard SQL query: SELECT count(*) FROM TID003_ANAGEDIFICIO anagraficaEdificio INNER JOIN TID002_CANDIDATURA candidatura ON (candidatura.PRG_PAR =…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
1
vote
1 answer

Is the use of Session.buildLockRequest() to reattach entity to EntityManager a practical solution?

My problem is relatively simple: I have an entity with many lazily loaded Sets that I don't need all the time. Now I don't want to load everything eagerly, nor do I want to have several different getSlimEntity(), getFullEntity(),…
1
vote
0 answers

Hibernate, updating an object containing a collection without loading the collection

I have a Project that contains a Set of Columns that contains a Set of Tasks that contains a Set of TaskAssigness. I'm trying to update a column title without having to load its set of tasks, but I get the following error : [AssertionFailure] - an…
Niallith
  • 146
  • 1
  • 2
  • 11
1
vote
0 answers

Null pointer exception while event occur

Exception when scheduled timer event occur..... When i use SetEvent se = new SetEvent(); se.startArchiveEvent(); then i getting following exception.... Exception in thread "Timer-0" java.lang.NullPointerException at…
1
vote
3 answers

Hibernate : session.get(...) vs session.getNamedQuery(...)

In the a transaction process I create/save an object and next to end of transaction I read again object (before setting an history event) @org.springframework.stereotype.Service @Transactional(value="transactionManager") public class UTServiceImpl…
1
vote
0 answers

Hibernate Session practices

I'm working on a task where application uses some configuration from database. Configuration is being stored in java persistent object. On server start Hibernate session gets created and all configuration data is loaded into object with lazy load…
pratikpawar
  • 2,038
  • 2
  • 16
  • 20
1
vote
1 answer

spring transactional nested open session?

If a method of service is marked as @Transactional with propagation nested, and inside it there are many calls to other @Transactional methods, each one of these methods will use its own session? It should represent many connections to db for just…
Ignasi
  • 5,887
  • 7
  • 45
  • 81
1 2 3
8 9