aspose file tools*
The moose likes Spring and the fly likes HibernateException: No Hibernate Session bound to thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "HibernateException: No Hibernate Session bound to thread" Watch "HibernateException: No Hibernate Session bound to thread" New topic
Author

HibernateException: No Hibernate Session bound to thread

Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
I'm using Spring 3.0 with ibernate and I've the follwing exception when the hibernate method createSQLQuery(...) is excecuted:



The dispatcher-servlet.xml



The root context xml




Java code





Many thanks in advance.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Where is your configuration for the SessionFactory, DataSource and TransactionManager and <tx:annotation-driven>?

Basically, my guess is that there isn't a proxy being created around your DAO with Spring's Transaction manager starting a transaction, even though you have the class and method annotated with @Transactional. You actually only need one or the other @Transactional. At the class level means that all methods of your interface should be transaction, and I assume that method is in your interface, so just leaving the annotation at the class level is enough.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
Hi Mark, I should have posted the full XML's....here they are

Dispatch servlet XML




Root Context XML

Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
I removed the @Transactional from the method, but still same exception.

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Do you know if you are getting that class proxied? I don't think you are. I think there is something missing, but I don't see it yet.

So set a break point at the caller of that method then step into, and if you see a .class popup then you have a proxy and that is good. But if you go right into your first line of that method in your class, then you are not getting the proxy and therefore not getting transactions.

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Wait a second where are your list of mapped classes here in your bean for SessionFactory. You have to tell it what are your mapped classes. either with properties mappingLocations, mappedClasses, or packagesToScan.



Mark
Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
Hi Mark, thanks for comment. I added mapped classes to root context



But still the same exception.

The Class Stock

Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
I made some progress, but have another exception :

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.MappingException: Unknown entity: com.stockdomain.domain.Stock
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



Meanwhile, I'll post the changes I did.
I added "<property name="annotatedClasses">" into the session bean Id.


the context xml








I also removed @Transactional annotation on the method in StockDAOImpl.java.
the class looks like this now.



I'll post a new thread for this new exception.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Sorry, I have been away a little bit. I'll look soon after you post your latest exception.

Mark
 
 
subject: HibernateException: No Hibernate Session bound to thread