- JTA - container-managered entity manager
- injected to app automatically by j2ee container
- close/rollback transaction automatically without extra coding
- transaction propagation supported by j2ee container
- multiple data resources are required, such as more than 1 DB, DB and JMS,etc
- Resource_Local - application-managed entity manager
- can be used in j2ee container, J2SE and web container
- need to create entity manager explicitly
- need to close entity manager explicitly
- NO transaction propagation
- eliminate DAO or JPA DAO Pattern
1. A generic DAO interface
public interface GenericDao <T, PK extends Serializable> {
PK create(T newInstance);
T read(PK id);
void update(T transientObject);
}
2. implement the genericDAO
3. For particular entity, if any new behavior is required
public interface UserDAO extends GenericDao<Person,ID> {
// define new method
List<User> findByName(String name);
}
Reference URL:
http://employees.oneonta.edu/higgindm/sweng/Generic_DAO.htm
http://www.ibm.com/developerworks/java/library/j-genericdao/index.html
No comments:
Post a Comment