Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:05:06+00:00 2026-06-16T05:05:06+00:00

I am using Spring Data Mongodb and Spring data JPA module for MySQL. I

  • 0

I am using Spring Data Mongodb and Spring data JPA module for MySQL.

I have successfully configured as suggested in the reference document.
I am able to save but not able to update the mongodb “RelatedDocuments”
though I am successfully able to update the MYSQL fields.

The entity relationship is like

User(Mysql) has Addresses(Mongo) > Has list of Address (quite similar to the survey example in reference.

My situation is exactly similar to http://forum.springsource.org/showthread.php?126897-Using-Spring-Data-with-MongoDB-and-MySQL

The versions I am using are as follows

spring-data.mongodb.version = 1.1.0.M1
spring.version = 3.1.2.RELEASE
    spring.data.jpa.version = 1.1.0.RELEASE

hibernate.entitymanager.version = 4.1.4.Final
hibernate.jpa-api.version = 1.0.1.Final (using JPA 2.0)

    aspectj.version = 1.6.12

Please could somebody point out what I might be missing, config files are as below

<!-- Activate Spring Data JPA repository support -->
<jpa:repositories base-package="com.domain.domain.*.repo" factory-class="com.mydomainit.domain.repo.BaseJpaRepositoryFactoryBean"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:persistenceXmlLocation="classpath*:META-INF/persistence.xml"
    p:persistenceUnitName="spring-jpa" p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="hibernateVendor" />

<bean id="hibernateVendor" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:showSql="true" p:generateDdl="false"
    p:database="MYSQL" />

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="entityManagerFactory" />

<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />

The MongoDB config is as below

<mongo:repositories base-package="com.domain.*.mongorepo" repository-impl-postfix="CustomImpl"
    factory-class="com.domain.mongorepo.CommonMongoRepoFactoryBean" />

<mongo:mongo id="mongoRef" host="${mongo.host.name}" port="${mongo.host.port}">
    <mongo:options connections-per-host="8" threads-allowed-to-block-for-connection-multiplier="4" connect-timeout="1000" max-wait-time="1500"
        auto-connect-retry="true" socket-keep-alive="true" socket-timeout="1500" slave-ok="true" write-number="${mongo.db.w}" write-timeout="${mongo.db.wtimeout}"
        write-fsync="${mongo.db.fsync}" />
</mongo:mongo>

<mongo:db-factory id="mongoDbFactory" dbname="${mongo.db.name}" username="${mongo.db.username}" password="${mongo.db.password}"
    mongo-ref="mongoRef" />

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate" c:mongoDbFactory-ref="mongoDbFactory" c:mongoConverter-ref="mappingConverter" />

<bean class="org.springframework.data.mongodb.crossstore.MongoDocumentBacking" factory-method="aspectOf">
    <property name="changeSetPersister" ref="mongoChangeSetPersister" />
</bean>
<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.core.MongoExceptionTranslator" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:05:08+00:00Added an answer on June 16, 2026 at 5:05 am

    The documentation in Internet is quite old, which makes it is difficult to configure; there are many dependencies between libraries and some apis changed. I managed to make it work as follows. I hope it helps:

    pom.xml

        <spring.version>3.2.0.RELEASE</spring.version>
        <querydsl.version>2.9.0</querydsl.version>
        <spring-data-jpa.version>1.2.0.RELEASE</spring-data-jpa.version>
        <mongodb.version>1.1.1.RELEASE</mongodb.version>
    
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>${mongodb.version}</version>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-mongodb</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb-cross-store</artifactId>
            <version>${mongodb.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.7.0</version>
        </dependency>
    

    databaseContext.xml

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <mongo:mongo host="localhost" port="27017" />
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg ref="mongo" />
        <constructor-arg name="databaseName" value="databasename" />
    </bean>
    <mongo:repositories base-package="com.yourcompany.repository.mongodb" />
    
    <bean class="org.springframework.data.mongodb.core.MongoExceptionTranslator" />
    <bean class="org.springframework.data.mongodb.crossstore.MongoDocumentBacking" factory-method="aspectOf">
        <property name="changeSetPersister" ref="mongoChangeSetPersister" />
    </bean>
    <bean id="mongoChangeSetPersister" class="org.springframework.data.mongodb.crossstore.MongoChangeSetPersister">
        <property name="mongoTemplate" ref="mongoTemplate" />
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    

    Product Object (to be stored in MySQL)

    @Entity
    public class Product {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long id; // MySQL + MongoDB
        private double value; // MySQL
        @RelatedDocument
        private ProductInfo info; // MongoDB
    }
    

    ProductInfo Object (to be stored in MongoDB)

    @Document
    public class ProductInfo {
        @Id
        public ObjectId id;
        private String name;
        private String description;
    }
    

    Product Repository

    @Repository
    public interface ProductRepository extends JpaRepository<Product, Long>{}
    

    JUnit Test

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes = { TestApplicationContext.class })
    @TestExecutionListeners({ TransactionalTestExecutionListener.class,
            DependencyInjectionTestExecutionListener.class })
    @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
    public class JournalMongoDBServiceIT  {
        @Resource
        ProductRepository productRepository;
    
        @Test
        @Transactional
        public void crossStoreProduct(){
            Product product = new Product();
            ProductInfo info = new ProductInfo();
            info.setName("Test");
            info.setDescription("Test Product");
            product.setInfo(info);
            productRepository.save(product);
        }
    
        @Test
        @Transactional
        public void crossStoreProductFindAndUpdate(){
            Product product = productRepository.findOne(32L);
            product.setValue(999L);
            product.getInfo().setDescription("Updated description");
            productRepository.save(product);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE I have a document class defined like
On a Spring project I'm using Spring Data MongoDB, and have 2 classes: public
I have few stored Javascripts in mongodb. I am using spring springframework.data.mongodb to access
I'm using Spring data neo4j 2.1.0.BUILD-SNAPSHOT and Neo4j 1.6.1 server. I have a Friendship
I am using the latest spring-data-mongodb (1.1.0.M2) and the latest Mongo Driver (2.9.0-RC1). I
I am using GridFsOperations API of spring-data for mongodb to store large files in
I'm building a Route Planner Webapp using Spring/Hibernate/Tomcat and a mysql database, I have
I'm using spring-data jpa 1.1.0.M1 now we were using a much higher version and
I am using Spring Data Commons - 1.4.0.RC1 and Spring Data MongoDB - 1.1.0.RC1,
i'm using Spring Data for MongoDB and got the following classes class A {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.