Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.0.2 + JPA 2.0 + Hibernate 3.5.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.0.2 + JPA 2.0 + Hibernate 3.5.0

    I am not sure if this is a JPA persistence configuration problem or, a STS IDE problem or, a simple classpath problem, so I will start here with my first guess.

    I hope someone can see my error here as I've spent several days trying uncountable different combos.

    Environment:
    IDE: STS v2.3.3.M1
    JDK: 1.6.0_16
    GWT: SDK 2.0.3

    Problem: The debug output below is generated after I use GWT compiler (everything compiles fine) and then Run As Google Web Application.

    The only other error I get during development on this project is a dialog pops up occasionally that states,
    Code:
    'Updating /liquidlogic-gwt/war/WEB-INF/lib with jars
     from  \liquidlogic-gwt\war - unknown version' has encountered a problem.  
    
    SDK directory 'M:\liquidlogic-gwt\war' does not exist
    I have looked throughout the IDE preferences and my config files and cannot find a setting for changing this. The correct physical path should be:
    Code:
    M:\workspace\liquidlogic-gwt\war
    (I left off some of the debug output to make it easier to read):
    Code:
       Initializing Spring root WebApplicationContext
       [WARN] Failed startup of context com.google.gwt.dev.shell.jetty.JettyLauncher
    $WebAppContextWithReload@f8968f{/,M:\workspace\liquidlogic-gwt\war}
    org.springframework.beans.factory.BeanCreationException: Error creating bean wit
    h name 'jpaTransactionManager' defined in ServletContext resource [/WEB-INF/appl
    icationContext.xml]: Cannot resolve reference to bean 'entityManager' while sett
    ing bean property 'entityManager'; nested exception is org.springframework.beans
    .factory.BeanCreationException: Error creating bean with name 'entityManager' de
    fined in ServletContext resource [/WEB-INF/applicationContext.xml]: 
    [....]
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
    ng bean with name 'entityManager' defined in ServletContext resource [/WEB-INF/a
    pplicationContext.xml]: Invocation of init method failed; nested exception is ja
    va.lang.IllegalArgumentException: No persistence unit with name 'LiquidLogic' fo
    und
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    .initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
    [...]
    
       [WARN] Nested in org.springframework.beans.factory.BeanCreationException: Err
    or creating bean with name 'jpaTransactionManager' defined in ServletContext res
    ource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'entit
    yManager' while setting bean property 'entityManager'; nested exception is org.s
    pringframework.beans.factory.BeanCreationException: Error creating bean with nam
    e 'entityManager' defined in ServletContext resource [/WEB-INF/applicationContex
    t.xml]: Invocation of init method failed; nested exception is java.lang.IllegalA
    rgumentException: No persistence unit with name 'LiquidLogic' found:
    java.lang.IllegalArgumentException: No persistence unit with name 'LiquidLogic' 
    found
    [...]
    Project Structure
    Code:
    war
        - META-INF
            - persistence.xml
        - WEB-INF
            - applicationContext.xml
            - web.xml
    web.xml
    Code:
    <web-app>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    	<!-- Servlets -->
    	<servlet>
    		<servlet-name>springGwtRemoteServiceServlet</servlet-name>
    		<servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
    	</servlet>	
    
    	<servlet-mapping>
    		<servlet-name>springGwtRemoteServiceServlet</servlet-name>
    		<url-pattern>liquidGwtServices/*</url-pattern>
    	</servlet-mapping>	
    
    	<!-- Default page to serve -->
    	<welcome-file-list>
    		<welcome-file>LiquidlogicGWT.html</welcome-file>
    	</welcome-file-list>
    
    </web-app>
    applicationContext.xml
    Code:
    <beans>
    	<context:component-scan base-package="com.liquidnetworks.liquidlogic.gwt" />
    	<context:annotation-config />
    	<tx:annotation-driven />
    
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    		<property name="url" value="jdbc:hsqldb:mem:LiquidLogic" />
    		<property name="username" value="sa" />
    		<property name="password" value="" />
    	</bean>
    
    	<bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManager" ref="entityManager" />
    	</bean>
    
    	<bean id="entityManager"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="persistenceUnitName" value="LiquidLogic" />
    		<property name="dataSource" ref="dataSource" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" />
    				<property name="showSql" value="true" />
    				<property name="generateDdl" value="true" />
    			</bean>
    		</property>
    		<property name="jpaProperties">
    			<props>
    				<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="applicationDao"
    		class="com.liquidnetworks.liquidlogic.gwt.server.repository.impl.ApplicationDao"
    		lazy-init="true">
    		<property name="entityManager">
    			<ref local="entityManager" />
    		</property>
    	</bean>
    
    	<bean
    		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    
    </beans>

    persistence.xml
    Code:
    <persistence-unit name="LiquidLogic"
    		transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>		
    		
    		<class>com.liquidnetworks.liquidlogic.gwt.shared.domain.impl.application.CreditApplication</class>
    	</persistence-unit>
    
    </persistence>
    JpaDao (Base DAO)
    Code:
    public abstract class JpaDao<K, E> extends JpaDaoSupport {
        protected Class<E> entityClass;
    
        @SuppressWarnings("unchecked")
        public void JpaDAO() {
            ParameterizedType genericSuperclass = (ParameterizedType) getClass()
                    .getGenericSuperclass();
            this.entityClass = (Class<E>) genericSuperclass
                    .getActualTypeArguments()[1];
        }
    
        public void persist(E entity) {
            getJpaTemplate().persist(entity);
        }
    
    [...]
    
        @SuppressWarnings("unchecked")
        public List<E> findAll() {
            Object res = getJpaTemplate().execute(new JpaCallback() {
    
                public Object doInJpa(EntityManager entityManagerFactory)
                        throws PersistenceException {
                    Query q = entityManagerFactory.createQuery("SELECT h FROM "
                            + entityClass.getName() + " h");
                    return q.getResultList();
                }
    
            });
    
            return (List<E>) res;
        }
    }

    ApplicationDao (Specialized DAO)
    Code:
    @Repository("applicationDao")
    public class ApplicationDao extends JpaDao<Long, CreditApplication> {
    
        @PersistenceContext(unitName = "LiquidLogic")
        EntityManager entityManager;
    
        public void init() {
            super.setEntityManager(entityManager);
        }
    
    }

    CreditApplication (Entity Class)

    Code:
    @Entity
    @Table(name = "APPLICATION")
    public class CreditApplication extends BaseDomainObject implements Application {
    
        private static final long serialVersionUID = -5883327875366981438L;
        
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "id")
        private Integer id;
        @Column(name = "creation_date", nullable = false)
        private Date creationDate;
        @Column(name = "loan_amount", nullable = false)
        private Money loanAmount;
        @Column(name = "deposit_amount")
        private Money depositAmount;
        @ManyToMany
        @JoinTable(name = "APPLICATION_TO_APPLICANT", joinColumns = @JoinColumn(name = "APPLICATION_ID"), inverseJoinColumns = @JoinColumn(name = "APPLICANT_ID"))
        private List<Applicant> applicants;
    
        // application field has not been implemented in Asset
        @OneToMany(targetEntity = Asset.class, mappedBy = "department")
        private List<Asset> assets;
    
        // application field has not been implemented in Asset
        // @OneToMany(targetEntity=Bid.class, mappedBy="application")
        private List<Bid> liveBids;
    
        public CreditApplication() {
            creationDate = new Date();
        }
    
        public CreditApplication(Money loanAmount, Money depositAmount) {
            creationDate = new Date();
            this.loanAmount = loanAmount;
            this.depositAmount = depositAmount;
        }
    
        public Applicant getApplicantById(Integer applicantId) {
            Applicant matchedApplicant = null;
            for (Applicant applicant : applicants) {
                if (applicant.getApplicantId() == applicantId) {
                    matchedApplicant = applicant;
                    break;
                }
            }
            return matchedApplicant;
        }
    
        [...]
    
    }

  • #2
    Unable to add listener of type: ContextLoaderListe ner

    Hi ,

    Spring 3.0.3
    Hibernate 3.5, JPA 2.0
    GWT 2.0.4
    GlassFish V3.0.1


    I have a similar configuration an my error trce is :

    Code:
    GRAVE: ContainerBase.addChild: start: 
    org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: PWC1430: Unable to add listener of type: org.springframework.web.context.ContextLoaderListener, because it does not implement any of the required ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener, HttpSessionListener, or HttpSessionAttributeListener interfaces
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:5232)
    	at com.sun.enterprise.web.WebModule.start(WebModule.java:499)
    .....
    My web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	id="WebApp_ID" version="2.5" metadata-complete="true">
    	<display-name>wimslive</display-name>
    
    	<!-- spring integration -->
    	<context-param>
    		<param-name>log4jConfigLocation</param-name>
    		<param-value>/WEB-INF/classes/log4j.properties</param-value>
    	</context-param>
    
    	<!--
    		<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
    	-->
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
    	</context-param>
    
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    	<listener>
    		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    	</listener>
    
    	<!-- Handles Spring requests -->
    	<!-- SpringGwt remote service servlet -->
    	<servlet>
    		<servlet-name>springGwtRemoteServiceServlet</servlet-name>
    		<servlet-class>com.inter.wimslive.server.SpringGwtRemoteServiceServlet</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>springGwtRemoteServiceServlet</servlet-name>
    		<url-pattern>/wimslive/*</url-pattern>
    	</servlet-mapping>
    
    	<session-config>
    		<session-timeout>30</session-timeout>
    	</session-config>
    
    	<welcome-file-list>
    		<welcome-file>wimslive.html</welcome-file>
    
    	</welcome-file-list>
    </web-app>
    My aplicationContext.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    	
    	
    	<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
    	
    	<context:spring-configured />
    	
    	<context:component-scan base-package="com.inter.wimslive">
    		<context:exclude-filter expression=".*_Roo_.*"
    			type="regex" />
    		<context:exclude-filter expression="org.springframework.stereotype.Controller"
    			type="annotation" />
    	</context:component-scan>
    
    
    
    
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    			destroy-method="close" >
    		<property name="driverClassName" value="${database.driverClassName}" />
    		<property name="url" value="${database.url}" />
    		<property name="username" value="${database.username}" />
    		<property name="password" value="${database.password}" />
    	</bean>
    	
    	
    
    
    	<!--<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>-->
    	
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        
        <tx:annotation-driven transaction-manager="transactionManager" />
        
        <tx:jta-transaction-manager/>
    
    
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="mappingResources">
    			<list>
    				<value>com/inter/wimslive/entity/hbm/Empleados.hbm.xml</value>
    			</list>
    		</property>
    		<!--<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.format_sql">true</prop>
    				<prop key="hibernate.use_sql_comments">false</prop>
    				<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
    				<prop key="hibernate.jdbc.batch_size">20</prop>
    				<prop key="hibernate.c3p0.min_size">10</prop>
    				<prop key="hibernate.c3p0.max_size">100</prop>
    				<prop key="hibernate.c3p0.timeout">10</prop>
    				<prop key="hibernate.c3p0.acquireRetryAttempts">30</prop>
    				<prop key="hibernate.c3p0.acquireIncrement">5</prop>
    				<prop key="hibernate.c3p0.idleConnectionTestPeriod">100</prop>
    				<prop key="hibernate.c3p0.initialPoolSize">20</prop>
    				<prop key="hibernate.c3p0.maxPoolSize">100</prop>
    				<prop key="hibernate.c3p0.maxIdleTime">300</prop>
    				<prop key="hibernate.c3p0.maxStatements">50</prop>
    				<prop key="hibernate.c3p0.minPoolSize">10</prop>
    				<prop key="hibernate.c3p0.preferredTestQuery">SELECT 1</prop>
    				<prop key="hibernate.c3p0.testConnectionOnCheckout">true</prop>
    			</props>
    		</property>
    	--></bean>
    </beans>
    Please help us!!

    Comment


    • #3
      Have you found a solution? I'm experiencing the same problem.

      (Details on http://stackoverflow.com/questions/6...does-not-exist)

      Comment


      • #4
        for configuration, you can reference this
        http://www.springsourcery.org/spring...ml?random=7262

        Comment


        • #5
          I'm neither using Spring nor MySQL or Hibernate. I only ran into the problem posted here.

          Comment

          Working...
          X