Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HibernateInterceptor variant for Hibernate 4 [SPR-9028] #13667

Closed
spring-projects-issues opened this issue Jan 15, 2012 · 22 comments
Closed

HibernateInterceptor variant for Hibernate 4 [SPR-9028] #13667

spring-projects-issues opened this issue Jan 15, 2012 · 22 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jan 15, 2012

Per Edlund opened SPR-9028 and commented

When using the HibernateInterceptor with Hibernate4, org.springframework.orm.hibernate4.HibernateTransactionManager and org.springframework.orm.hibernate4.LocalSessionFactoryBean I'm getting a signature error which I don't really understand. I added a comment to one of the other issues regarding this, here's the stack trace

Caused by: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:322)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:233)
at org.springframework.orm.hibernate3.HibernateInterceptor.getSession(HibernateInterceptor.java:145)
at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy44.getAll(Unknown Source)


Affects: 3.1 GA

Attachments:

Issue Links:

  • #15915 Re-consider including HibernateTemplate and related classes for Hibernate 4

10 votes, 18 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 19, 2012

Juergen Hoeller commented

Hibernate 4.0 changed critical signatures in the Hibernate API, such as currentSession() and openSession() which have a different return type now (org.hibernate.Session instead of org.hibernate.classic.Session). For that reason, no Hibernate 3 support classes (from the orm.hibernate3) package are going to work against Hibernate 4.0.

So if you'd like a HibernateInterceptor variant, we'd have to provide a specific one for Hibernate 4.0 in the orm.hibernate4 package. What specifically are you using HibernateInterceptor for? It became rather uncommon to see that one in practice, which is why we omitted it from orm.hibernate4 for the time being...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 21, 2012

Per Edlund commented

Hi Juergen!

We're currently using hibernate interceptor for 2 reasons. One is that we access DAO's from different thread's and in some cases from constructors. Another reason is that we're using JMS and in onMessage we just use the dao's without any session/tx- handling. For us it's really a convenient way of always being sure that the session is bound when accessing the dao's.

Do you understand my reason ?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 26, 2012

Daniel Geske commented

Same problem here with the missing HibernateInterceptor in the orm.hibernate4 package, though I have a different reason to use it.
I was working on a Quartz job which should lazy load related objects when I hit this road block using Spring 3.1 and Hibernate 4.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 1, 2012

Daniel Geske commented

FYI I solved my problem by adding the @Transactional annotation to the method the scheduled job executes.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 11, 2012

Raymond DeCampo commented

I also had found a need for the HibernateInterceptor. I am using it in MDB as well as in LoginManager configurations. If there is a work-around I would be interested in hearing it.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 26, 2012

PanosZhu commented

I think this is a very important function. I need it. I am using it both in tcp and http protocol. And also using it in scheduled job.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 17, 2012

thomas houtekier commented

I am also interested in this feature. Is there a known workaround for know?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 11, 2012

Andres Olave commented

Hi there guys,

I really needed HibernateInterceptor since encountering a hibernate bug that was only fixed in version 4.x. And we, rightly or wrongly, use HibernateInterceptor all over the place (Mdb's, business logic services, our one-page Widget Web framework 'services', and event processing).

So I took the old one and very pragmatically made it to work with Hibernate 4 for our uses. This is now on our test servers and looks like its holding up quite nicely.

Note it does not currently support hibernate filters as we have no need for these - but if anyone else would like to renable them and test it, I am sure your fellow spring user's will be grateful.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 26, 2012

Pawel Omelko commented

Do you already know if this class (HibernateInterceptor) will be available in hibernate4 package? This issue was create almost years ago.

It's very useful during working with Quartz triggered jobs, but @Transactional is not quite substitute.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 27, 2012

Pawel Omelko commented

Hi Andreas, Any problems with yours HibernateInterceptor implementation? I think about use it in my project.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 28, 2013

Pawel Omelko commented

Hello Juergen,

Any progress in this case?

If we already have some OpenSession class for http thread it will be nice to have one for not http thread (like Quartz workers).

What do you think about adding some kind of @OpenSession annotation, which can bind/unbind session to thread like HibernateInterceptor use to (using aspectj of course :))?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 24, 2013

Amit Mahindrakar commented

