Session « Transaction « JPA Q&A





1. Hibernate transaction duplicate problem    stackoverflow.com

I want update some of my table in database and want all of these work do in 1 transaction, first of all I delete some entry in branchbuildin(Table) and Insert new one ...

2. Extended Session for transactions    stackoverflow.com

What is 'Extended Session Antipattern' ?

3. Hibernate Session scope in JTA transactions vs Open-Session-In-View    stackoverflow.com

Is it correct to say that using JTA Transactions with Hibernate contrasts using the Open-Session-In-View with regards to the session scope?
From what I've been able to gather the Session scope in ...

4. Java RMI and Hibernate: Managing sessions and transactions    stackoverflow.com

In my ASP.NET projects I follow a transaction-per-request pattern for dealing with NHibernate using a custom HttpModule. I've recently been working on a Java client and server app using RMI and ...

5. Hibernate session management for multiple transactions ?    stackoverflow.com

What is the best way for maintaning Hibernate session for multiple database transactions? Do I need to open and close each session every time or should I rely upon getCurrentSession()? Whats ...

6. Hibernate: Session and Transaction    coderanch.com

this post continues this conversation. here's what i got from Hibernate API: A transaction is associated with a Session and is usually instantiated by a call to Session.beginTransaction(). A single session might span multiple transactions since the notion of a session (a conversation between the application and the datastore) is of coarser granularity than the notion of a transaction. However, it ...

8. Multiple transaction in same session possible in hibernate??    coderanch.com

Hi, Is it possible to work on more than one transaction with the same hibernate session object ?? I'm getting some problem by doing like this, . . ........ ........ Session session = sessionFactory.getSession(); Transaction tx = null; While(totalObjects) { tx = session.beginTansaction(); try { session.saveOrUpdate(Object); tx.commit(); } catch(Exception e) { tx.rollback(); throw e; } ...... ...... } In the above ...

9. Of Hibernate sessions and transactions    coderanch.com

I guess I'm still confused as to what's happening in my code snippet. If a session is opened with openSession() I'd assume that a new session is created. I'd then expect a call to getCurrentSession() to return that session rather than create a new one. If a new one is created by getCurrentSession() but subsequent calls to getCurrentSession() return that same ...





10. Where to open Hibernate Session and Transactions    coderanch.com

Hi I want to know where is the best to open the Hibernate session with spring MVC application, in Controllers, Service Layer or at DAO level. I have opened a session and transaction at service level it works fine for the first time when i login but when i try to perform next operation Say Delete, I get the following exception ...

11. session-per-request or session-per-transaction?    forum.hibernate.org

Let's say I have a website with a rather large number of visits, perhaps 10-20 per second with occasional brief spikes of 10 times that or so. Strictly from a performance perspective, is there a measurable downside to keeping Hibernate sessions open for the entire length of the request? The documentation seems to indicate that opening a Hibernate session at the ...

12. 2 transactions in one Session    forum.hibernate.org

I am using Open Session In View Filter. My request handling needs to perform an update operation and ras well eturn a different data with lazy loaded data points. My "Update transaction" doesn't get flushed until the request is processed. I have read about configuring two transactions per session, one for update and the other for read. Can someone please tell ...

13. jta with managed Session scope    forum.hibernate.org

I was going through 'Java Persistence with Hibernate' book and got stuck at Page#494. We do extending a conversation by setting hibernate.current_session_context_class to managed; does that mean now I cannot use 'jta' inside my methods? This assumptions is getting more stronger when I looked at the interceptor code at Page#494. In the interceptor, we are calling 'currentSession.beginTransaction' that means we are ...

14. How to use session.lock()    forum.hibernate.org

Supose I'm using a database that support SELECT FOR UPDATE like PostgreSQL .... When I lock the object and another user try to select it ... the second user don't get an error or exception reporting the lock, so I can't report the lock to user and the application will stay locked !! Is possible to control when a lock occurs? ...

15. Optimistic Locking in multiple sessions    forum.hibernate.org

I have implemented Optimistic Locking; it works in one environment and not in other. In my test case, I load 2 objects using the same id. Initially the version number in the database is 0. I make changes to both first and second object. I saveOrUpdate the first object it works fine, and the version number is updated to 1. When ...

16. session and transactions and postgres...    forum.hibernate.org

I have a strange thing happening here. Using sessions from multiple ejb beans, with jboss and postgres as the backend, I can see that both EJBs run fine up to a point, but the first to reach insert/update, seems to block the other (becomes UPDATE waiting postgres process ... or INSERT waiting) As soon as I call session.close(), the other ejb ...





17. Scope of session vs JTA transaction    forum.hibernate.org

18. session.lock() semantics    forum.hibernate.org

Hi, I need to be able to grant exclusive access to a persistant object in our object model to a single user. I intend to use session.lock(theObj, LockMode.UPGRADE_NOWAIT), but I'm a bit confused as to how this works. Could someone answer the following questions for me? 1) Does calling session.lock() automatically re-SELECT the specified object with the "FOR UPDATE NOWAIT" clause? ...

19. session.lock() semantics    forum.hibernate.org

Hi, I need to be able to grant exclusive access to a persistant object in our object model to a single user. I intend to use session.lock(theObj, LockMode.UPGRADE_NOWAIT), but I'm a bit confused as to how this works. Could someone answer the following questions for me? 1) Does calling session.lock() automatically re-SELECT the specified object with the "FOR UPDATE NOWAIT" clause? ...

20. session.lock and TransientObjectException    forum.hibernate.org

