Announcement Announcement Module
Collapse
No announcement yet.
Problem using Roo with with Postgres & MongoDB cross-store aspect support Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using Roo with with Postgres & MongoDB cross-store aspect support

    I've set up a very simple roo (1.2M1) project with one MongoDB entity and one PostgreSQL entity. I've added cross-store support but I get this error with the full stack trace below.

    Any advice would be greatly appreciated as I seem to be following the instructions but just can't get it to work.


    Code:
    Error creating bean with name 'entityManagerFactory' defined in file [/Users/mark/apps/springsource/tc-server-developer-2.1.1.RELEASE/cbs2/wtpwebapps/mongo/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.mongo.domain.NoteData
    Mongo entity
    Code:
    @RooJavaBean
    @RooToString
    @RooMongoEntity
    public class NoteData {
    	private String noteDataName;
    }
    JPA entity
    Code:
    @RooJavaBean
    @RooToString
    @RooEntity
    public class Note {	
    	private String noteName;
    }
    applicationContext-mongo.xml
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:cloud="http://schema.cloudfoundry.org/spring" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/context           
    	http://www.springframework.org/schema/context/spring-context-3.0.xsd           
    	http://www.springframework.org/schema/data/mongo           
    	http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd           
    	http://www.springframework.org/schema/beans           
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd           
    	http://schema.cloudfoundry.org/spring 
    	http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd">
    
    	<mongo:db-factory host="${mongo.host}" id="mongoDbFactory"
    		port="${mongo.port}" />
    	<!-- Default bean name is 'mongo' -->
    	<mongo:mongo host="localhost" port="27017" />
    
    	<mongo:repositories base-package="com.mongo" />
    
    	<!-- To translate any MongoExceptions thrown in @Repository annotated classes -->
    	<context:annotation-config />
    
    	<bean class="org.springframework.data.mongodb.core.MongoTemplate"
    		id="mongoTemplate">
    		<constructor-arg ref="mongoDbFactory" />
    	</bean>
    
    	<bean class="org.springframework.data.mongodb.core.MongoExceptionTranslator" />
    
    	<!-- Mongo cross-store aspect config -->
    	<bean id="mongoChangeSetPersister"
    		class="org.springframework.data.persistence.document.mongodb.MongoChangeSetPersister">
    		<property name="mongoTemplate" ref="mongoTemplate" />
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    
    	<bean
    		class="org.springframework.data.persistence.document.mongodb.MongoDocumentBacking"
    		factory-method="aspectOf">
    		<property name="changeSetPersister" ref="mongoChangeSetPersister" />
    	</bean>
    
    
    
    </beans>

    Stack trace when I start tc server 2.1

    Code:
    Nov 3, 2011 11:38:43 PM org.apache.catalina.core.StandardContext listenerStart
    SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoChangeSetPersister' defined in file [/Users/mark/apps/springsource/tc-server-developer-2.1.1.RELEASE/cbs2/wtpwebapps/mongo/WEB-INF/classes/META-INF/spring/applicationContext-mongo.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [/Users/mark/apps/springsource/tc-server-developer-2.1.1.RELEASE/cbs2/wtpwebapps/mongo/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.mongo.domain.NoteData
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
    blah...blah..blah
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [/Users/mark/apps/springsource/tc-server-developer-2.1.1.RELEASE/cbs2/wtpwebapps/mongo/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.mongo.domain.NoteData
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    blah...blah..blah
    Last edited by md10024; Nov 4th, 2011, 08:54 PM.

  • #2
    To get around the hibernate annotation complaint about not finding a usable Id, I added an Id into my domain objects, as an experiment. This hack apparently satisfied hibernate's requirements during load time and allowed TC server to start, hinting that this is really a bug in the way the aspects are (or are not) resolved during load time weaving.

    This workaround doesn't really "work" however in that the repository store method throws an exception complaining about invalid model attributes, presumably the javax.persistence.Id ....

    I think I'll report this as a bug.

    Code:
    package com.mongo.domain;
    
    import java.math.BigInteger;
    
    import javax.persistence.Id;
    
    import org.springframework.roo.addon.javabean.RooJavaBean;
    import org.springframework.roo.addon.layers.repository.mongo.RooMongoEntity;
    import org.springframework.roo.addon.tostring.RooToString;
    
    @RooJavaBean
    @RooToString
    @RooMongoEntity
    public class NoteData {
    
    	@Id
    	BigInteger myId; //hack alert!
    	
    	private String noteName;
    }

    Comment


    • #3
      Ok, I downloaded the nightly roo version and am now getting the error below. I'll get the nightly spring-data-mongodb and give it a try with that

      Code:
      2011-11-04 17:52:51,819 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoEnityRepository': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/convert/EntityConverter
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)

      Comment


      • #4
        Still having problems getting cross-store persistence working with Roo after including the dependency on the spring-data mongo build snapshot (spring-data-mongodb-80aa057) while using roo build snapshot (spring-roo-51be0cd)

        My JPA entity looks like this,
        Code:
        @RooJavaBean
        @RooToString
        @RooDisplayString
        @RooJpaActiveRecord
        public class JpaEntity {
        
        	private String name;
        
        	@RelatedDocument
        	private MongoEntity mongoEntity;
        }
        My Mongo entity

        Code:
        @RooJavaBean
        @RooToString
        @RooMongoEntity
        @RooDisplayString
        public class MongoEntity {
        
            private String name;
        }

        My mongo context

        Code:
        	<mongo:db-factory host="${mongo.host}" id="mongoDbFactory"
        		port="${mongo.port}" />
        
        	<mongo:repositories base-package="com.test" />
        
        	<!-- To translate any MongoExceptions thrown in @Repository annotated classes -->
        	<context:annotation-config />
        
        	<bean class="org.springframework.data.mongodb.core.MongoTemplate"
        		id="mongoTemplate">
        		<constructor-arg ref="mongoDbFactory" />
        	</bean>
        
        	<bean class="org.springframework.data.mongodb.core.MongoExceptionTranslator" />
        
        	<!-- Mongo cross-store aspect config -->
        	<bean id="mongoChangeSetPersister"
        		class="org.springframework.data.mongodb.crossstore.MongoChangeSetPersister">
        		<property name="mongoTemplate" ref="mongoTemplate" />
        		<property name="entityManagerFactory" ref="entityManagerFactory" />
        	</bean>
        
        	<bean
        		class="org.springframework.data.mongodb.crossstore.MongoDocumentBacking"
        		factory-method="aspectOf">
        		<property name="changeSetPersister" ref="mongoChangeSetPersister" />
        	</bean>
        
        </beans>
        My test code:


        Code:
        			MongoEntity me = new MongoEntity();
        			me.setName("me");
        			meRepo.save(me);
        		
        			
        			JpaEntity je = new JpaEntity();
        			je.setName("je");
        			
        			je.setMongoEntity(me);
        			je.persist();
        			
        			List<MongoEntity> meList = meRepo.findAll();
        			
        			List<JpaEntity> jpas = JpaEntity.findAllJpaEntitys();
        			JpaEntity jpae = jpas.get(0);
        
                                // this fails, see stacktrace
        			MongoEntity mongo = jpae.getMongoEntity();
        			
        			String name = mongo.getName();
        Both entities persist properly, but when retrieving the JPA entity I get a stack overflow
        Code:
        SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
        java.lang.StackOverflowError
        	at java.lang.Long.toString(Long.java:97)
        	at java.lang.String.valueOf(String.java:2945)
        	at java.lang.Long.toString(Long.java:740)
        	at java.lang.String.valueOf(String.java:2826)
        	at java.lang.StringBuilder.append(StringBuilder.java:115)
        	at com.test.domain.JpaEntity_Roo_ToString.ajc$interMethod$com_test_domain_JpaEntity_Roo_ToString$com_test_domain_JpaEntity$toString(JpaEntity_Roo_ToString.aj:10)
        	at com.test.domain.JpaEntity.toString(JpaEntity.java:1)
        	at java.lang.String.valueOf(String.java:2826)
        	at java.lang.StringBuilder.append(StringBuilder.java:115)
        	at org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.getPersistentId(MongoChangeSetPersister.java:108)
        	at org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethod$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$get_persistent_id(MongoDocumentBacking.aj:198)
        	at com.test.domain.JpaEntity.get_persistent_id(JpaEntity.java:1)
        	at org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethodDispatch1$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$get_persistent_id(MongoDocumentBacking.aj)
        	at com.test.domain.JpaEntity_Roo_JavaBean.mongoEntity_aroundBody1$advice(JpaEntity_Roo_JavaBean.aj:245)
        	at com.test.domain.JpaEntity_Roo_JavaBean.ajc$interMethod$com_test_domain_JpaEntity_Roo_JavaBean$com_test_domain_JpaEntity$getMongoEntity(JpaEntity_Roo_JavaBean.aj:19)
        	at com.test.domain.JpaEntity.getMongoEntity(JpaEntity.java:1)
        	at com.test.domain.JpaEntity_Roo_JavaBean.ajc$interMethodDispatch1$com_test_domain_JpaEntity_Roo_JavaBean$com_test_domain_JpaEntity$getMongoEntity(JpaEntity_Roo_JavaBean.aj)
        	at com.test.domain.JpaEntity_Roo_ToString.ajc$interMethod$com_test_domain_JpaEntity_Roo_ToString$com_test_domain_JpaEntity$toString(JpaEntity_Roo_ToString.aj:11)
        	at com.test.domain.JpaEntity.toString(JpaEntity.java:1)
        	at java.lang.String.valueOf(String.java:2826)
        	at java.lang.StringBuilder.append(StringBuilder.java:115)
        	at org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.getPersistentId(MongoChangeSetPersister.java:108)
        	at org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethod$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$get_persistent_id(MongoDocumentBacking.aj:198)
        	at com.test.domain.JpaEntity.get_persistent_id(JpaEntity.java:1)
        	at org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethodDispatch1$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$get_persistent_id(MongoDocumentBacking.aj)
        	at com.test.domain.JpaEntity_Roo_JavaBean.mongoEntity_aroundBody1$advice(JpaEntity_Roo_JavaBean.aj:245)
        	at com.test.domain.JpaEntity_Roo_JavaBean.ajc$interMethod$com_test_domain_JpaEntity_Roo_JavaBean$com_test_domain_JpaEntity$getMongoEntity(JpaEntity_Roo_JavaBean.aj:19)
        	at com.test.domain.JpaEntity.getMongoEntity(JpaEntity.java:1)
        	at com.test.domain.JpaEntity_Roo_JavaBean.ajc$interMethodDispatch1$com_test_domain_JpaEntity_Roo_JavaBean$com_test_domain_JpaEntity$getMongoEntity(JpaEntity_Roo_JavaBean.aj)
        	at com.test.domain.JpaEntity_Roo_ToString.ajc$interMethod$com_test_domain_JpaEntity_Roo_ToString$com_test_domain_JpaEntity$toString(JpaEntity_Roo_ToString.aj:11)
        	at com.test.domain.JpaEntity.toString(JpaEntity.java:1)
        	at java.lang.String.valueOf(String.java:2826)
        	at java.lang.StringBuilder.append(StringBuilder.java:115)
        	at org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.getPersistentId(MongoChangeSetPersister.java:108)
        	at org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethod$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$get_persistent_id(MongoDocumentBacking.aj:198)
        	at com.test.domain.JpaEntity.get_persistent_id(JpaEntity.java:1)
        	at org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethodDispatch1$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$get_persistent_id(MongoDocumentBacking.aj)
        	at com.test.domain.JpaEntity_Roo_JavaBean.mongoEntity_aroundBody1$advice(JpaEntity_Roo_JavaBean.aj:245)
        	at com.test.domain.JpaEntity_Roo_JavaBean.ajc$interMethod$com_test_domain_JpaEntity_Roo_JavaBean$com_test_domain_JpaEntity$getMongoEntity(JpaEntity_Roo_JavaBean.aj:19)
        	at com.test.domain.JpaEntity.getMongoEntity(JpaEntity.java:1)
        	at com.test.domain.JpaEntity_Roo_JavaBean.ajc$interMethodDispatch1$com_test_domain_JpaEntity_Roo_JavaBean$com_test_domain_JpaEntity$getMongoEntity(JpaEntity_Roo_JavaBean.aj)
        	at com.test.domain.JpaEntity_Roo_ToString.ajc$interMethod$com_test_domain_JpaEntity_Roo_ToString$com_test_domain_JpaEntity$toString(JpaEntity_Roo_ToString.aj:11)
        	at com.test.domain.JpaEntity.toString(JpaEntity.java:1)
        	at java.lang.String.valueOf(String.java:2826)
        So far, I have not been able to get cross-store persistence working with Roo in either the milestone nor nightly builds. Does anyone else have it working??

        thanks,
        Mark

        Comment


        • #5
          See https://jira.springsource.org/browse/ROO-2864
          Please vote for it if you want to see Roo support cross-store capabilities

          Comment

          Working...
          X