• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HibernateException: No Hibernate Session bound to thread

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Frank VanOor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark, I should have posted the full XML's....here they are

Dispatch servlet XML




Root Context XML

 
Frank VanOor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I removed the @Transactional from the method, but still same exception.

 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark, thanks for comment. I added mapped classes to root context



But still the same exception.

The Class Stock

 
Frank VanOor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I have been away a little bit. I'll look soon after you post your latest exception.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic