我正在为 MySQL 使用 Spring Data Mongodb 和 Spring Data JPA 模块。
我已按照参考文档中的建议成功配置。尽管我能够成功更新 MYSQL 字段,但我能够保存但无法更新 mongodb“RelatedDocuments”。
实体关系就像
用户(Mysql)有地址(蒙戈)>有地址列表(与参考中的调查示例非常相似。
我的情况与http://forum.springsource.org/showthread.php?126897-Using-Spring-Data-with-MongoDB-and-MySQL完全相同
我使用的版本如下
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
请有人指出我可能缺少什么,配置文件如下
<!-- 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" />
MongoDB配置如下
<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" />