Results 1 to 3 of 3

Thread: Model not being persisted

  1. #1
    Join Date
    Oct 2009
    Posts
    3

    Default Model not being persisted

    Hello all,

    Sorry, I'm a noob.

    I've set up my first app, mostly copying from booking-mvc (I'll add the config files at the end of this post). Everything's working fine, except the model isn't being saved. No exceptions or anything indicating that anything's amiss. The flow:


    Code:
      
    <persistence-context/>
    
      <on-start>
        <evaluate expression="projectService.createProject()" result="flowScope.project"/>
      </on-start>
    
      <view-state id="new" model="project">
        <transition on="save" to="done">
          <evaluate expression="projectService.deleteProject(project)"/>  (NOTE: all this does is log the project name, for debugging)
          <render fragments="newProjectForm"/>
        </transition>
      </view-state>
    
      <end-state id="done" commit="true" view="externalRedirect:servletRelative:/admin/intro"/>
    From the logs, Hibernate appears to be configured properly:
    Code:
    INFO  2009-10-07 14:38:34,103 hibernate.ejb.Ejb3Configuration - found EJB3 Entity bean: com.elided.photogallery.domain.project.Project
    DEBUG 2009-10-07 14:38:34,759 ejb.util.NamingHelper - No JNDI name configured for binding Ejb3Configuration
    and it seems like the commit tries to happen:

    Code:
    transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder@fb765a] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@1a17727] bound to thread [http-80-1]
    orm.jpa.JpaTransactionManager - Found thread-bound EntityManager [org.hibernate.ejb.EntityManagerImpl@ea58e3] for JPA transaction
    orm.jpa.JpaTransactionManager - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
    orm.jpa.JpaTransactionManager - Exposing JPA transaction as JDBC transaction [SimpleConnectionHandle: com.elided.dbpool.ConnectionWrapper@179c0a7]
    transaction.support.TransactionSynchronizationManager - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@5739a0] for key [com.elided.dbpool.AwiDataSource@10c986] to thread [http-80-1]
    transaction.support.TransactionSynchronizationManager - Initializing transaction synchronization
    orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler - Joined local transaction
    orm.jpa.JpaTransactionManager - Triggering beforeCommit synchronization
    orm.jpa.JpaTransactionManager - Triggering beforeCompletion synchronization
    orm.jpa.JpaTransactionManager - Initiating transaction commit
    orm.jpa.JpaTransactionManager - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@ea58e3]
    orm.jpa.JpaTransactionManager - Triggering afterCommit synchronization
    orm.jpa.JpaTransactionManager - Triggering afterCompletion synchronization
    transaction.support.TransactionSynchronizationManager - Clearing transaction synchronization
    transaction.support.TransactionSynchronizationManager - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@5739a0] for key [com.elided.dbpool.AwiDataSource@10c986] from thread [http-80-1]
    orm.jpa.JpaTransactionManager - Not closing pre-bound JPA EntityManager after transaction
    transaction.support.TransactionSynchronizationManager - Removed value [org.springframework.orm.jpa.EntityManagerHolder@fb765a] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@1a17727] from thread [http-80-1]
    but nothing shows up in the DB. I'd also expect to see some indication in the logs that there was an attempt made to persist 'project', but there's nothing. It's entirely possibly that I don't have the Entities annotated correctly, but wouldn't there be error messages rather than silent failure? And BTW I set org.hibernate and most of org.springframework to debug for logging.

    I've been reading the source and stepping through with the debugger, but I don't have enough of a grasp yet to really know what to look for. And of course I've also tried searching here and on the web. Where do I start to try to track this down? How can I determine if the EntityManager, etc. (I haven't figured out how it all works yet) has any awareness of 'project'? All advice is, of course, welcome.

    The config files:

    data-access-config.xml
    Code:
      <tx:annotation-driven />
    
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
          <value>
            hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
          </value>
        </property>
      </bean>
    
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    		</property>
    	</bean>
    
      <bean id="dataSource" class="com.elided.dbpool.AwiDataSource"/>
    webmvc-config.xml
    Code:
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    		<property name="order" value="0" />
    		<property name="flowRegistry" ref="flowRegistry" />
    	</bean>
    
    	<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>
    	</bean>
    
    	<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
    	</bean>
    
      <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    		<property name="definitions">
    			<list>
    				<value>/WEB-INF/layouts/layouts.xml</value>
    				<value>/WEB-INF/views.xml</value>
    				<value>/WEB-INF/flows/new/new-views.xml</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    
    	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    		<property name="flowExecutor" ref="flowExecutor"/>
    	</bean>
    webflow-config.xml
    Code:
    	<webflow:flow-executor id="flowExecutor">
    		<webflow:flow-execution-listeners>
    			<webflow:listener ref="jpaFlowExecutionListener" />
    		</webflow:flow-execution-listeners>
    	</webflow:flow-executor>
    
    	<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/flows">
    		<webflow:flow-location-pattern value="/**/*-flow.xml" />
    	</webflow:flow-registry>
    
    	<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" development="true" />
    
    	<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    		<property name="viewResolvers" ref="tilesViewResolver"/>
    		<property name="useSpringBeanBinding" value="true" />
    	</bean>
    
    	<bean id="jpaFlowExecutionListener" class="org.springframework.webflow.persistence.JpaFlowExecutionListener">
    		<constructor-arg ref="entityManagerFactory" />
    		<constructor-arg ref="transactionManager" />
    	</bean>
    persistence.xml FWIW
    Code:
       <persistence-unit name="photogallery-admin">
         <provider>org.hibernate.ejb.HibernatePersistence</provider>
         <class>com.elided.photogallery.domain.project.Project</class>
         <class>com.elided.photogallery.domain.project.ProjectKey</class>
         <class>com.elided.photogallery.domain.RowControl</class>
         <class>com.elided.photogallery.domain.Flag</class>
         <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
            <property name="hibernate.show_sql" value="true"/>
         </properties>
       </persistence-unit>

    Thanks!
    Steve

  2. #2
    Join Date
    Oct 2009
    Posts
    3

    Default

    UPDATE: I do have an issue with my Hibernate config and/or possibly missing jar files. I've been messing around with a test case using HibernateTemplate, just trying to save a Project. I got some ClassNotFound exceptions, and now I'm getting the "Unknown Entity" error, even though I made certain to use javax.persistence.Entity in my annotations.

    I might just go to hbm files and forget about the annotations. But if anybody has any advice, I'm still happy to hear it. I'm supposed to have the tech spec written by Friday.

    Thanks.
    Steve

  3. #3
    Join Date
    Oct 2009
    Posts
    3

    Default

    Solution: the object instance I expected to be persisted wasn't in the PersistenceContext. Taking a clue from JpaBookingService in the booking-mvc example, after creating a Project object it has to be merged with the EntityManager.

    That, and using the correct version of Hibernate, got everything working the way I expected.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •