Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] EclipseLink + Spring (EntityManagerFactory --> EntityManager)

The way I do it is to let spring scan for my DAO's, so I don't define
them in xml where i inject an EntityManagerFactory with:

@PersistenceContext
 private EntityManager entityManager;

I don't have the energy to read your app context xml, but here's a
scrubbed version of mine if you want to comb through it:

<?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:aop="http://www.springframework.org/schema/aop";
	xmlns:context="http://www.springframework.org/schema/context";
	xmlns:jee="http://www.springframework.org/schema/jee";
xmlns:lang="http://www.springframework.org/schema/lang";
	xmlns:p="http://www.springframework.org/schema/p";
xmlns:tx="http://www.springframework.org/schema/tx";
	xmlns:util="http://www.springframework.org/schema/util";
	xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
		http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
		http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd";>
	<context:annotation-config />
	<context:component-scan base-package="com.redacted.tpl.*" />
	<aop:aspectj-autoproxy/>
	<tx:annotation-driven />




	<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
		p:entityManagerFactory-ref="entityManagerFactory" />
	<bean
		class="org.springframework.transaction.aspectj.AnnotationTransactionAspect"
		factory-method="aspectOf">
		<property name="transactionManager" ref="transactionManager" />
	</bean>
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
		<property name="url"
			value="jdbc:oracle:thin:@xxx" />
		<property name="username" value="xxx" />
		<property name="password" value="xxx" />
	</bean>
	<bean id="jpaAdapter"
		class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
		<property name="databasePlatform"
			value="org.eclipse.persistence.platform.database.oracle.OraclePlatform" />
		<property name="showSql" value="true" />
	</bean>
	<!--
		<bean id="loadTimeWeaver"
		class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
	-->
	<bean id="loadTimeWeaver"
		class="org.springframework.instrument.classloading.oc4j.OC4JLoadTimeWeaver" />
	<!--
		<bean id="loadTimeWeaver"
		class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver">
		</bean>
	-->
	<context:load-time-weaver />
	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="TPLModel" />
		<property name="dataSource" ref="dataSource" />
		<property name="jpaVendorAdapter" ref="jpaAdapter" />
     <!-- <property name="loadTimeWeaver" ref="loadTimeWeaver"/> -->
	</bean>
	<bean
		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
/>
		<!--
			<bean id="messageSource"
		class="org.springframework.context.support.ResourceBundleMessageSource">
		<property name="basename">
			<value>messages</value>
		</property>
	</bean> -->
		<bean id="messageSource"
		class="org.springframework.context.support.ResourceBundleMessageSource">
		<property name="basename">
			<value>ApplicationResources.properties</value>
		</property>
	</bean>
	<bean id="SSOHandler"
		class="com.redacted.tpl.controller.interceptors.SSOHandlerInterceptor" />

	<!-- View Resolver -->
	<!-- jstl -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
	<util:list id="annotatedClasses">
		<value>com.redacted.tpl.*</value>
	</util:list>
	<!--
		Maps request paths to @Controller classes; e.g. a path of /hotels
		looks for a controller named HotelsController
	-->
	<bean
		class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
		<property name="order" value="1" />
		<property name="defaultHandler">
			<!--
				If no @Controller match, map path to a view to render; e.g. the
				"/intro" path would map to the view named "intro"
			-->
			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"
/>
		</property>
		<property name="interceptors">
			<list>
				<ref bean="SSOHandler" />
			</list>
		</property>
	</bean>
	
	<!-- Maps all other request URLs to views -->
	<bean id="urlMapping"
		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="defaultHandler">
			<!--
				Selects view names to render based on the request URI: e.g. /index
				selects "index"
			-->
			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"
/>
		</property>
		<property name="order" value="2" />
	</bean>
</beans>



./tch



