To manage entities in your persistence application, you need to obtain an entity manager from an EntityManagerFactory.
An EntityManager instance is an interface that are used to interact with the persistence context. This API is used to:
An entity manager can be acquired through
In the Java SE environment, not the container but the application manages the life cycle of an entity manager.
You must create this entity manager using the EntityManagerFactory's method createEntityManager. You have to use the javax.persistence.Persistence class to bootstrap an EntityManagerFactory instance.
public class Employee {
public static void main(String[] args) {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("EmpService");
EntityManager em = emf.createEntityManager();
...
em.close();
emf.close();
}
Notice that you need to explicitly close the entity manager and the factory.
In the Java EE environment, you acquire an entity manager:
@PersistenceContext
public EntityManager em;
You can only use the @PersistenceContext annotation injection on session beans, servlets and JSP.
@Stateless
@PersistenceContext(name="ProjectEM", unitName="Project")
public class ProjectSessionBean implements Project {
@Resource
SessionContext ctx;
public void makeCurrent() {
try {
EntityManager em = (EntityManager)ctx.lookup("ProjectEM");
...
}
}
@PersistenceUnit
EntityManagerFactory emf;
Exception Description: The getter method [public boolean generated.ObjectT.isIsDefaultReadable()] on entity class [class generated.ObjectT] does not have a corresponding setter method defined.
at oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:143)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:169)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at org.jvnet.hyperjaxb3.ejb.test.AbstractEntityManagerTest.createEntityManagerFactory(AbstractEntityManagerTest.java:85)
at org.jvnet.hyperjaxb3.ejb.test.AbstractEntityManagerTest.setUp(AbstractEntityManagerTest.java:44)
at org.jvnet.hyperjaxb3.ejb.test.AbstractEntityManagerSamplesTest.setUp(AbstractEntityManagerSamplesTest.java:39)
Xjc makes use of Boolean in the Set method but it must use the primitive type boolean (without capital b).
A work around is to use a Jaxb binding file with the below node.
<jaxb:globalBindings generateIsSetMethod="true" />
More: Stackoverflow