Hello Juergen,

Has there been any progress in this case?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 2, 2014

Juergen Hoeller commented

FYI, we introduced a HibernateTemplate variant for Hibernate 4 in Spring 4.0.1. However, there's still no HibernateInterceptor there since we ultimately would prefer to get rid of it completely.

If there is still interest in this, could you please summarize your HibernateInterceptor use cases including your specific HibernateInterceptor configuration (flush mode, filter names, etc).

We generally prefer transactional execution in combination with programmatic Hibernate access, but well, we would like to have a proper migration strategy for existing HibernateInterceptor usage...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 3, 2014

Raymond DeCampo commented

We are using a simplified version of the HibernateInterceptor attached to this bug report (without the flush mode). We use it to provide a Hibernate session in environments outside of the web container. Specifically, in a custom javax.security.auth.spi.LoginModule implementation as well as in message-driven beans.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 3, 2014

Per Edlund commented

Hi!

We no longer use the HibernateInterceptor. We started with having the platform transaction manager as a field, and then using that to start the transaction if accessed from a thread or the constructor.

So for us, it's fine to skip it.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 3, 2014

Pawel Omelko commented

Hi Juergen,

We still need it. It's very usefull for:

  • Quartz jobs
  • RMI invoked methods

So now we are using attached HibernateInterceptor by Andres Olave. With FlushMode.AUTO and no hibernate filters. It's working without problems so far.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 4, 2014

Daniel Geske commented

My use cases have disappeared since the product where we ran into this issue was retired.
At the time, the problem was with scheduled Quartz jobs, similar to @pomelko.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 4, 2014

Juergen Hoeller commented

Thanks for your feedback so far, guys.

Raymond, Pawel,

Could you also use HibernateTemplate, since we're shipping a variant of that as of 4.0.1 now? That is, wrap your Hibernate access in a HibernateCallback and operate on the Session there?

Or is the reason why you're using HibernateInterceptor primarily the transparent enabling of SessionFactory.getCurrentSession(), with a strong preference of that API style? In that case, could you wrap your data access operations in a HibernateTransactionManager transaction, triggered by @Transactional or programmatic use of a TransactionTemplate?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 4, 2014

Pawel Omelko commented

It's not that simple to wrap quartz/rmi executed method with HibernateCallback. There is many access from different daos, which expect to have current session.

Using @Transactional on those (quartz/rmi invoked) method it's not the best idea for existing code. It could cause long db transaction and even some dead locks.

I can't understand why don't you just give us this HibernateInterceptor. Why not http threads are worst that http?

Going this way we don't need OpenSessionInView interceptor also, but we already have one for hibernate4 :)

Did I convinced you?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 4, 2014

Juergen Hoeller commented

Pawel,

Thanks for the elaboration. This is exactly why I'm reaching out here: I'd like to better understand where HibernateInterceptor is still useful in 2014, in particular for migrations from Hibernate 3 to Hibernate 4.

As for transactions, as long as you're only reading, there shouldn't be any locking involved. FWIW, the Hibernate team strongly recommends transactions for any kind of Hibernate Session access, which is a key reason why we've been stronger in our enforcement there as well.

As for OpenSessionInViewInterceptor, this is a slightly different case since it's less advisable to wrap the MVC view rendering phase in a connection-binding resource transaction, with potentially blocking response I/O involved on HTTP access at the same time.

That said, I am leaning towards inclusion of some kind of HibernateInterceptor still. It's more about how much functionality it would have, and whether such a class would be marked as deprecated right from the beginning, suggesting alternative approaches instead.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 4, 2014

Juergen Hoeller commented

Actually, we might turn it into a non-deprecated OpenSessionInterceptor or the like in orm.hibernate4.support, next to OpenSessionInViewInterceptor and OpenSessionInViewFilter. Such a focused interceptor implementation would only do Session binding, i.e. no flushing and no exception translation, designed for use at non-web boundaries as you outlined.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 6, 2014

Juergen Hoeller commented

I've added a streamlined OpenSessionInterceptor to orm.hibernate4.support, and also mirrored it in orm.hibernate3.support as a migration help from the outdated HibernateInterceptor there. To be available in the next 4.0.2 snapshot.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants