Package javax.persistence

Examples of javax.persistence.EntityManagerFactory.createEntityManager()


  }

  public void testConfiguredInterceptor() {
    configuration.setProperty( HibernatePersistence.INTERCEPTOR, ExceptionInterceptor.class.getName() );
    EntityManagerFactory emf = configuration.createEntityManagerFactory();
    EntityManager em = emf.createEntityManager();
    Item i = new Item();
    i.setName( "Laptop" );
    try {
      em.getTransaction().begin();
      em.persist( i );
View Full Code Here


  }

  public void testEmptyCreateEntityManagerFactoryAndPropertyUse() {
    configuration.setProperty( HibernatePersistence.INTERCEPTOR, ExceptionInterceptor.class.getName() );
    EntityManagerFactory emf = configuration.createEntityManagerFactory();
    EntityManager em = emf.createEntityManager();
    Item i = new Item();
    i.setName( "Laptop" );
    try {
      em.getTransaction().begin();
      em.persist( i );
View Full Code Here

    em.close();
  }

  public void testEventPerProperties() throws Exception {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory( "manager1", new HashMap() );
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Cat cat = new Cat();
    cat.setLength( 3 );
    cat.setAge( 34 );
    cat.setName( "Did" ); //should raise a validation exception
View Full Code Here

                    JPA_LOGGER.debugf("created new TransactionScopedEntityManager for unit name=%s", unitName);
            } else {
                // handle PersistenceContextType.EXTENDED
                ReferenceCountedEntityManager entityManager1 = SFSBCallStack.findPersistenceContext(unitName);
                if (entityManager1 == null) {
                    EntityManager tmpEm = emf.createEntityManager(properties);
                    entityManager = new ExtendedEntityManager(unitName, tmpEm);
                    entityManager1 = new ReferenceCountedEntityManager((ExtendedEntityManager)entityManager);
                    if (JPA_LOGGER.isDebugEnabled())
                        JPA_LOGGER.debugf("created new ExtendedEntityManager for unit name=%s", unitName);
View Full Code Here

        sfsb1.createEmployee("Sally","1 home street", 1);

      EntityManagerFactory emf = rawLookup("myEMF",EntityManagerFactory.class);
        assertNotNull("JNDI lookup of jboss.entity.manager.factory.jndi.name should return EntityManagerFactory", emf);

        EntityManager em = emf.createEntityManager();
        Employee emp = (Employee)em.find(Employee.class,1);
        assertTrue("Name read from EntityManager is Sally", "Sally".equals(emp.getName()));
    }
}
View Full Code Here

  @Test
  public void testAnnotatedClassFound() throws Exception {
    EntityManagerFactory emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
   
    EntityManager em = emf.createEntityManager();
   
    em.getTransaction().begin();
   
    Car c = new Car();
   
View Full Code Here

  public void testTranRequired() throws Exception {
    registerClient("bp-test-unit");
   
    EntityManagerFactory emf = getProxyEMF("bp-test-unit");
   
    final EntityManager managedEm = emf.createEntityManager();
   
    ensureTREBehaviour(false, managedEm, "contains", new Object());
    ensureTREBehaviour(false, managedEm, "createNamedQuery", "hi");
    ensureTREBehaviour(false, managedEm, "createNativeQuery", "hi");
    ensureTREBehaviour(false, managedEm, "createNativeQuery", "hi", Object.class);
View Full Code Here

   
    registerClient("bp-test-unit");
   
    EntityManagerFactory emf = getProxyEMF("bp-test-unit");
   
    final EntityManager managedEm = emf.createEntityManager();
   
    UserTransaction ut = context().getService(UserTransaction.class);
   
    ut.begin();
    try {
View Full Code Here

     * and pre-persist lifecycle events.
     */
    public void testValidation() {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("BeanValidation");
        EntityManager em = emf.createEntityManager();

        // Create a valid location
        Location loc = new Location();
        loc.setCity("Rochester");
        loc.setState("MN");
View Full Code Here

    private EntityManager createEntityManager()
    {
        final EntityManagerFactory emf = emfProvider.get();
        if ( null == properties )
        {
            return emf.createEntityManager();
        }
        else
        {
            return emf.createEntityManager( properties );
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.