跳至主要内容

博文

目前显示的是标签为“Mongo”的博文

Data crossstore between Mongo and JPA

Data crossstore between Mongo and JPA Spring Data Mongo provides another attractive feature, when you mix to use Mongo and JPA in your projects, you can unite the models of Mongo and JPA. Model The   Conference   and   Signup   are still used as example models, Conference   is JPA entity class and   Signup   is a Mongo Document. @Entity public class Conference { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; @RelatedDocument private Signup signup; } The   Signup   Document is defined as the following. @Document public class Signup { @Id private String id; } @RelatedDocument   annotation indicates the   signup   property of Conference is a reference of   Signup   Mongo Document. This annotation will be processed by a AspectJ aspect which provided in Spring Data Mongo. You have to add some code fragments to Spring configuration. <!-- Mongo cros...

Spring Data Mongo: bridge MongoDB and Spring

Spring Data Mongo: bridge MongoDB and Spring MongoDB   is one of the most popular NoSQL products, Spring Data Mongo(Maven archetype id is spring-data-mongodb) tries to provides a simple approach to access MongoDB. Configuration Add the following code fragments in your Spring configuration. <!-- Mongo config --> <mongo:db-factory id="mongoDbFactory" host="localhost" port="27017" dbname="conference-db" /> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongoDbFactory" /> </bean> <mongo:repositories base-package="com.hantsylabs.example.spring.mongo" /> Firstly, declare a   DbFactory   which is responsible for connecting to the MongoDB server. Then, register the   MongoTemplate   object which envelop the data operations on MongoDB. Lastly add   mongo:repositories   with an essential   base-package...