Announcement Announcement Module
Collapse
No announcement yet.
Strange behaviour since moving from JDK 7 to JDK 6 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange behaviour since moving from JDK 7 to JDK 6

    Hi,

    I'm developing a web application using :

    Spring 3.1.2
    Tomcat 6
    JDK 7
    SQL Serveur 2008 R2 (JDBC driver sqljdbc4.jar)

    All is working as expected.

    When moving from JDK 7 to JDK 6, my application is not working anymore
    I'm confused, as Spring prerequisites are JDK 1.5+.

    It seems to be dabase related :

    When starting Tomcat, no error on console.
    When accessing to my application, the browser keeps blocked on "waiting for localhost".

    When debbuging, I see a problemon on this line :

    Code:
    if (SpringHelper.getInstance(request).getUrlService().isUrlProtected(pUrl))
    I have put a breakpoint in isUrlProtected method, but I'm not able to reach it.

    When watching content of getUrlService(), I see information I'm not used to work with :

    Code:
    CGLIB$BOUND	true	
    [...]
    CGLIB$CALLBACK_0	Cglib2AopProxy$DynamicAdvisedInterceptor  (id=3121)	
    iUrlDao	null
    I never enter in isUrlProtected method, my breakpoint is never reached.
    The Tomcat thread is marked as "Running" but no response was sent to the client (still displaying "waiting for localhost").
    I have not any exception in console.

    Here is my service layer :
    Code:
    // imports
    [...]
    
    @Transactional
    public class ServiceUrl {
    	private InterfaceTUrlDao iUrlDao;
    
    	/**
    	 * @return the iUrlDao
    	 */
    	public InterfaceTUrlDao getiUrlDao() {
    		return iUrlDao;
    	}
    
    	/**
    	 * @param iUrlDao the iUrlDao to set
    	 */
    	public void setiUrlDao(InterfaceTUrlDao iUrlDao) {
    		this.iUrlDao = iUrlDao;
    	}
    	
    	public void persist(TUrl transientInstance) {
    		iUrlDao.persist(transientInstance);
    	}
    
    	public void remove(TUrl persistentInstance) {
    		iUrlDao.remove(persistentInstance);
    	}
    
    	public TUrl merge(TUrl detachedInstance) {
    		return iUrlDao.merge(detachedInstance);
    	}
    
    	public TUrl findById(int id) {
    		return iUrlDao.findById(id);
    	}
    	
    	public boolean isUrlProtected(String urlPath)
    	{
    		// just search for the entry in db
    		return iUrlDao.findByPath(urlPath) != null;
    	}
    }
    Here is my DAO layer :
    Code:
    // imports
    [...]
    
    /**
     * Home object for domain model class TUrl.
     * @author Hibernate Tools
     */
    public class TUrlDao implements InterfaceTUrlDao {
    
    	private static final Log log = LogFactory.getLog(TUrlDao.class);
    
    	@PersistenceContext(type=PersistenceContextType.EXTENDED)
    	private EntityManager entityManager;
    
    	public void persist(TUrl transientInstance) {
    		log.debug("persisting TUrl instance");
    		try {
    			entityManager.persist(transientInstance);
    			log.debug("persist successful");
    		} catch (RuntimeException re) {
    			log.error("persist failed", re);
    			throw re;
    		}
    	}
    
    	public void remove(TUrl persistentInstance) {
    		log.debug("removing TUrl instance");
    		try {
    			entityManager.remove(persistentInstance);
    			log.debug("remove successful");
    		} catch (RuntimeException re) {
    			log.error("remove failed", re);
    			throw re;
    		}
    	}
    
    	public TUrl merge(TUrl detachedInstance) {
    		log.debug("merging TUrl instance");
    		try {
    			TUrl result = entityManager.merge(detachedInstance);
    			log.debug("merge successful");
    			return result;
    		} catch (RuntimeException re) {
    			log.error("merge failed", re);
    			throw re;
    		}
    	}
    
    	public TUrl findById(int id) {
    		log.debug("getting TUrl instance with id: " + id);
    		try {
    			TUrl instance = entityManager.find(TUrl.class, id);
    			entityManager.refresh(instance);
    			log.debug("get successful");
    			return instance;
    		} catch (RuntimeException re) {
    			log.error("get failed", re);
    			throw re;
    		}
    	}
    	
    	public TUrl findByPath(String path) {
    		try
    		{
    			Query query = entityManager.createQuery("select u from TUrl u where u.pathUrl like :theUrl");
    			query.setParameter("theUrl", path);
    			
    			TUrl result = (TUrl) query.getSingleResult();
    			entityManager.refresh(result);
    			return result;
    		}
    		catch (NoResultException nre)
    		{
    			return null;
    		}
    		catch (NonUniqueResultException nure)
    		{
    			throw nure;
    		}
    	}
    }
    Here my application-context.xml file
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	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.1.xsd
    						http://www.springframework.org/schema/tx
    						http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
    						
    	<!-- DAO layer -->
    	<bean id="daoUrl" class="myProject.dao.jpa.TUrlDao" />
    	[...]
    	
    	<!-- Service layer -->
    	<bean id="serviceUrl" class="myProject.service.ServiceUrl">
    		<property name="iUrlDao" ref="daoUrl"/>
    	</bean>
    	[...]
    
    	<!-- Exception translation bean post processor -->
    	<bean class="org.springframework.orm.hibernate3.HibernateExceptionTranslator"/>
    	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    
    	<!-- SQL Server data source -->
    	<bean id="sqlServerDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
    		<property name="url" value="jdbc:sqlserver://serverName:;databaseName=sid" />
    		<property name="username" value="user" />
    		<property name="password" value="pwd" />
    	</bean>
    	
    	<!-- entity manager -->
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="sqlServerDataSource" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="showSql" value="false" />
    				<property name="databasePlatform" value="org.hibernate.dialect.SQLServer2008Dialect" />
    				<property name="generateDdl" value="false" />
    			</bean>
    		</property>
    	</bean>
    	
    	<!-- Transactions manager -->
    	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    
    	<!-- enable the configuration of transactional behavior based on annotations -->
    	<tx:annotation-driven transaction-manager="txManager" />
    	
    	<!-- Persistence -->
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    	
    	<!-- Other data source not used currently... -->
    	<bean id="oracleDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    		<property name="url" value="jdbc:oracle:thin:@server:1521:instance" />
    		<property name="username" value="user" />
    		<property name="password" value="pwd" />
    	</bean>
    	
    	<!-- Form validation : associated messages -->
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basename">
    			<value>messages</value>
    		</property>
    	</bean>
    </beans>
    My SpringHelper class :
    Code:
    // imports
    [...]
    
    /**
     * Spring Helper class.
     * 
     * Provide access to bean objects defined in spring application context file.
     * 
     * Based on Singleton pattern to initialize objects once.
     * 
     */
    public class SpringHelper {
    	/**
    	 * Unique instance
    	 */
    	private static SpringHelper instance = null;
    	
    	/**
    	 * Service layer
    	 */
    	private ServiceUrl urlService;
    
    	/**
    	 * @return the urlService
    	 */
    	public ServiceUrl getUrlService() {
    		return urlService;
    	}
    
    	[...]
    
    	/**
    	 * Singleton
    	 * 
    	 */
    	public static SpringHelper getInstance(HttpServletRequest request)
    	{
    		// first call
    		if (instance == null)
    		{
    			instance = new SpringHelper(request);
    		}
    		
    		return instance;
    	}
    	
    	/**
    	 * Private constructor to force Singleton usage
    	 */
    	private SpringHelper(HttpServletRequest request)
    	{
    		// get servlet context from request
    		ServletContext servletContext = request.getSession().getServletContext();
    		
    		// get service layer
    		urlService = (ServiceUrl) WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean("serviceUrl");
    	}
    }
    When moving back to JDK 7, it's working.

    I'm a little bit lost on this topic...
    Last edited by schumi2k2; Sep 25th, 2012, 04:55 AM.

  • #2
    Why are you using an ugly singleton and not simply inject the dependency? Or simply use the RequestContextUtils to get access to the applicationcontext to get the service. Not sure but the singleton might be the problem...

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      Why are you using an ugly singleton and not simply inject the dependency? Or simply use the RequestContextUtils to get access to the applicationcontext to get the service. Not sure but the singleton might be the problem...
      Thanks for your help.

      A colleague of mine trying to help me, made the same remark than you.

      He tried to inject the service object directly in the controller (like you suggest) but it does not help.

      Comment


      • #4
        I still would remove it it at least improves your design/architecture (things like such a singleton are basically an indication something is wrong at least IMHO that is ).

        Debug the behavior of your singleton (see if the context it initialized, see if the service gets injected etc.).

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          I still would remove it it at least improves your design/architecture (things like such a singleton are basically an indication something is wrong at least IMHO that is ).

          Debug the behavior of your singleton (see if the context it initialized, see if the service gets injected etc.).
          I will remove this horrible Singleton class, your are definitly right.

          See it working using JDK 7 is (sorry to insist on that), confusing, doesn't it ?

          Comment


          • #6
            Problem resolved by switching JDK version to JDK 6u35 (also working with JDK 6u16).

            While doing some tests directly on my DAOs, I had some RuntimeException : unable to release connection.
            I did some searches on forums and found people having database issues with JDK 6u29.

            Hope it helps!

            Comment


            • #7
              Bug JDK 6u29 :

              http://bugs.sun.com/bugdatabase/view...bug_id=7105007
              http://blogs.msdn.com/b/jdbcteam/arc...update-30.aspx

              Comment


              • #8
                Thanks for posting back for future references.

                Comment

                Working...
                X