Tue Apr 20, 2010 4:31 pm
package com.codemiles.jpa;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public abstract class JPAService {
private EntityManager entityManager;
/**
* @param args
*/
public void insertTopic(Topic topic){
EntityManagerFactory factory = Persistence
.createEntityManagerFactory("persistenceUnitName");
entityManager = factory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(topic);
entityManager.getTransaction().commit();
entityManager.close();
factory.close();
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.