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

Spring Webflow in Grails keeping plenty of hibernate sessions open

I have an Internet app running on Grails 1.1.2 and it integrates Spring WebFlow mechanism. The problem is that there are some bots ignoring robots.txt and are entering the flow quite often. Because second step of the flow needs some human…
Pavel P
  • 637
  • 1
  • 7
  • 21
1
vote
2 answers

When to Use session.replicate() method

As per hibernate documentation:, there is a small example on how to use session.replicate() and usecases for the feature as: Section 11.9. Replicating object between two different datastores: Usecases for this feature include reconciling data…
learner
  • 6,062
  • 14
  • 79
  • 139
1
vote
1 answer

Manually open a hibernate session with Spring config

The issue I am having is that I use Spring to manage and load hibernate for my web application. I am currently using OpenSessionInViewFilter. This works as intended when I am viewing the application, but not so well when I am trying to access…
Raymond Holguin
  • 1,050
  • 2
  • 12
  • 35
1
vote
1 answer

how to managing hibernate session in spring

i have problem with session close what impact during running this application and what if this goes in production. i faceting two problem in my production server its consume lots off memory during application usage around 800MB to just start…
dalwadi
  • 78
  • 5
1
vote
1 answer

When to open hibernate connection and hibernate session?

I have a question related to Hibernate Connection, Session and SessionFactory. The queries are as below: 1) Is it a good practice to open up a connection on every request and close it after that? 2) There is a single sessionfactory which opens up…
Rahul Taneja
  • 417
  • 1
  • 8
  • 18
1
vote
3 answers

Grails Quartz Job has no Hibernate session after upgrade, causing LazyInitializationException

I've upgraded a Grails 1.0.4 application to 1.1.1. After upgrading, I'm repeatedly getting Exceptions when executing my Quartz jobs (using Quartz plugin 0.4.1). The plugin is used to manually schedule jobs using Simple and Cron Triggers via a…
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
1
vote
1 answer

Spring context refreshing makes Hibernate session throw this exception: No Session found for current thread

I am developing a web application that has multiple spring contexts. It has a main context that holds business logic, hibernate session and application's core needs, and other contexts are for spring mvc binding. Normally application works fine and…
Masterhead
  • 53
  • 6
1
vote
1 answer

Hibernate session mode is getting set by default to Manual

I have simple Spring MVC - Hibernate application, that worked fine (inserts & reads data) when connected to MySQL 5.5 database. On connecting the same application to Oracle 10g, it read records from database, but was not able to insert the…
Ujjwal
  • 603
  • 12
  • 23
1
vote
1 answer

Hibernate: Is it possible to do a auto sesssion clear upon transaction commit?

I have lot of separate functions and I'm bound to do a session.clear() upon transaction.commit() in each of them to kind of release memory. I might be wrong but I think, session.clear() in hibernate is not called by default upon…
SSaikia_JtheRocker
  • 5,053
  • 1
  • 22
  • 41
1
vote
1 answer

Hibernate automatic versioning not working (with Spring)

I am trying to use the automatic versioning of Hibernate but when the update method f of the Session is called I do not see the version field in the where clause of the query nor is the version incremented in the database. I am doing something…
alex
  • 705
  • 9
  • 21
0
votes
1 answer

Hibernate delete item

When I try to delete an object using HQL, I use hiberate's session.CreateQuery().executeUpdate() and it returns 1 item is deleted. However, in database, nothing has been deleted. After executeUpdate, I also did flush. Could anyone give me some…
lucky_start_izumi
  • 2,511
  • 13
  • 41
  • 61
0
votes
0 answers

Where to find HibernateSession while mocking using mockito + spring mvc

I am trying to mock the HibernateSession and SessionFactory I am unable to resolve the below in spring mvc @Mock private HibernateSession hibernateSession; I have added the below dependencies `
shaen
  • 21
  • 5
0
votes
0 answers

Doesn't work second-level cache in Hibernate app

I'm trying to connect and test the second level cache in the hibernate application. It seems like I managed to connect the necessary dependencies and set up the config file. But the cache itself does not work when checking, the new session makes a…
0
votes
1 answer

Unable to close the Hibernate Session for loading Lazily loaded fields

We are using Hibernate+Spring for a module and we used @ManyToOne(fetch = FetchType.LAZY) on multiple fields in multiple POJOs. While querying for these POJOs through HQL, I am opening a HibernateSession and returning the result from the DAO method.…
Shaik Bajivali
  • 167
  • 1
  • 16
0
votes
1 answer

Hibernate: ThreadLocalSessionContext: Already session bound on call to bind()

When I try to use the ThreadLocalSessionContext in the following way: Session hsession = HibernateUtils.getSession(); ThreadLocalSessionContext.bind(hsession); // do stuff hsession.close(); I do this for every single Struts Action. Is there…
tomato
  • 5,644
  • 13
  • 43
  • 48
1 2 3
8 9