Announcement Announcement Module
Collapse
No announcement yet.
Spring 2.0 + Jpa will not write to MySQL DB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 2.0 + Jpa will not write to MySQL DB

    Hello all,

    I am new to Spring, however I have made a very serious effort to diagnose and treat my problems with out posting, which until now has been successful. I have created a Spring 2.0 + Jpa enabled JSR-168 portlet to run in the Liferay portal framework. My portlet seems to work great with the exception that it does not write to the MySQL DB. I have viewed my MySQL log file and debug files and seen that the JpaTemplate is able to construct a query to select information from the db, however when I try to write or delete the SQL code is never generated. No error is generated unless I attempt to delete and object, then I receive a "Entity must be managed to call remove". If I use a ReflectiveLTW I am unable to even read fro the DB, I receive an "Unknown Abstract Schema Type [Links]" error. I have included the configuration files, and error logs. All of my spring, toplink, and MySQL connector jars are in WEB-INF\lib. I am also using getJpaTemplate() in my DAO class. Thanks so much for any suggestions.


    *Please assume that non-relevant files and JSP tags are in their correct locations.

    web.xml
    Code:
    <?xml version="1.0"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app>
    	<display-name>TheWellnessChallengePortlets</display-name>
    	<context-param>
    		<param-name>company_id</param-name>
    		<param-value>liferay.com</param-value>
    	</context-param>
    	<context-param>
    		<param-name>webAppRootKey</param-name>
    		<param-value>com.hfp.twc.v2</param-value>
    	</context-param>
    	<context-param>
    		<param-name>log4jConfigLocation</param-name>
    		<param-value>/WEB-INF/classes/log4j.properties</param-value>
    	</context-param>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/context/applicationContext.xml</param-value>
    	</context-param>
    	<listener>
    		<listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
    	</listener>
    	<listener>
    		<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
    	</listener>
    	<listener>
    		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    	</listener>
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	<servlet>
    		<servlet-name>WebLinks</servlet-name>
    		<servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
    		<init-param>
    			<param-name>portlet-class</param-name>
    			<param-value>org.springframework.web.portlet.DispatcherPortlet</param-value>
    		</init-param>
    		<load-on-startup>0</load-on-startup>
    	</servlet>
    	<servlet>
    		<servlet-name>ViewRendererServlet</servlet-name>
    		<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>WebLinks</servlet-name>
    		<url-pattern>/WebLinks/*</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
    		<servlet-name>ViewRendererServlet</servlet-name>
    		<url-pattern>/WEB-INF/servlet/view</url-pattern>
    	</servlet-mapping>
    	<taglib>
    		<taglib-uri>http://java.sun.com/portlet</taglib-uri>
    		<taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
    	</taglib>
    	<taglib>
    		<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
    		<taglib-location>/WEB-INF/tags/c.tld</taglib-location>
    	</taglib>
    	<taglib>
    		<taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
    		<taglib-location>/WEB-INF/tags/fmt.tld</taglib-location>
    	</taglib>
    	<taglib>
    		<taglib-uri>http://java.sun.com/jsp/jstl/functions</taglib-uri>
    		<taglib-location>/WEB-INF/tags/fn.tld</taglib-location>
    	</taglib>
    	<taglib>
    		<taglib-uri>http://www.springframework.org/tags</taglib-uri>
    		<taglib-location>/WEB-INF/tags/spring.tld</taglib-location>
    	</taglib>
    </web-app>
    applicationContext.xml
    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:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!-- Message source for this context, loaded from localized "messages_xx" files -->
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basenames">
    			<list>
    				<value>messages</value>
    			</list>
    		</property>										
    	</bean>
    
    	<!-- Default View Resolver -->
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="cache" value="false"/>
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    		<property name="prefix" value="/WEB-INF/jsp-files/"/>
    		<property name="suffix" value=".jsp"/>
    	</bean>
    
    	<!-- Abstract Default Exception Handler Bean -->
        <bean id="defaultExceptionHandlerTemplate" class="org.springframework.web.portlet.handler.SimpleMappingExceptionResolver" abstract="true">
    		<property name="defaultErrorView" value="defError"/>
    		<property name="exceptionMappings">
    			<props>
    				<prop key="javax.portlet.PortletSecurityException">notAuthorized</prop>
    				<prop key="javax.portlet.UnavailableException">notAvailable</prop>
    			</props>
    		</property>  
    	</bean>
    </beans>
    Last edited by bobthemagicman; Feb 26th, 2007, 05:02 PM.

  • #2
    links.xml
    Code:
    <beans>
    
    	<!-- Property Configurer  -->
    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="locations">
    			<list>
    				<value>WEB-INF/links.properties</value>
    			</list>
    		</property>
    	</bean>
    
    	<!-- Services -->
    
    	<bean id="linkService" class="com.hfp.twc.v2.links.LinkService">
    		<property name="linksDao" ref="linksDao"></property>
    		<property name="linkCategoryDao" ref="linkCategoryDao"></property>
    		<property name="sectionText" value="${incentives.sectionText}"></property>
    		
    	</bean><!-- Validators -->
    
    	<bean id="linksValidator" class="com.hfp.twc.v2.links.util.LinksValidator"/>
    
    	<bean id="linkCategoryValidator" class="com.hfp.twc.v2.links.util.LinkCategoryValidator"></bean><!-- Controllers -->
    
    	<bean id="linkCategoryControllerTemplate" abstract="true">
    		<property name="linkService"><ref bean="linkService"/></property>
    	</bean>
    	<bean id="linksController" class="com.hfp.twc.v2.links.LinksController" parent="linkCategoryControllerTemplate"></bean>
    	<bean id="linkEditController" class="com.hfp.twc.v2.links.LinkEditController" parent="linkCategoryControllerTemplate"><property name="commandName" value="link"></property><property name="validator">
    			<ref bean="linksValidator" />
    		</property>
    		<property name="sessionForm" value="true"></property>
    		<property name="commandClass" value="com.hfp.twc.v2.links.model.Links"></property>
    		<property name="formView" value="linkEdit"></property></bean>
    		
    			
    	<bean id="linkAddController" class="com.hfp.twc.v2.links.LinkAddController" parent="linkCategoryControllerTemplate">
    		<property name="commandName" value="link"></property>
    		<property name="validator">
    			<ref bean="linksValidator" />
    		</property>
    		<property name="formView" value="linkEdit"></property>
    		<property name="commandClass" value="com.hfp.twc.v2.links.model.Links"></property>
    		<property name="sessionForm" value="true"></property>
    	</bean>
    	<bean id="linkDeleteController" class="com.hfp.twc.v2.links.LinkDeleteController" parent="linkCategoryControllerTemplate"></bean>
    		
    			
    	<bean id="linkCategoryController" class="com.hfp.twc.v2.links.LinkCategoryController" parent="linkCategoryControllerTemplate"></bean>
    	<bean id="deleteLinkCategoriesController" class="com.hfp.twc.v2.links.DeleteLinkCategoriesController" parent="linkCategoryControllerTemplate"></bean>
    		
    			
    	<bean id="editLinkCategoriesController" class="com.hfp.twc.v2.links.EditLinkCategoriesController" parent="linkCategoryControllerTemplate"><property name="commandName" value="Links"></property><property name="validator">
    			<ref bean="linkCategoryValidator" />
    		</property></bean>
    		
    			
    	<bean id="addLinkCategoriesController" class="com.hfp.twc.v2.links.AddLinkCategoriesController" parent="linkCategoryControllerTemplate"><property name="commandName" value="Links"></property><property name="validator">
    			<ref bean="linkCategoryValidator" />
    		</property></bean>
    		
    			
    	<bean id="linkHelpController" class="org.springframework.web.portlet.mvc.ParameterizableViewController">
    		<property name="viewName" value="linkHelp"></property></bean>
    	<bean id="linkSortController"
    		class="com.hfp.twc.v2.links.LinkSortController" parent="linkCategoryControllerTemplate">
    	</bean><!-- Handler Mapping -->
    	
    	<bean id="parameterMappingInterceptor" class="org.springframework.web.portlet.handler.ParameterMappingInterceptor"/>
    	<bean id="portletModeParameterHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping">
            <property name="order" value="10"/>
    		<property name="interceptors">
    			<list>
    				<ref bean="parameterMappingInterceptor"/>
    			</list>
    		</property>
    		<property name="portletModeParameterMap">
    			<map>
    				<entry key="view">
    					<map>
    						<entry key="viewCategories"><ref bean="linkCategoryController"/></entry>
    						<entry key="viewLinks">
    							<ref bean="linksController" /></entry>
    						<entry key="editLinks"><ref bean="linkEditController"/></entry>
    						<entry key="deleteLinks"><ref bean="linkDeleteController"/></entry>
    						<entry key="addLinks">
    							<ref bean="linkAddController"></ref></entry>
    						<entry key="helpLinks">
    							<ref bean="linkHelpController" /></entry>
    						<entry key="1">
    							<ref bean="linkSortController" /></entry>
    						<entry key="2">
    							<ref bean="linkSortController" ></ref></entry>
    						<entry key="3">
    							<ref bean="linkSortController" /></entry>
    
    					</map>
    				</entry>
    				<entry key="editCategories">
    					<map>
    						<entry key="editLinkCategories">
    							<ref bean="editLinkCategoriesController"></ref></entry></map></entry>
    				<entry key="addCategories">
    					<map>
    						<entry key="addLinkCategories">
    							<ref bean="addLinkCategoriesController" /></entry></map></entry>
    				<entry key="deleteCategories">
    					<map>
    						<entry key="deleteLinkCategories">
    							<ref bean="deleteLinkCategoriesController" /></entry>
    					</map></entry>
    			</map>
    		</property>
    	</bean>
    	<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
            <property name="order" value="20"/>
    		<property name="portletModeMap">
    			<map>
    				<entry key="view"><ref bean="linkCategoryController"></ref></entry>
    				<entry key="help">
    					<ref bean="linkHelpController" ></ref></entry>
    			</map>
    		</property>
    	</bean>
    
    	<!-- Exceptions Handler -->
    
    	<bean id="defaultExceptionHandler" parent="defaultExceptionHandlerTemplate"/>
    	
    	<!-- Data Access Objects -->
    	
    	<bean id="linkCategoryDao" class="com.hfp.twc.v2.links.model.LinkCategoryDao">
    		<property name="entityManagerFactory"
    			ref="entityManagerFactory">
    		</property>
    	</bean><bean id="linksDao" class="com.hfp.twc.v2.links.model.LinksDao">
    		<property name="entityManagerFactory" ref="entityManagerFactory">
    		</property>
    	</bean>
    	<!-- Data Source -->
    		<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
    				<property name="showSql" value="true"/>
    				<property name="generateDdl" value="false"/>
    				<property name="database" value="MYSQL"/>
    				<property name="databasePlatform" value="oracle.toplink.essentials.platform.database.MySQL4Platform"/>
    			</bean>
    		</property>
    		<property name="loadTimeWeaver">
    			<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
    		</property>
    	</bean>
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    		<property name="url" value="jdbc:mysql://localhost:3306/twc_v2"/>
    		<property name="username" value="root" />
    		<property name="password" value="root" />
    	</bean>
    		<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory"/>
    		<property name="dataSource" ref="dataSource"/>
    	</bean>
    		<bean id="jdbcTemplat" class="org.springframework.jdbc.core.JdbcTemplate">
    		<property name="dataSource" ref="dataSource">
    		</property>
    	</bean>
    		
    
    </beans>
    Code:
    @Entity(name="Links")
    @Table(name="twc_links")
    public class Links implements Comparable, Serializable {
    
    	/**
    	 * 
    	 */
    	@Transient
    	private static final long serialVersionUID = 1L;
    
    	@Id
    	@GeneratedValue(strategy=GenerationType.IDENTITY)
    	@Column(name="link_id")
    	private int linkId;
    
    	@Column(name="link_name")
    	private String linkName;
    
    	@Column(name="link_description")
    	private String linkDescription;
    
    	@Column(name="link_url")
    	private String linkUrl;
    
    	@Column(name="window_script")
    	private String windowScript;
    
    	@Column(name="link_image")
    	private String linkImage;
    
    	@Column(name="link_rating")
    	private int rating;
    
    	@Column(name="count")
    	private int clickCount;
    
    	@ManyToOne
    	@JoinColumn(name="category_id")
    	private LinkCategory myLinkCategory;
    
    	@Temporal(TemporalType.DATE)
    	@Column(name="created_date")
    	private Calendar createDate;
    
    	@Temporal(TemporalType.DATE)
    	@Column(name="modified_date")
    	private Calendar modifiedDate;
    
    	
    	public Links(){
    	}
    // all necessary getters and setters are here
    }//ends Class

    Comment


    • #3
      Error Logs

      This log is from when I try to delete an Object with the instrmentationLTW:
      Code:
      22:42:06 DEBUG [http-8080-Processor24] (PortletContentGenerator.java:118) - -- 'linkId' = [2]
      22:42:06 DEBUG [http-8080-Processor24] (PortletContentGenerator.java:118) - -- 'categoryId' = [1]
      22:42:06 DEBUG [http-8080-Processor24] (PortletContentGenerator.java:118) - -- 'action' = [deleteLinks]
      22:42:06 DEBUG [http-8080-Processor24] (JpaTemplate.java:183) - Creating new EntityManager for JpaTemplate execution
      22:42:06 DEBUG [http-8080-Processor24] (DriverManagerDataSource.java:289) - Creating new JDBC Connection to [jdbc:mysql://localhost:3306/twc_v2]
      [TopLink Fine]: 2007.02.26 10:42:06.037--ServerSession(31683550)--Connection(18693853)--Thread(Thread[http-8080-Processor24,5,main])--SELECT link_id, link_image, link_rating, link_description, count, window_script, created_date, link_url, modified_date, link_name, category_id FROM twc_links WHERE (link_id = ?)
      	bind => [2]
      22:42:06 DEBUG [http-8080-Processor24] (DriverManagerDataSource.java:289) - Creating new JDBC Connection to [jdbc:mysql://localhost:3306/twc_v2]
      [TopLink Fine]: 2007.02.26 10:42:06.037--ServerSession(31683550)--Connection(4470681)--Thread(Thread[http-8080-Processor24,5,main])--SELECT category_id, category_name, category_description FROM twc_link_categories WHERE (category_id = ?)
      	bind => [1]
      22:42:06 DEBUG [http-8080-Processor24] (JpaTemplate.java:200) - Closing new EntityManager after JPA template execution
      22:42:06 DEBUG [http-8080-Processor24] (JpaTemplate.java:183) - Creating new EntityManager for JpaTemplate execution
      22:42:06 DEBUG [http-8080-Processor24] (DriverManagerDataSource.java:289) - Creating new JDBC Connection to [jdbc:mysql://localhost:3306/twc_v2]
      [TopLink Fine]: 2007.02.26 10:42:06.084--ServerSession(31683550)--Connection(20955323)--Thread(Thread[http-8080-Processor24,5,main])--SELECT link_id, link_image, link_rating, link_description, count, window_script, created_date, link_url, modified_date, link_name, category_id FROM twc_links WHERE (link_id = ?)
      	bind => [2]
      22:42:06 DEBUG [http-8080-Processor24] (DriverManagerDataSource.java:289) - Creating new JDBC Connection to [jdbc:mysql://localhost:3306/twc_v2]
      [TopLink Fine]: 2007.02.26 10:42:06.100--ServerSession(31683550)--Connection(33240770)--Thread(Thread[http-8080-Processor24,5,main])--SELECT category_id, category_name, category_description FROM twc_link_categories WHERE (category_id = ?)
      	bind => [1]
      22:42:06 DEBUG [http-8080-Processor24] (JpaTemplate.java:200) - Closing new EntityManager after JPA template execution
      22:42:06 DEBUG [http-8080-Processor24] (JpaTemplate.java:183) - Creating new EntityManager for JpaTemplate execution
      22:42:06 DEBUG [http-8080-Processor24] (DriverManagerDataSource.java:289) - Creating new JDBC Connection to [jdbc:mysql://localhost:3306/twc_v2]
      [TopLink Fine]: 2007.02.26 10:42:06.115--ServerSession(31683550)--Connection(31325034)--Thread(Thread[http-8080-Processor24,5,main])--SELECT link_id FROM twc_links WHERE (link_id = ?)
      	bind => [2]
      22:42:06 DEBUG [http-8080-Processor24] (JpaTemplate.java:200) - Closing new EntityManager after JPA template execution
      22:42:06 DEBUG [http-8080-Processor24] (DispatcherPortlet.java:614) - Caught exception during action phase - forwarding to render phase
      org.springframework.dao.InvalidDataAccessApiUsageException: Entity must be managed to call remove: com.hfp.twc.v2.links.model.Links@48c33e, try merging the detached and try the remove again.; nested exception is java.lang.IllegalArgumentException: Entity must be managed to call remove: com.hfp.twc.v2.links.model.Links@48c33e, try merging the detached and try the remove again.
      Caused by: 
      java.lang.IllegalArgumentException: Entity must be managed to call remove: com.hfp.twc.v2.links.model.Links@48c33e, try merging the detached and try the remove again.
      	at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.performRemove(UnitOfWorkImpl.java:2767)
      	at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.remove(EntityManagerImpl.java:240)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:283)
      	at $Proxy87.remove(Unknown Source)
      	at org.springframework.orm.jpa.JpaTemplate$7.doInJpa(JpaTemplate.java:280)
      	at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:191)
      	at org.springframework.orm.jpa.JpaTemplate.remove(JpaTemplate.java:278)
      	at com.hfp.twc.v2.links.model.LinksDao.deleteLink(LinksDao.java:23)
      	at com.hfp.twc.v2.links.LinkService.deleteLink(LinkService.java:92)
      	at com.hfp.twc.v2.links.LinkDeleteController.handleActionRequestInternal(LinkDeleteController.java:26)
      	at org.springframework.web.portlet.mvc.AbstractController.handleActionRequest(AbstractController.java:224)
      	at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleAction(SimpleControllerHandlerAdapter.java:52)
      	at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:604)
      	at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:417)
      	at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:400)
      	at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:88)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      This the log from when I try to start my portlet with a ReflectiveLTW
      Code:
      22:52:46 DEBUG [http-8080-Processor25] (DriverManagerDataSource.java:289) - Creating new JDBC Connection to [jdbc:mysql://localhost:3306/twc_v2]
      [TopLink Config]: 2007.02.26 10:52:46.598--ServerSession(15910041)--Connection(32109282)--Thread(Thread[http-8080-Processor25,5,main])--Connected: jdbc:mysql://localhost:3306/twc_v2
      	User: root@localhost
      	Database: MySQL  Version: 5.0.27-community-nt-log
      	Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.0.4 ( $Date: 2006-10-19 17:47:48 +0200 (Thu, 19 Oct 2006) $, $Revision: 5908 $ )
      [TopLink Info]: 2007.02.26 10:52:46.629--ServerSession(15910041)--Thread(Thread[http-8080-Processor25,5,main])--file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%205.5/webapps/TheWellnessChallengePortlets/WEB-INF/classes/-jdbc/TheWellnessChallenge login successful
      22:52:46 DEBUG [http-8080-Processor25] (JpaTemplate.java:200) - Closing new EntityManager after JPA template execution
      22:52:46 DEBUG [http-8080-Processor25] (DispatcherPortlet.java:614) - Caught exception during action phase - forwarding to render phase
      org.springframework.dao.InvalidDataAccessApiUsageException: Unknown entity bean class: class com.hfp.twc.v2.links.model.Links, please verify that this class has been marked with the @Entity annotation.; nested exception is java.lang.IllegalArgumentException: Unknown entity bean class: class com.hfp.twc.v2.links.model.Links, please verify that this class has been marked with the @Entity annotation.
      Caused by: 
      java.lang.IllegalArgumentException: Unknown entity bean class: class com.hfp.twc.v2.links.model.Links, please verify that this class has been marked with the @Entity annotation.
      	at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:293)
      	at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:133)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:283)
      	at $Proxy78.find(Unknown Source)
      	at org.springframework.orm.jpa.JpaTemplat
      Sorry for the length of this post.

      Comment


      • #4
        The entity seems to be unknown to JPA. You seem to use annotations, do you have the

        Code:
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
        somewhere?

        But then again, fetching shouldn't work either... Are you inside a transaction?
        Last edited by Nik; Feb 27th, 2007, 01:58 AM.

        Comment


        • #5
          Originally posted by Nik View Post
          But then again, fetching shouldn't work either... Are you inside a transaction?
          I'm not much of an expert on JPA but that was my first thought as well. The issue regarding "Entity must be managed to call remove" I've seen related to lack of transactions before or people not reattaching the object.

          Comment


          • #6
            Hey all,

            Thanks for your replies. As I mentioned before I am new with this. It appears that you are both encouraging me to use transaction. I am most likely wrong but I thought that transactions were optional, thus I didn't use them or use them properly. Are they required when using Jpa? Also I thought the
            Code:
            <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
            was only if you weren't using getJpaTemplate. If not where should I put the @PersistenceContext and @Repository annotations. It is also my understanding that the purpose of the getJpaTemplate was to handle transactions. Thanks again for any input you can offer.
            Last edited by bobthemagicman; Feb 27th, 2007, 10:52 AM.

            Comment


            • #7
              I've not really done much with JPA, mainly Hibernate. I think the problem is if you aren't working with transaction what is the scope of the EntityManager (Hibernate Session)? The transaction will bind an EntityManager to the thread, therefore you can retrieve an object from the database and then remove it with the same EntityManager. If you don't have a transaction, then do you have a EntityManager that spans the retrieve and the remove? If you don't then after the retrieve the entity is actually detached and therefore the remove will try to get rid of a detached entity. Hence the exception.

              Comment


              • #8
                Well I believe that the idea is that the JpaTemplate is supposed to take care of exactly that which is why in the configuration it is injected with an EntityManagerFactory. I have also converted all my my DB tables to InnoDb and added the @Transaction annotation to certain methods, which was to no avail. I feel as though the problem lies with my LTW or EntityManagerFactory. I think the key may lie in that the Reflective LTW won't even read from the DB, nor will the SimpleLTW, I remember reading that the Intrumentation LTW is quite good at "filling in the gap" when weaving. Thanks again

                Comment


                • #9
                  Yeah you've lost me now . I've not looked into that stuff in enough detail to even comment. The only thing I noticed about your configuration is that you haven't told it that the transactions are annotation driven. Maybe something else in your configuration is supposed to do that, I just don't know.

                  Code:
                  <tx:annotation-driven transaction-manager="txManager"/>
                  http://www.springframework.org/docs/...ve-annotations

                  Comment


                  • #10
                    I am open for anything, I will add that and give her a go.
                    Thanks

                    Comment


                    • #11
                      On a side note this article was sent my way. Might be worth a read.
                      http://blog.interface21.com/main/200...-in-spring-20/

                      Comment


                      • #12
                        Hey,

                        I wanted to thank you all again for the help. Thanks to an some other resources I was able to diagnose the problem and correct it. The main portion of my solution was thanks to this thread

                        http://forum.springframework.org/showthread.php?t=32671

                        What I did was moved the toplink-essentials.jar and the persistence.jar from the ${TOMCAT.HOME}/webapps/myWebapp/WEB-INF/lib directory to the ${TOMCAT.HOME}/common/lib directory. My portle began working properly regardless of my LTW.
                        Thanks

                        Comment


                        • #13
                          Thanks for the tip, that's a strange one to add to the list. Haven't heard about that kind of weirdness before.

                          Comment

                          Working...
                          X