If you want to use MongoDB in the Java Enterprise World you have to address two questions.
The first one is: Should I use the native driver or should I use a persistence framework? Spring is a common framework in many Java applications. It has created a very good object-document-mapping framework with Spring Data for MongoDB. It is easy to integrate into new and existing Java applications.
The second question is: How can I ensure my deliverables against error? So you need a testing framework. NoSQLUnit is such a framework that helps you to write tests against a real MongoDB Server or an in-memory clone like Fongo.
This talk will cover Spring Data and NoSQLUnit. It will give a basic overview about what things are useful before you can deploy your application, e.g. in a cloud service like MongoSoup.
7. Hibernate ORM
@Entity
@Table(name = „ORDER")
public class Order implements Serializable {
!
!
@Id
@GeneratedValue
@Column(name="ID")
private Long id;
mapping of POJOs to relational database tables
!
@OneToOne(cascade = CascadeType.ALL, optional = false, orphanRemoval = false)
@JoinColumn(name = "USER_ID", nullable = false)
@ForeignKey(name = "ORDER_USER_FK")
private User user;
@OneToMany(mappedBy = "order")
@Fetch(FetchMode.JOIN)
private List<OrderItem> orderItems;
8. Spring Data
@Document(collection = Order.COLLECTION_NAME)
public class Order implements Serializable {
public static final String COLLECTION_NAME = "order";
!
@Id
private ObjectId id;
!
@Indexed(unique = true)
annotated sample class here
private long orderId;
!
@DBRef
private User user;
private List<OrderItem> orderItems;
!
@Indexed
private Date orderDate = new Date();
9. Unit Tests
- Fast
- Isolated
- Repeatable
relational in memory DB for testing
- Self-verifying
- Timely