Quantcast
Channel: Spring Community Forums - Social
Viewing all articles
Browse latest Browse all 145

Spring social closes the DB connection using JPA, Hibernate

$
0
0
Hello,
I'm developing a sample application that connects to facebook, scans a group feed, and save all the comments on a DB.

I'm facing a very strange problem that completely blocks me: in the method where I scan the feed, if I ask the comments of a post (facebook.commentOperations().getComments(post.get Id())), the connection with the DB closes and I can't use JPA any more, every action aborts with this error:

2013-07-17 17:06:22,611 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.l ogExceptions:145] SQL Error: 0, SQLState: null
2013-07-17 17:06:22,612 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.l ogExceptions:147] Connection is closed.
2013-07-17 17:06:22,613 INFO [org.hibernate.event.internal.DefaultLoadEventListe ner.onLoad:158] HHH000327: Error performing load command : org.hibernate.exception.GenericJDBCException: could not prepare statement
2013-07-17 17:06:22,618 ERROR [org.springframework.transaction.interceptor.Transa ctionInterceptor.completeTransactionAfterThrowing: 408] Application exception overridden by rollback exception
org.springframework.orm.hibernate3.HibernateJdbcEx ception: JDBC exception on Hibernate data access: SQLException for SQL [select ...]; SQL state [null]; error code [0]; could not prepare statement; nested exception is org.hibernate.exception.GenericJDBCException: could not prepare statement
....
Caused by: java.sql.SQLException: Connection is closed. at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$Pool GuardConnectionWrapper.checkOpen(PoolingDataSource .java:185) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$Pool GuardConnectionWrapper.prepareStatement(PoolingDat aSource.java:312)

If I simply comment the above call to getComments() then everything works fine and I can iterate between posts and do every action on the data layer without problems.

It seems like somehow the facebook object messes up with the declarative transaction model of Spring, but I can't understand how to solve it.

Facebook connect is integrated in spring security using socialAuthenticationFilter following the example of one of the samples.

I'm using Spring Data JPA and hibernate with a LocalContainerEntityManagerFactoryBean and spring social 1.1M3, this is the data configuration xml:

Code:

  <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/myds"/>
  </bean>

  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
  </bean>

  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan">
      <list>
        <value>it.example.entities</value>
      </list>
    </property>
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        <property name="showSql" value="false" />
        <property name="generateDdl" value="true" />
    </bean>
    </property>
  </bean>
 
  <jpa:repositories base-package="it.example.dao"
                    entity-manager-factory-ref="entityManagerFactory"
                    transaction-manager-ref="transactionManager"/>
  <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="false" />

Any help would be very very appreciated since this is completely blocking for me :(

Thanks!
Alex

Viewing all articles
Browse latest Browse all 145

Trending Articles