-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: The EntityManager hangs
PostPosted: Fri Feb 07, 2014 4:57 am 
Newbie

Joined: Tue Jan 14, 2014 12:26 pm
Posts: 2
I have an old Spring application witch I upgraded with a new scheduled function.
The application is running in TomCat.
There was already some other working scheduling features which worked fine.
The new scheduling function reads information from an LDAP server and adds information into a mySQL database.
The application worked fine before i added this new function.

It works for a half day after that it hangs in function query.getResultList() on the row marked with <==== below

Could it have something with transactions to do?

I am also using @Autowired BasicDataSource for getting the Connection, it is used for truncating a table in mySQL.

I need some advise please.

/ Peter
Code:

****************     Entity manager configuration

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      ">
   
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName" value="${jdbc.driverClassName}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
   </bean>

    <!-- Auto scan the components -->
    <context:component-scan
            base-package="com.cybercom.semesterfu.storage.bo.impl,com.cybercom.semesterfu.storage.dao.impl"/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
                <property name="showSql" value="true"/>
                <property name="generateDdl" value="true"/>
            </bean>
        </property>
    </bean>

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

    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

****************  Persistence configuration

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
    <persistence-unit name="userpersistence" transaction-type="RESOURCE_LOCAL">
    </persistence-unit>
</persistence>

**************** My new scheduling code

:
    @Autowired
    BasicDataSource dataSource;

   /**
     * Reads department and employees into VP:s database
     */
    @Scheduled(cron = "${ldap.cron.expression:17 37 * * * *}")
    public void handleLdapScheduling()
   {
       logger.info( "handleLdapScheduling() is updateing 'Departments' and 'Employees'" );
 
        try
        {
           Connection dbConnection = dataSource.getConnection();
:

**************** Calling the function that hangs

    @RequestMapping(value="/vacation/resend", method=RequestMethod.GET)
    @Scheduled(cron = "${request.resend.cron:37 13 * * * *}")
    public void resendRequests() {
       logger.debug("resendRequests() - started");
       List<Integer> failedRequests = dayIntervalBo.getFailedRequests();
:

**************** Hanging function (old code working bebare I added the new handleLdapScheduling() code

@Repository("dayIntervalDao")
public class DayIntervalDaoImpl implements DayIntervalDao {
   
    private final static Logger log = LoggerFactory.getLogger(DayIntervalDaoImpl.class);

    @PersistenceContext
    EntityManager entityManager;

    @Override
   public List<Integer> getFailedRequests() {
       TypedQuery<Integer> query = entityManager.createQuery(
              "SELECT DISTINCT di.requestID " +
              "FROM DayInterval AS di " +
              "WHERE di.requestID <> 0 " +
              "AND di.status = 'PENDING'",
              Integer.class);
       log.debug( "getFailedRequests() After entityManager.createQuery()" );
       List<Integer> resultList =  query.getResultList()                                  <=======
       log.debug( "getFailedRequests() After query.getResultList()" );

        return resultList;
   }
:



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.