Announcement Announcement Module
Collapse
No announcement yet.
Spring JPA + MongoDB cross-store is not persisting properties of the document part Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JPA + MongoDB cross-store is not persisting properties of the document part

    Hi,

    Still trying to integrate Spring data JPA and mongo with crossstore functionalities, but without success until now

    My simplest case is to save a map of String/String in a Object (very close to the example in the documentation) :

    Code:
    public class ServiceDataFolder implements Serializable {
    
    	private static final long serialVersionUID = 1L;
    	private boolean required = false;
    	private Map<String, String> questionari;
    
    	public Map<String, String> getQuestionari() {
    		return questionari;
    	}
    
    	public void setQuestionari(Map<String, String> questionari) {
    		this.questionari = questionari;
    	}
    
    	public ServiceDataFolder addQuestionnaire(String title, String value) {
    		this.questionari.put(title, value);
    		return this;
    	}
    
    	public boolean isRequired() {
    		return required;
    	}
    
    	public void setRequired(boolean required) {
    		this.required = required;
    	}
    
    
    	@Override
    	public String toString() {
                   ...
    	}
    
    }
    One of my worries about cross-store support is the constriction to use this kind of "wrapped objects" also when are not necessary, but ok ...
    The object is java plain with no MongoDB annotations (as i seen in the docs it must no be annotated with @Document, @Index, etc) and used as a direct reference by the jpa entity:

    Code:
    package org.novaworks.legal.model;
    
    import java.util.Map;
    import java.util.Map.Entry;
    
    import javax.persistence.Entity;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    import javax.validation.constraints.NotNull;
    
    import org.hibernate.annotations.Cache;
    import org.hibernate.annotations.CacheConcurrencyStrategy;
    import org.hibernate.validator.constraints.NotEmpty;
    import org.novaworks.legal.model.document.ServiceDataFolder;
    import org.springframework.data.mongodb.crossstore.RelatedDocument;
    
    
    @Entity
    @Table(name = "SERVIZI")
    @Cache(region="long_lived", usage = CacheConcurrencyStrategy.READ_WRITE) 
    public class Service extends AbstractPersistentEntity { //abstract contains ID, Version and other common stuff ...
    
    	private static final long serialVersionUID = 1L;
    	
    	@NotEmpty
    	private String code;
    	@NotEmpty
    	private String name;
    	@NotEmpty
    	private String description;
    	
    	@ManyToOne(optional = false)
    	private ServiceGroup serviceGroup;
    	
    	@RelatedDocument
    	ServiceDataFolder infos;
    	
    	@NotNull
    	private Double price;
    	
    	private String workflowID;
    	
    	
    	public String getWorkflowID() {
    		return workflowID;
    	}
    	public void setWorkflowID(String workflowID) {
    		this.workflowID = workflowID;
    	}
    	public ServiceGroup getGruppo() {
    		return gruppo;
    	}
    	public void setGruppo(ServiceGroup gruppo) {
    		this.gruppo = gruppo;
    	}
    	public ServiceDataFolder getInfos() {
    		return infos;
    	}
    	public void setInfos(ServiceDataFolder infos) {
    		this.infos = infos;
    	}
    
           ... other getters/setters
    
    }
    Entity are persisted through interface extending JpaRepository<Service, String> using her save method. After a call to save, changes to entity are committed and a mongoDB entry related to Service entity is created but properties of ServiceDataFolder are not stored!
    Specifically the property "questionary" is created but empty (no boolean property "required" is no "infos" collection property):

    Code:
    {
    	"_id" : ObjectId("4fc77b323004f9b4be7690cc"),
    	"_entity_id" : "1483a6b2-a8aa-407a-9844-fa6d18eefb06",
    	"_entity_class" : "org.novaworks.legal.model.Service",
    	"_entity_field_name" : "questionari",
    	"_class" : "org.novaworks.legal.model.document.ServiceDataFolder",
    	"questionari" : {
    		
    	},
    	"_entity_field_class" : "org.novaworks.legal.model.document.ServiceDataFolder"
    }
    Transactions boundaries are correctly generated (i'm using Atomikos standalone JTA transaction-manager): i see two partecipant registrations (probably one for the EntityManager and another one for Mongo connections?).

    Version used by frameworks realted libs:

    HTML Code:
              <properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    		<spring.framework.version>3.1.0.M2</spring.framework.version>
    		<spring.data.version>1.1.0.BUILD-SNAPSHOT</spring.data.version>
    		<org.cloudfoundry-version>0.6.1</org.cloudfoundry-version>
    		<aspectj.version>1.6.12</aspectj.version>
    	 </properties>
    
    
                    <dependency>
    			<groupId>org.hibernate.javax.persistence</groupId>
    			<artifactId>hibernate-jpa-2.0-api</artifactId>
    			<version>1.0.0.Final</version>
    		</dependency>
    		<dependency>
     			<groupId>org.springframework.data</groupId>
     			<artifactId>spring-data-mongodb</artifactId>
     			<version>${spring.data.version}</version>
    		</dependency> 
    		<dependency>
    			<groupId>org.springframework.data</groupId>
    			<artifactId>spring-data-jpa</artifactId>
    			<version>${spring.data.version}</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.springframework.data</groupId>
    			<artifactId>spring-data-mongodb-cross-store</artifactId>
    			<version>1.1.0.M1</version>
    			<exclusions>
    				<exclusion>
    					<artifactId>spring-data-commons-core</artifactId>
    					<groupId>org.springframework.data</groupId>
    				</exclusion>
    			</exclusions>  
    		</dependency>
    For the sake of completion the following is the log after a save invocation:

    Code:
    2012-06-01 09:31:36,979 INFO  org.novaworks.legal.ui.panel.ServicePanel.execute:469 - saving org.novaworks.legal.model.Service@5d2b5465
    2012-06-01 09:31:36,981 DEBUG org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$before$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$2$adf21a1:135 - User-defined constructor called on DocumentBacked object of class class org.novaworks.legal.model.Service
    2012-06-01 09:31:36,987 DEBUG org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$before$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$2$adf21a1:135 - User-defined constructor called on DocumentBacked object of class class org.novaworks.legal.model.Service
    2012-06-01 09:31:36,988 DEBUG org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethod$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$itdPostLoad:230 - JPA lifecycle event PostLoad: org.novaworks.legal.model.Service :: org.novaworks.legal.model.Service@8f7cb481
    2012-06-01 09:31:36,988 DEBUG org.springframework.data.mongodb.crossstore.MongoDocumentBacking.registerTransactionSynchronization:147 - Adding transaction synchronization for org.novaworks.legal.model.Service@8f7cb481
    2012-06-01 09:31:36,989 DEBUG org.springframework.data.mongodb.crossstore.MongoDocumentBacking.ajc$interMethod$org_springframework_data_mongodb_crossstore_MongoDocumentBacking$org_springframework_data_mongodb_crossstore_DocumentBacked$itdPostLoad:230 - JPA lifecycle event PostLoad: org.novaworks.legal.model.Service :: org.novaworks.legal.model.Service@5d2b5465
    2012-06-01 09:31:36,989 DEBUG org.springframework.data.mongodb.crossstore.MongoDocumentBacking.registerTransactionSynchronization:147 - Adding transaction synchronization for org.novaworks.legal.model.Service@5d2b5465
    2012-06-01 09:31:36,999 DEBUG org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.persistState:119 - Flush: changeset: {}
    2012-06-01 09:31:36,999 DEBUG org.springframework.data.mongodb.core.MongoDbUtils.doGetDB:111 - Registering Spring transaction synchronization for new Hibernate Session
    2012-06-01 09:31:36,999 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCommit:36 - After Commit called for org.novaworks.legal.model.Service@8f7cb481
    2012-06-01 09:31:36,999 DEBUG org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.persistState:119 - Flush: changeset: {}
    2012-06-01 09:31:36,999 DEBUG org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.persistState:119 - Flush: changeset: {}
    2012-06-01 09:31:37,000 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCommit:36 - After Commit called for org.novaworks.legal.model.Service@5d2b5465
    2012-06-01 09:31:37,000 DEBUG org.springframework.data.mongodb.crossstore.MongoChangeSetPersister.persistState:119 - Flush: changeset: {}
    2012-06-01 09:31:37,000 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCompletion:42 - After Completion called with status = 0
    2012-06-01 09:31:37,000 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCompletion:42 - After Completion called with status = 0
    2012-06-01 09:31:37,001 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCompletion:46 - ChangedSetBackedTransactionSynchronization completed successfully for org.novaworks.legal.model.Service@8f7cb481
    2012-06-01 09:31:37,001 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCompletion:42 - After Completion called with status = 0
    2012-06-01 09:31:37,001 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCompletion:42 - After Completion called with status = 0
    2012-06-01 09:31:37,001 DEBUG org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization.afterCompletion:46 - ChangedSetBackedTransactionSynchronization completed successfully for org.novaworks.legal.model.Service@5d2b5465
    thanks to anyone will give me any help!

  • #2
    Any help?
    I'm stucked here. It's seems strange that cross-store persistence is working bad in that way :-(

    Comment


    • #3
      Oliver: need to open a jira issue?

      Comment

      Working...
      X