On Thu, Feb 19, 2009 at 5:09 AM, Kasper Hansen <kbhdk1976@xxxxxxxxx> wrote:
> I can't seem to get from an EntityManagerFactory to an EntityManager,
> without a class conversion problem; Please look for the yellow marked code
> in spring-context.xml ! I hope for some good tips/help to get further ! I'm
> stuck.
>
>
> 10:44:24,381 ERROR ContextLoader:215 - Context initialization failed
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'providerManager' defined in ServletContext resource
> [/WEB-INF/spring/spring-context.xml]: Initialization of bean failed; nested
> exception is org.springframework.beans.TypeMismatchException: Failed to
> convert property value of type [$Proxy19 implementing
> javax.persistence.EntityManagerFactory,org.springframework.orm.jpa.EntityManagerFactoryInfo]
> to required type [javax.persistence.EntityManager] for property
> 'entityManager'; nested exception is java.lang.IllegalArgumentException:
> Cannot convert value of type [$Proxy19 implementing
> javax.persistence.EntityManagerFactory,org.springframework.orm.jpa.EntityManagerFactoryInfo]
> to required type [javax.persistence.EntityManager] for property
> 'entityManager': no matching editors or conversion strategy found
>     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
>     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
>     at java.security.AccessController.doPrivileged(Native Method)
>     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
>     at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
>     at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
>     at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
>     at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
>     at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
>     at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
>     at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
>     at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
>     at
> org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
>     at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
>     at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
>     at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
>     at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
>     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>     at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>     at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>     at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
>     at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>     at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
>
> The full stacktrace dump is in the attached file.
>
>
> spring-context.xml:
> <?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:aop="http://www.springframework.org/schema/aop";
>         xmlns:tx="http://www.springframework.org/schema/tx";
>         xmlns:context="http://www.springframework.org/schema/context";
>         xsi:schemaLocation="
>         http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>         http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
>         http://www.springframework.org/schema/aop
> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
>         http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context-2.5.xsd";>
>
>     <bean id="jpaVendorAdapter"
> class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
>         <property name="databasePlatform"
> value="org.eclipse.persistence.platform.database.MySQLPlatform" />
>         <property name="generateDdl" value="true" />
>         <property name="showSql" value="true" />
>         <property name="database" value="MYSQL" />
>     </bean>
>
>     <bean id="entityManagerFactory"
> class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
>         <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
>         <property name="persistenceXmlLocation"
> value="WEB-INF/spring/persistence.xml" />
>         <property name="persistenceUnitName" value="ibslogic" />
>     </bean>
>
>     <context:load-time-weaver />
>
>     <bean id="providerManager"
> class="dk.logiksyndikatet.ibslogic.manager.ProviderManager">
> <----- THIS IS HERE I HAVE A PROBLEM. It does not work with
> EntityManagerFactory or EntityManager ! How do i do it ?
>         <property name="entityManager" ref="entityManagerFactory" />
>     </bean>
>
>     <bean
> class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
> />
>
>     <!-- enable the configuration of transactional behavior based on
> annotations -->
>     <tx:annotation-driven transaction-manager="txManager" />
>
>     <bean id="txManager"
> class="org.springframework.orm.jpa.JpaTransactionManager">
>         <property name="entityManagerFactory" ref="entityManagerFactory" />
>     </bean>
> </beans>
>
>
> persistence.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.0"
>     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_1_0.xsd";>
>     <persistence-unit name="ibslogic">
>         <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
>         <class>dk.logiksyndikatet.ibslogic.domain.Settings</class>
>         <properties>
>             <property name="eclipselink.jdbc.user" value="ibslogicuser"/>
>             <property name="eclipselink.jdbc.password"
> value="ibslogicpassword"/>
>             <property name="eclipselink.jdbc.driver"
> value="com.mysql.jdbc.Driver"/>
>             <property name="eclipselink.jdbc.url"
> value="jdbc:mysql://localhost:3306/ibslogic"/>
>             <property name="eclipselink.ddl-generation"
> value="create-tables"/>
>             <property name="eclipselink.ddl-generation.output-mode"
> value="sql-script" />
>             <property name="eclipselink.weaving" value="false" />
>         </properties>
>     </persistence-unit>
> </persistence>
>
>
> web.xml:
> <?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_4.xsd";
>     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd";
>     id="NewHairID" version="2.4">
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/fmt.tld</taglib-location>
>     </taglib>
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/fmt-rt.tld</taglib-location>
>     </taglib>
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/c.tld</taglib-location>
>     </taglib>
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/c-rt.tld</taglib-location>
>     </taglib>
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/sql.tld</taglib-location>
>     </taglib>
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/sql-rt.tld</taglib-location>
>     </taglib>
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/x.tld</taglib-location>
>     </taglib>
>
>     <taglib>
>         <taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
>         <taglib-location>/WEB-INF/classes/tlds/x-rt.tld</taglib-location>
>     </taglib>
>
>     <display-name>newhair</display-name>
>
>     <filter>
>         <display-name>Stripes Filter</display-name>
>         <filter-name>StripesFilter</filter-name>
>
> <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
>
>         <init-param>
>             <param-name>Configuration.Class</param-name>
>
> <param-value>net.sourceforge.stripes.config.RuntimeConfiguration</param-value>
>         </init-param>
>
>         <init-param>
>             <param-name>ActionResolver.Packages</param-name>
>
> <param-value>dk.logiksyndikatet.applications.newhair</param-value>
>         </init-param>
>
>         <init-param>
>             <param-name>ActionBeanContext.Class</param-name>
>
> <param-value>dk.logiksyndikatet.common.stripes.ActionBeanContextNewHair</param-value>
>         </init-param>
>
>         <init-param>
>             <param-name>LocalePicker.Locales</param-name>
>             <param-value>da_DK:UTF-8</param-value>
>         </init-param>
>
>         <init-param>
>             <param-name>Interceptor.Classes</param-name>
>             <param-value>
>
> net.sourceforge.stripes.integration.spring.SpringInterceptor,
>
> net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor,
>                 dk.logiksyndikatet.common.stripes.SecurityInterceptor
>             </param-value>
>         </init-param>
>      </filter>
>
>     <filter-mapping>
>         <filter-name>StripesFilter</filter-name>
>         <url-pattern>*.jsp</url-pattern>
>         <dispatcher>REQUEST</dispatcher>
>     </filter-mapping>
>
>     <filter-mapping>
>         <filter-name>StripesFilter</filter-name>
>         <servlet-name>StripesDispatcher</servlet-name>
>         <dispatcher>REQUEST</dispatcher>
>     </filter-mapping>
>
>     <servlet>
>         <servlet-name>StripesDispatcher</servlet-name>
>
> <servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>StripesDispatcher</servlet-name>
>         <url-pattern>*.htm</url-pattern>
>     </servlet-mapping>
>
>     <env-entry>
>         <description>IBS provider id</description>
>         <env-entry-name>bean/provider-id</env-entry-name>
>         <env-entry-type>java.lang.String</env-entry-type>
>         <env-entry-value>1</env-entry-value>
>     </env-entry>
>
>     <listener>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>     </listener>
>     <context-param>
>         <param-name>contextConfigLocation</param-name>
>         <param-value>/WEB-INF/spring/spring-context.xml</param-value>
>     </context-param>
> </web-app>
>
>
> ProviderManager.java
> public class ProviderManager {
>
>     @PersistenceContext
>     private EntityManager entityManager;
>
>     ....
> }
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>


Back to the top