List of usage examples for javax.persistence EntityManagerFactory createEntityManager
public EntityManager createEntityManager();
EntityManager
. From source file:dao.UsuarioDao.java
public void cadastrarPessoa(Usuario usuario) { EntityManagerFactory factory = Persistence.createEntityManagerFactory("LoginUsersPU"); EntityManager em = factory.createEntityManager(); em.getTransaction().begin();/* w w w .j a v a2s . c om*/ em.persist(usuario); em.getTransaction().commit(); em.close(); }
From source file:org.croodie.resource.UserServerResource.java
@Override public Representation createUser(User user) { EntityManagerFactory emf = EMF.get(); EntityManager em = emf.createEntityManager(); try {/*from w w w . j a va 2s.c om*/ em.persist(user); } catch (Exception ex) { throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Internal Server Error", ex); } finally { em.close(); } return new JacksonRepresentation<User>(user); }
From source file:org.croodie.resource.UserServerResource.java
@Delete public Representation deleteUser(Representation entity) { Form form = new Form(entity); String id = form.getFirstValue("id"); EntityManagerFactory emf = EMF.get(); EntityManager em = emf.createEntityManager(); try {/*from ww w. j a v a 2 s.c om*/ User user = em.find(User.class, id); em.remove(user); } finally { em.close(); } return null; }
From source file:org.croodie.resource.UserServerResource.java
@Get public Representation retrieveUsers(Representation entity) { Form form = new Form(entity); String id = form.getFirstValue("id"); logger.info("Fetching user with id: " + id); EntityManagerFactory emf = EMF.get(); EntityManager em = emf.createEntityManager(); User user = null;/* w ww. j av a 2s.c om*/ try { user = em.find(User.class, id); } finally { em.close(); } return null; }
From source file:example.springdata.jpa.basics.BasicSample.java
/** * Sets up a {@link SimpleJpaRepository} instance. *///from www . j ava 2 s . c o m @Before public void setUp() { EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa.sample.plain"); em = factory.createEntityManager(); userRepository = new SimpleJpaRepository<User, Long>(User.class, em); em.getTransaction().begin(); }
From source file:sequrity.LoginService.java
public Korisnik loadUserByEmail(String email) throws Exception { Context envCtx = (Context) new InitialContext().lookup("java:comp/env"); EntityManagerFactory emf = (EntityManagerFactory) envCtx.lookup("ime"); EntityManager em = emf.createEntityManager(); try {//from ww w .jav a2 s. com return (Korisnik) em.createNamedQuery("Profesor.findByEmail").setParameter("email", email) .getSingleResult(); } catch (NoResultException e) { try { return (Korisnik) em.createNamedQuery("Student.findByEmail").setParameter("email", email) .getSingleResult(); } catch (NoResultException ex) { throw new Exception("Korisnik ne postoji u sistemu."); } } }
From source file:org.jasig.jpa.OpenEntityManagerAspect.java
/** * Create a JPA EntityManager to be bound to a request. * <p>Can be overridden in subclasses. * @param emf the EntityManagerFactory to use * @see javax.persistence.EntityManagerFactory#createEntityManager() *///from w w w .j a v a 2 s. co m protected EntityManager createEntityManager(EntityManagerFactory emf) { return emf.createEntityManager(); }
From source file:au.com.shawware.sandbox.persistence.JPAConfiguration.java
/** * Defines the entity manager to use./* w w w . j av a 2 s . c om*/ * * @param entityManagerFactory the factory to use to create the bean * * @return the entity manager bean */ @Bean @SuppressWarnings("static-method") public EntityManager entityManager(final EntityManagerFactory entityManagerFactory) { return entityManagerFactory.createEntityManager(); }
From source file:vn.edu.vnuk.tasks_jpa.dao.TaskDao.java
public EntityManager getEntityManager() { EntityManagerFactory factory = Persistence.createEntityManagerFactory("vnuk-tasks-jpaPU"); return factory.createEntityManager(); }
From source file:org.apache.shindig.social.opensocial.jpa.openjpa.Bootstrap.java
public void init(String unitName) { EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(unitName); entityManager = emFactory.createEntityManager(); }