Search in sources :

Example 1 with DataPoint

use of org.hibernate.osgi.test.client.DataPoint in project hibernate-orm by hibernate.

the class OsgiIntegrationTest method testNative.

@Test
public void testNative() throws Exception {
    final ServiceReference sr = bundleContext.getServiceReference(SessionFactory.class.getName());
    final SessionFactory sf = (SessionFactory) bundleContext.getService(sr);
    Session s = sf.openSession();
    s.getTransaction().begin();
    s.persist(new DataPoint("Brett"));
    s.getTransaction().commit();
    s.close();
    s = sf.openSession();
    s.getTransaction().begin();
    DataPoint dp = (DataPoint) s.get(DataPoint.class, 1);
    assertNotNull(dp);
    assertEquals("Brett", dp.getName());
    s.getTransaction().commit();
    s.close();
    dp.setName("Brett2");
    s = sf.openSession();
    s.getTransaction().begin();
    s.update(dp);
    s.getTransaction().commit();
    s.close();
    s = sf.openSession();
    s.getTransaction().begin();
    dp = (DataPoint) s.get(DataPoint.class, 1);
    assertNotNull(dp);
    assertEquals("Brett2", dp.getName());
    s.getTransaction().commit();
    s.close();
    s = sf.openSession();
    s.getTransaction().begin();
    s.createQuery("delete from DataPoint").executeUpdate();
    s.getTransaction().commit();
    s.close();
    s = sf.openSession();
    s.getTransaction().begin();
    dp = (DataPoint) s.get(DataPoint.class, 1);
    assertNull(dp);
    s.getTransaction().commit();
    s.close();
}
Also used : SessionFactory(org.hibernate.SessionFactory) DataPoint(org.hibernate.osgi.test.client.DataPoint) AuditedDataPoint(org.hibernate.osgi.test.client.AuditedDataPoint) ServiceReference(org.osgi.framework.ServiceReference) Session(org.hibernate.Session) Test(org.junit.Test)

Example 2 with DataPoint

use of org.hibernate.osgi.test.client.DataPoint in project hibernate-orm by hibernate.

the class OsgiIntegrationTest method testJpa.

@Test
public void testJpa() throws Exception {
    final ServiceReference serviceReference = bundleContext.getServiceReference(PersistenceProvider.class.getName());
    final PersistenceProvider persistenceProvider = (PersistenceProvider) bundleContext.getService(serviceReference);
    final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory("hibernate-osgi-test", null);
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    em.persist(new DataPoint("Brett"));
    em.getTransaction().commit();
    em.close();
    em = emf.createEntityManager();
    em.getTransaction().begin();
    DataPoint dp = em.find(DataPoint.class, 1);
    assertNotNull(dp);
    assertEquals("Brett", dp.getName());
    em.getTransaction().commit();
    em.close();
    em = emf.createEntityManager();
    em.getTransaction().begin();
    dp = em.find(DataPoint.class, 1);
    dp.setName("Brett2");
    em.getTransaction().commit();
    em.close();
    em = emf.createEntityManager();
    em.getTransaction().begin();
    em.createQuery("delete from DataPoint").executeUpdate();
    em.getTransaction().commit();
    em.close();
    em = emf.createEntityManager();
    em.getTransaction().begin();
    dp = em.find(DataPoint.class, 1);
    assertNull(dp);
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) DataPoint(org.hibernate.osgi.test.client.DataPoint) AuditedDataPoint(org.hibernate.osgi.test.client.AuditedDataPoint) PersistenceProvider(javax.persistence.spi.PersistenceProvider) EntityManagerFactory(javax.persistence.EntityManagerFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

AuditedDataPoint (org.hibernate.osgi.test.client.AuditedDataPoint)2 DataPoint (org.hibernate.osgi.test.client.DataPoint)2 Test (org.junit.Test)2 ServiceReference (org.osgi.framework.ServiceReference)2 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1