public void run1() throws Exception { Session _session = HibernateSession.currentSession(); Team _team = (Team) _session.load(Team.class, new Long(1)); HibernateSession.closeSession(); _session = HibernateSession.currentSession(); _session.lock(_team, LockMode.NONE); //_team.getPlayers().iterator(); HibernateSession.closeSession(); }

21. Transactions in Session bean and hibernate    forum.hibernate.org

22. Session and Transaction    forum.hibernate.org

23. Session-per-transaction or ThreadLocalSession?    forum.hibernate.org

I'm revisiting this topic because I'm implementing my business logic behind stateless session beans. I could be wrong, but I don't think http://hibernate.org/42.html (ThreadLocalSession) applies to this situation. What I really want is a session-per-transaction here, but after thinking it through, I realize this could be tricky. First, an SLSB instance, while living in a single thread, can be invoked by ...

24. session per application transaction    forum.hibernate.org

You can use both styles, a Long Session or Detached Objects/Reattachment for each request/response. Keep in mind that you have to close the Long Session at some point, usually at the end of your application transaction. The atomicity aspect is simple: If you have n database transactions in 1 application transaction, only the last database transaction should write data. For example, ...

25. Hibernate in J2EE: issues on Session and Transactions    forum.hibernate.org

hi all, i m a beginner with Hibernate and i want to ask few questions about how can i use it in a J2EE app. I have implemented a 'PersistenceManager' layer in my app, which is in charge of interacting with the database. My app is a struts-based app, so i have downloaded the hibernate plugin for struts which instantiates a ...

26. Reuse Hibernate Session instances within a transaction    forum.hibernate.org

Author Message jnizet Post subject: Reuse Hibernate Session instances within a transaction Posted: Wed Jul 07, 2004 3:51 am Newbie Joined: Fri Jul 02, 2004 11:18 am Posts: 5 Hi. I'm beginning with Hibernate, and I'm trying to use it within JBoss CMT session beans. I find it a bit strange to open, flush and close a session each ...

27. Multiple "application transactions" per session?    forum.hibernate.org

if you know exactly how to handle this design, you can use it. You must know that many : - httpRequest for one httpSession (i suppose you are storing the hibernate session somewhere via httpSession) is always possible (refresh IE F5), - and that hibernate session isn't threadsafe - what happens if a user go away take a coffe? his httpSession ...

28. transactions and sessions?    forum.hibernate.org

Hibernate version: 2.1 Hi. I'm having trouble getting proper transactional semantics with Hibernate in Weblogic 7.0, and would appreciate any help on the subject. I have a big loop which manages another component of the application via the database and the JMS. Some of its work must be transactional - for example, sending a message to the JMS and updating a ...

29. Session and Transaction scope    forum.hibernate.org

30. Multi transaction by one Session    forum.hibernate.org

Newbie Joined: Wed Sep 29, 2004 8:39 pm Posts: 1 I want to carry out a Multi transaction by one Session. My code is as follows. Then, I am waiting for a reply. Thank you. Code: public void csvUpload(List admArtistCSVInfoList) throws Exception { Session session=null; try{ /* START SESSION */ session = SessionManager.currentSession(); Calendar calendar = Calendar.getInstance(); Date currentDate = calendar.getTime(); ...

31. Optimistic Locking and Stateless Sessions    forum.hibernate.org

I'm working with a client who is using Hibernate. They have NOT implemented any locking strategies yet as it is a low contention site. Once they get the site up and running, it will be a very high volume site (but still low contention). Consequently their architecture specifies both a stateless app server (Websphere) and a stateless UI Server (Tomcat). As ...

32. Sessions and Transactions    forum.hibernate.org

Why is the scope of a transaction different than the scope of a session? In other words, why can I have multiple transactions on a single session? I don't really see a use case where it would be safe to have several transactions on a single session since a transaction commit will flush the session, possibly committing changes to dirty objects. ...

33. Session spanning multiple JTA transactions    forum.hibernate.org

[I never got a real answer to this in the Hibernate3 forum, but hopefully some "pre version 3" users can provide the solution] If a Hibernate Session spans several JTA transactions (or in any other way connects to the database before a JTA transaction), the connection Hibernate uses will not be correctly enlisted with the JTA transaction, since it is cached ...

34. How to maintain the session throughout a transaction?    forum.hibernate.org

Hello, Could someone help me in handling this problem ? Say a transaction involves 3 database calls and i need to commit the transaction only when all three database calls succeed without any exceptions. This means that i cannot create, commit and close a seperate session for each of these 3 calls. How do i maintain the session across the transaction. ...

35. Embedded Transactions from Single Session?    forum.hibernate.org

36. Whats the semantic behind Sessions lock operation?    forum.hibernate.org

Whats the semantic behind Sessions lock operation? Should it be called 'reattach' and for historic reasons it is not? What is considered the identity of an object for this method to throw a 'NonUniqueObjectException', is it the id (database id) of the object? or the java identity? It sounds perfectly good to me the implementors decide to throw a exception when ...

37. transactions and sessions    forum.hibernate.org

we are using hibernate 3.0.5 We create the session, begin a transaction do some work commit transation begin transaction try to do some more work and get error saying unable to obtain session. So, what happens one you commit transacion? Do you loose the session? How do you do multiple commits with the same session?

38. session.lock does not reattach    forum.hibernate.org

Hibernate version: .2.1.7c Mapping documents: User .... Entity:

39. Guru: How to do >1 sessions-per-application-transaction?    forum.hibernate.org

Hi, I am designing a web application that requires opening more than 1 databases. I have to use the session-per-application-transaction pattern and I am wondering how to save more than 1 sessions in HttpSession and access them via the ThreadLocal. Referring to the following snippets from CaveatEmptor 3.1alpha 3, the HibernateFilterLong class: Code: public void doFilter(ServletRequest request, ...

40. multiple open sessions with in a single transaction    forum.hibernate.org

I am using H3 and have some basic questions (or ideas) regarding multiple open sessions with in a single transction. Any body know of any links/articles that deal with this topic? Specifically, If and when whould the updates made to an object in one session (and flushed) be visible in a new session in the same transaction? (first session is still ...

41. Managing the session on the JTA transaction    forum.hibernate.org

42. two open transactions for one session    forum.hibernate.org

43. Optimistic locking and multiple session use    forum.hibernate.org

Code between sessionFactory.openSession() and session.close():/* * Title: $Id$ * Classification: Restricted-Commercial * Copyright: Copyright (c) 2005 * Company: EADS-DS UK * Author: bakers * Modified: $Author$: $Date$ * Version: $Revision$ * * Package: HibernateUtil * Classes: com.cogent.infrastructure.hibernate.util; */ package com.cogent.infrastructure.hibernate.util; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.UserTransaction; import org.hibernate.Session; import org.hibernate.SessionFactory; import ...

44. How to spawn multiple transactions using a single session?    forum.hibernate.org

Consider the following piece of code. Here I am trying to open two trnsactions using the same session. 1: Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 2: Transaction transaction1=session.beginTransaction(); 3: Event e= (Event) session.load(Event.class, id1); 4: transaction1.commit(); 5: Transaction transaction2=session.beginTransaction(); 6: Event e2= (Event) session.load(Event.class, id2); 7: transaction2.commit(); This gives me an "org.hibernate.SessionException: Session is closed!" error in line 5. So transaction1.commit() is leading ...

45. Session/Transaction code: where to put it?    forum.hibernate.org

The answer is not that simple. - Are we dealing with long application transaction? Definition of long if an application transaction spans between hibernate transaction. - Do we want to deal with detached object or open session view (means we will only close the session once the application transaction is finish). The answer to this question will be very different depending ...

46. Hibernate sessions and transactions issue    forum.hibernate.org

Hi, I am using Hibernate with Spring for a web based application running on Tomcat5. I have a table called CreditCard which stores credit card information. CCTransactionDAO class uses hibernate to access a MySQL database. A ccTransactionManager interface is used to call the CCTransactioDAO to get and save rown in the table. All configuration is performed using spring's applicationContext.xml Show below ...

47. Need better understanding of Session and Transaction    forum.hibernate.org

Hi Guys, I would like to now better understanding and relationship between 1. session.save(); 2.session.flush(); 3.session.connection().commit() 4. Transaction.commit(); Lets say i would like to insert data to Person Table Person a = new Person(); a.setName("test") session.save(a); session.flush(); session.connection().commit() Above will insert into database and commit the value right? But i can also use session.save(a); then transaction.commit(); Which are the differences? what ...

48. Why is the wiki "Open Session In View" page locked    forum.hibernate.org

It is locked because the author decided to lock it. You can open your own page and, if you decide that the content is important in its unmodified form, lock it. This is a _feature_. I don't know which history you are referring to, the complete history of a page is available already.

49. Stupid (?) transaction/session issue...    forum.hibernate.org

SessionFactory sf = (SessionFactory) getServletContext().getAttribute("session-factory"); sf.getCurrentSession().beginTransaction(); List apps = appDao.findByExample(new LhpApp()); request_.setAttribute("apps", appDao.findByExample(new LhpApp())); sf.getCurrentSession().getTransaction().commit(); ...

50. Problems with Session and transaction handling?    forum.hibernate.org

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); Person p1 = new Person(10,"aaaa"); session.merge(p1.getClass().getName(),p1); Transaction tnx = session.beginTransaction(); Person p = new Person(10,"aaaa"); Object res =session.merge(p.getClass().getName(),p); session.delete(res); session.merge(p.getClass().getName(),p1); tnx.commit(); ...

51. Sessions and transactions Hibernate Wiki entry    forum.hibernate.org

I just read the Wiki entry on "Sessions and transactions" http://www.hibernate.org/42.html In section "Transaction demarcation with JTA" the second code example raises the question whether it is really correct: Code: // code from the Hibernate wiki UserTransaction tx = (UserTransaction)new InitialContext() ...

52. Problems with Session and transaction handling?    forum.hibernate.org

Problems with Session and transaction handling? JSF-Version: 1.1 Spring-Version: 1.2.8 spring-aop.ar Spring-Version: 1.2.4 Hibernate-version: 3.1.3 weblogic 8i We are handling transaction By custom interceptor (TransactionInterceptor) while creating transaction we are getting following Exception org.springframework.transaction.CannotCreateTransactionException : Could not open Hibernate Session for transaction; nested exception is org.hibernate.SessionException: Session is closed! In production it is erratic behavior . If we try second time ...

53. Transactions and Session    forum.hibernate.org

Context ctx = new InitialContext(); tx = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction"); tx.begin(); session = HibernateUtil.getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(User.class); criteria.add(Restrictions.eq("username", username)); criteria.add(Restrictions.eq("password", password)); List results = criteria.list(); session.close(); tx.commit();

54. Problems with Session and transaction handling?    forum.hibernate.org

55. How to do multiple transaction per session?    forum.hibernate.org

56. Session and transaction problem!    forum.hibernate.org

Hello everyone, I found a problem when using hibernate with ZK which is a ajax framework. First, when I update or save a POJO, it's ok, and the POJO is persistent to database,but the problem came when I reload it again. like findByID,findAll, etc, I always get the previous objects. Second, I found if I execute session.close() before any find operation, ...

57. Transaction versus Session    forum.hibernate.org

58. Can i open another session in same transaction??    forum.hibernate.org

Hi All, I am trying to Open One more session inside the transaction and creating Transaction for that session .after Query i am closing the session and after some i am commiting main transaction and closing the main session.the problem i am facinng is second session coneections are growing in database..Any one help me how to handle this scenario

59. yet another session and transaction problem    forum.hibernate.org

Newbie Joined: Thu Mar 27, 2008 1:30 pm Posts: 5 I did read http://hibernate.org/42.html But I still have questions... I created the servlet filter to open a session when I receive a webservice request. This filter is opening and closing the session. I don't get Lazy initialization problem anymore. To close the session I'm calling the disconnect method instead of close ...

60. Why both Session and Transactions    forum.hibernate.org

You could read one of the following books: Hibenate in action Java persistence using hibernate A session is a collection of loaded objects relating to a unit of work. For every unit of work you will need a session instance. Hibernate can detect changes made to the objects within a session. A transaction interface on the other hand provides method to ...

61. Transaction that spans Session and StatelessSession    forum.hibernate.org

Is it possible to create a transaction that spans both Session and StatelessSession operations? obviously the operations would not occur concurrently. can i manually fetch a connection from a C3P0 datasource (autocommit is false), then open a new Session using that connection, use it then open a StatelessSession using the same connection? im guessing i would have to manually commit the ...

62. Multiple transactions in a session.    forum.hibernate.org

Hello All, I am currently working in an JSF application where there is a main form with 3 action buttons. When I click each button it opens an another form in which I complete the form and while saving the transaction do not have to be committed in the database but just saved. Like wise i do it for all the ...

63. Problems with Session and transaction handling?    forum.hibernate.org

public OrderHandler() throws NamingException { logger.debug("Enter c'tor of OrderHandler()"); InitialContext ctx = new InitialContext(); SessionFactory sessionFac_report = new Configuration().configure().buildSessionFactory(); sesReporting = sessionFac_report.openSession(); } ... public void saveToDatabase() throws Exception { Transaction txReporting = null; try{ txReporting =sesReporting.beginTransaction(); ... ...

64. Problem to understand the transaction session mechanism    forum.hibernate.org

Hello, I am here to ask you a question about transaction and session management. Because I know you are experimented. This is my problem : When I want to save or get information from the data base, I use a session and do some operation on it like : Code: List results = session.createQuery("from File").list(); or session.saveOrUpdate(File); But when I want ...

65. Hibernate session and transaction management    forum.hibernate.org

Hi everyone, I would like to know the drawbacks of using hibernates built in session and transaction handling? Does it support multiple connections? I've read in a few places not for production use. I have been unable to find the specifics, is there a link you could point me towards? I've looked into the other options; JTA and Spring unsure which ...

66. Sessions and Transactions    forum.hibernate.org

Hi, heaving read hibernate docs, i get the idea but wud like a bit more clarity on few things or more of an advice rather ... 1. Does one have to always use ThreadLocal for managing Sessions on web applications? what kind of applications really need this approach 2. Say a user logs in to the system, queries an employee details ...

67. Transaction problem - two open sessions    forum.hibernate.org

Beginner Joined: Fri Mar 21, 2008 8:07 pm Posts: 23 I'm getting the following error: Code: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'populator' defined in class path resource [spring-core.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Initialization of DAO failed; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions: org.hibernate.HibernateException: Illegal attempt ...

68. Session.lock() creates duplicate proxies    forum.hibernate.org

Hi I do a Session.lock() on a collection of detached objects to attach them to the current session. The objects have a many-to-one association chain of objects with cascade="lock". Upon Session.lock() I get a org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session It seems that Hibernate creates different proxies for the same object. I ...