Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Spring, Hibernate, MySQL Stand-Alone App

  1. #1
    Join Date
    Oct 2007
    Posts
    26

    Default Spring, Hibernate, MySQL Stand-Alone App

    Spring: 2.0.7
    Hibernate Core: 3.2.5.ga
    Hibernate Annotation: 3.3.0 GA

    I am using Spring, Hibernate, C3P0 and MySQL in a stand-alone application. The app runs on its own and not in an application server or a container of any sort.

    I keep getting the below error. I'd appreciate all pointers on what I may have done wrong. Thanks...

    The log below is triggered by the following code:

    sessionFactory.getCurrentSession();

    20:41:50,953 DEBUG SessionFactoryUtils:315 - Opening Hibernate Session
    20:41:51,015 DEBUG SessionImpl:220 - opened session at timestamp: 11929381109
    20:41:51,015 DEBUG SessionFactoryUtils:771 - Closing Hibernate Session
    20:41:51,015 ERROR GeoLocEditorService:51 - ***Exception***
    org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    at org.springframework.orm.hibernate3.AbstractSession FactoryBean$TransactionAwareInvocationHandler.invo ke(AbstractSessionFactoryBean.java:300)
    at $Proxy17.getCurrentSession(Unknown Source)


    ===
    My service method is annoated with @Transactional.

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
    <property name="configLocation" value="/hibernate.cfg.xml"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- Hibernate Transaction Manager -->
    <bean id="txManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <!-- Enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="txManager"/>

  2. #2
    Join Date
    Oct 2007
    Posts
    26

    Default

    Any ideas anyone? Thanks...

  3. #3
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Without looking at the code, stack trace or hibernate configuration - not really.

  4. #4
    Join Date
    Oct 2007
    Posts
    26

    Default

    Quote Originally Posted by dejanp View Post
    Without looking at the code, stack trace or hibernate configuration - not really.
    Well, there is a stack trace and configuration in the original post. You can see that Spring tried to open the session only to close it immediately

    The stack trace shows what the code does

  5. #5
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    One line is not a stack trace, you can't see the flow from it. Configuration is only partial Spring config, not Hibernate config.

  6. #6
    Join Date
    Oct 2007
    Posts
    26

    Talking

    Come on dude. If you have an inkling then out with it and be help instead of being a pain. You can clearly see in the original post the call() that produced the Spring stack trace...the rest is in application code. And yes, there is a@ @transactional notation in the right place. The same code/config works fine in a Tomcat environment.

    Here is the hibernate config.

    <property name="hibernate.cglib.use_reflection_optimizer">tr ue</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MyS QLDialect</property>

    Quote Originally Posted by dejanp View Post
    One line is not a stack trace, you can't see the flow from it. Configuration is only partial Spring config, not Hibernate config.

  7. #7

    Default

    Does the database driver you are using support transactions?

  8. #8
    Join Date
    Oct 2007
    Posts
    26

    Default

    Quote Originally Posted by jonnio View Post
    Does the database driver you are using support transactions?
    Yes, I use mySQL 5.x, InnoDB and their appropriate JDBC driver.

    I am scratching my head on the following debug from within Spring. You can see the it opened then closed the session immediate...why the close?

    20:41:50,953 DEBUG SessionFactoryUtils:315 - Opening Hibernate Session
    20:41:51,015 DEBUG SessionImpl:220 - opened session at timestamp: 11929381109
    20:41:51,015 DEBUG SessionFactoryUtils:771 - Closing Hibernate Session

  9. #9
    Join Date
    Mar 2007
    Posts
    26

    Default

    that would be a problem with your hibernate configuration (or with your database configuration).
    Without more information noone will be able to help you further than that.

  10. #10
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you post the full stacktrace, then it's possible to see if a transaction proxy was applied. Is it also possible to see the code you are running here?
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •