[hibernate-dev] Session opening

Steve Ebersole steve at hibernate.org
Mon Apr 4 07:17:08 EDT 2011


session.sessionWithOptions().connection().openSession()

says *exactly* what you just said: "open a session using the same connection 
as an existing session".

Like I said, I do not think that is enough as I think that if you get the 
connection, you also need the "transaction context" holding that connection.  
"transacvtion context" here is the TransactionCoordinator.

session.sessionWithOptions().transactionContext().openSession()


On Monday, April 04, 2011, at 04:40 am, Max Rydahl Andersen wrote:
> > RE: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2860
> > 
> > This dealt with cleaning up all the overloaded openSession methods from
> > SessionFactory and SessionFactoryImplementor.
> > 
> > The new main method for obtaining a Session is
> > SessionFactory.withOptions() which returns a
> > org.hibernate.SessionBuilder instance which can be used to specify the
> > options with which you want the Session built by eventually calling
> > openSession() on it.  For example:
> > 
> > Session session = sessionFactory
> > 
> >        .withOptions()
> >        .connection( someConnection )
> >        .openSession();
> > 
> > The only prior form I left is openSession()
> > 
> > There is also a means to create a Session using certain information from
> > an existing session using Session.sessionWithOptions() which returns a
> > org.hibernate.SharedSessionBuilder (extending from SessionBuilder).
> > 
> > As part of this I was also finally able to remove the long deprecated
> > Session.connection() method since we now have doWork, doReturningWork and
> > now session opening.
> > 
> > Any questions or concerns?
> 
> Which of these best fits AuditLogInterceptor pattern ? i.e. where you want
> the same connection as a session but do not wish to "pollute" the session
> with entities/state concerning the auditlog entries ?
> 
> None of them seem to allow for that as far as I can see ?
> 
> They either use different session or have a limited lifecycle not
> permitting keeping a second session around for lookup/state ?
> 
> Am I missing something ?
> 
> /max
> http://about.me/maxandersen

---
Steve Ebersole <steve at hibernate.org>
http://hibernate.org



More information about the hibernate-dev mailing list