01.實體(Entity)與實體管理器

Entity and Entity Manager



(製作分享) JPA Controller & MVC

Entity





EntityManager









開發設計命名規範



  1. User Entity class -> UserEO
  2. Persistence.createEntityManagerFactory -> emf
  3. EntityManager -> em




Example




package wisdomfish;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.persistence.EntityNotFoundException;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import wisdomfish.exceptions.NonexistentEntityException;
import wisdomfish.exceptions.PreexistingEntityException;

/**
*
* @author ChaoYi, Kuo
*/
public class CustomerJpaController {

public CustomerJpaController() {
emf = Persistence.createEntityManagerFactory("WisdomFish JSF CRUDPU");
}
private EntityManagerFactory emf = null;

public EntityManager getEntityManager() {
return emf.createEntityManager();
}




Bean Validation 1.0, JSR 303



02.Bean Validation(JSR303)




Subpages (2): Basic JPA Entity
Comments