Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HibernateException: No Hibernate Session bound to thread

 
Frank VanOor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I removed the @Transactional from the method, but still same exception.

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I have been away a little bit. I'll look soon after you post your latest exception.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic