Lazy « Transaction « JPA Q&A

1. hibernate optimistic locking with lazy OneToOne associations

I've run into a variety of the 1-n selects problem described here (stack overflow). I have a Person object with a few OneToOne associations:

Person {
  public Long getOptLock();


2. JPA (Hibernate) - Session/Transaction and lazy loading

I have a Java EE project and the MySQL database is managed with an ORM. I worked a lot with Hibernate to learn what I am doing wrong and I think ...

3. The dreaded Lazy Initialization Exception when using JAX-WS and JEE6

I am getting a LIE when using the JAX-WS @Path and the @Stateless (or @RequestScoped) annotation. The code:

public class UserResourceRESTService {
  private EntityManager em;


4. Hibernate lazy loading requires EJB transaction?

When trying to optimize transactions on my java ee 6 project using hibernate, I tried to do as I did with Eclipselink and have transactions turned off for read-only queries, like ...

5. Lazy loading with JBoss AS 6 and TransactionAttribute.NEVER?

While, with Glassfish 3, I had no problem using lazy loading on no-transaction EJB methods, I can't figure out how to make it work with JBoss AS 6. As a workaround, I ...

6. Lazy session and concurrency session updates

Hi there, This is my first question on the forum because I usually try as much as possible to find solutions by myself, but here I'm stuck. Here the context: - I'm building an Eclipse RCP application (client) which uses Hibernate (+ H2) to store its data - The application mainly works on a huge tree (several millions of nodes) kept ...

7. OSIV, Two Transactions and Lazy Loading

I'm currently making use of the Open Session In View pattern. However, I create 2 transactions, one for the action, one for the view. I'm also making use of the thread local session context. When I commit a transaction for the action, I need to get a new session object instead of re-using the previous session. getCurrentSession() returns me a new ...

8. Transactions and lazy loading

I'm starting a new transaction when running a Query, but to prevent problems with loading Postgres blobs from the returned objects (a Postgres blob must be loaded within a transaction - see my previous post), I'm leaving the transaction open once I've returned the results to the calling method. Unfortunately this leaves me with a couple of processes left running for ...

9. Optimistic locking w/ lazy loading in a client app

I have a client application (Swing) that uses Hibernate 2.1 for database access (SQL Server). I'm using optimistic locking (w/ version numbers). I'm also using lazy loading to get rid of some performance bottlenecks when retrieving large resultsets. Since my application always runs in a single thread, I keep the Hibernate Session, and only one Session, open throughout the application lifecycle. ...

11. Proble with lazy loading, cache, LockMode.NONE and DB

Hello, I've a very strange problem here. We're working with hibernate and hivemind. In the past we work in ours CRUDS with this steps: a- Find an Object with our Finder Component. All the objects we use are retrieved with this component. This component after obtain the object, closes the session. b- Update the disconnected object as the user wish c- ...

13. Lazy loading problems after transaction rollback

Could someone confirm whether this is expected behaviour or a bug. I have a web app using the Spring OpenSessionInViewFilter. My controller code looks as follows (setup for test purposes only): Code: ... Set developers; try { projectManager.saveProject(project); } catch(DataIntegrityViolationException e) ...

14. open transaction required for lazy loading?

I understand that all operatioins on the enitityManager, such as merge, createQuery, find, et. al. must execute with in an open transaction. Is this true for lazy loading? If I'm doing an open em in view thing, does a transaction still have to be open when the view tries to access un-initizlised data fields?

15. Is possible to change runtime lazy query transaction as eage

Aye. We can use size() and others methods. But there is a problem. I want that hibernate do not know the collection name. If I have Entity 1 -> Entity 2 -> Entity 3 - Entity 4. I want to bring Entity 1 instance, and when I will persist in another EM, it knows all related objects from Entity 1. So ...

16. locking object to session and lazy associations

17. Lazy loading, EntityManager and concurrency.