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,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:'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 left off some of the debug output to make it easier to read):Code:M:\workspace\liquidlogic-gwt\war
Project StructureCode: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 [...]
web.xmlCode:war - META-INF - persistence.xml - WEB-INF - applicationContext.xml - web.xml
applicationContext.xmlCode:<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>
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
JpaDao (Base DAO)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>
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; } [...] }


Reply With Quote
