diff --git a/documentation/src/main/docbook/devguide/en-US/chapters/osgi/OSGi.xml b/documentation/src/main/docbook/devguide/en-US/chapters/osgi/OSGi.xml index dcb1279727..ae53844744 100644 --- a/documentation/src/main/docbook/devguide/en-US/chapters/osgi/OSGi.xml +++ b/documentation/src/main/docbook/devguide/en-US/chapters/osgi/OSGi.xml @@ -383,14 +383,6 @@ tutorials' features.xml for example sequences. - - - The environment should be considered STATIC. Hibernate currently does not support the ability - to dynamically add and remove client bundles during runtime. Doing so is typically - catastrophic. We hope to better support at least partially-dynamic environments in - Hibernate 5. - - diff --git a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java index e4b748daf4..dba3609e97 100644 --- a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java +++ b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java @@ -30,9 +30,11 @@ import org.hibernate.osgitest.entity.DataPoint; * @author Brett Meyer */ public class DataPointServiceImpl implements DataPointService { + + private HibernateUtil hibernateUtil = new HibernateUtil(); public void add(DataPoint dp) { - EntityManager em = HibernateUtil.getEntityManager(); + EntityManager em = hibernateUtil.getEntityManager(); em.getTransaction().begin(); em.persist( dp ); em.getTransaction().commit(); @@ -40,7 +42,7 @@ public class DataPointServiceImpl implements DataPointService { } public void update(DataPoint dp) { - EntityManager em = HibernateUtil.getEntityManager(); + EntityManager em = hibernateUtil.getEntityManager(); em.getTransaction().begin(); em.merge( dp ); em.getTransaction().commit(); @@ -48,7 +50,7 @@ public class DataPointServiceImpl implements DataPointService { } public DataPoint get(long id) { - EntityManager em = HibernateUtil.getEntityManager(); + EntityManager em = hibernateUtil.getEntityManager(); em.getTransaction().begin(); DataPoint dp = (DataPoint) em.createQuery( "from DataPoint dp where dp.id=" + id ).getSingleResult(); em.getTransaction().commit(); @@ -57,7 +59,7 @@ public class DataPointServiceImpl implements DataPointService { } public List getAll() { - EntityManager em = HibernateUtil.getEntityManager(); + EntityManager em = hibernateUtil.getEntityManager(); em.getTransaction().begin(); List list = em.createQuery( "from DataPoint" ).getResultList(); em.getTransaction().commit(); @@ -66,7 +68,7 @@ public class DataPointServiceImpl implements DataPointService { } public void deleteAll() { - EntityManager em = HibernateUtil.getEntityManager(); + EntityManager em = hibernateUtil.getEntityManager(); em.getTransaction().begin(); em.createQuery( "delete from DataPoint" ).executeUpdate(); em.getTransaction().commit(); diff --git a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java index 66442637b3..0927f15f7d 100644 --- a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java +++ b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/src/main/java/org/hibernate/osgitest/HibernateUtil.java @@ -35,13 +35,13 @@ import org.osgi.framework.ServiceReference; public class HibernateUtil { - private static EntityManagerFactory emf; + private EntityManagerFactory emf; - public static EntityManager getEntityManager() { + public EntityManager getEntityManager() { return getEntityManagerFactory().createEntityManager(); } - private static EntityManagerFactory getEntityManagerFactory() { + private EntityManagerFactory getEntityManagerFactory() { if ( emf == null ) { Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class ); // Could get this by wiring up OsgiTestBundleActivator as well. diff --git a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java index 4bd2344642..c44e620ebb 100644 --- a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java +++ b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java @@ -31,9 +31,11 @@ import org.hibernate.osgitest.entity.DataPoint; * @author Brett Meyer */ public class DataPointServiceImpl implements DataPointService { + + private HibernateUtil hibernateUtil = new HibernateUtil(); public void add(DataPoint dp) { - Session s = HibernateUtil.getSession(); + Session s = hibernateUtil.getSession(); s.getTransaction().begin(); s.persist( dp ); s.getTransaction().commit(); @@ -41,7 +43,7 @@ public class DataPointServiceImpl implements DataPointService { } public void update(DataPoint dp) { - Session s = HibernateUtil.getSession(); + Session s = hibernateUtil.getSession(); s.getTransaction().begin(); s.update( dp ); s.getTransaction().commit(); @@ -49,7 +51,7 @@ public class DataPointServiceImpl implements DataPointService { } public DataPoint get(long id) { - Session s = HibernateUtil.getSession(); + Session s = hibernateUtil.getSession(); s.getTransaction().begin(); DataPoint dp = (DataPoint) s.createCriteria( DataPoint.class ).add( Restrictions.eq( "id", id ) ).uniqueResult(); @@ -60,7 +62,7 @@ public class DataPointServiceImpl implements DataPointService { // Test lazy loading (mainly to make sure the proxy classes work in OSGi) public DataPoint load(long id) { - Session s = HibernateUtil.getSession(); + Session s = hibernateUtil.getSession(); s.getTransaction().begin(); DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long(id) ); // initialize @@ -71,7 +73,7 @@ public class DataPointServiceImpl implements DataPointService { } public List getAll() { - Session s = HibernateUtil.getSession(); + Session s = hibernateUtil.getSession(); s.getTransaction().begin(); List list = s.createQuery( "from DataPoint" ).list(); s.getTransaction().commit(); @@ -80,7 +82,7 @@ public class DataPointServiceImpl implements DataPointService { } public void deleteAll() { - Session s = HibernateUtil.getSession(); + Session s = hibernateUtil.getSession(); s.getTransaction().begin(); s.createQuery( "delete from DataPoint" ).executeUpdate(); s.getTransaction().commit(); diff --git a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java index d44072f157..15fb4c7db1 100644 --- a/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java +++ b/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/HibernateUtil.java @@ -33,13 +33,13 @@ import org.osgi.framework.ServiceReference; public class HibernateUtil { - private static SessionFactory sf; + private SessionFactory sf; - public static Session getSession() { + public Session getSession() { return getSessionFactory().openSession(); } - private static SessionFactory getSessionFactory() { + private SessionFactory getSessionFactory() { if ( sf == null ) { Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class ); // Could get this by wiring up OsgiTestBundleActivator as well.