Working with Mongodb in Java with Spring-data Part 1: Configuration
Mongodb is a document-oriented NoSql (reads not-only-sql) database designed with scalability in mind. The Spring-data project offers a nice high-level framework take makes working with mongodb easy with java. Key feature includes:
- Annotation based mapping between java objects and BSON data.
- MongoTemplate which provide abstraction for mongo java driver functionalities
- Cross store support for using mongodb together with other (Relational) database.
Current stable version is 1.0.1.Release, which address many issues with the previous releases and offer support for some new features such as atomic findAndUpdate operation.
To get started, add the following dependency to maven project:
Bulgogi, beacon and fried egg all in a burger, what more can I ask for…
Execellent breakfast at the Kraverie, where Korean BBQ marries French crepe, and while fooling around on the side with American and Mexcian staples, and begats delicious offspring like Kimchidilla, Seoul Cheesesteak, and kimchi-cheese fries. Yumm...
Simplifying Generic Dao with factory pattern and Spring
The Generic Dao pattern has been the standard for building CRUD web application in Java. With the Generic Dao interface:
public interface GenericDao<T extends DataObject, ID extends Serializable> {
T save (T object);
T load (ID id);
void remove (ID id);
Class<T> getPersistedType();
}
With each data type in your application, you extend the interface to add more specific function, and override the generic CRUD functionality:
public interface UserDao extends GenericDao<User, String> {
User findUserByEmail (String email);
}
Soon enough, you end up with lots of daos floating around. In order to preform operation on an object you want to persist, you must also know which dao to use. This is where the Factory pattern comes in handy:

