I use hibernate3.2, oracle9.2 and websphere 5.1. After I try to configure jndi for the sessionfactory I get the error:
[10/11/07 10:07:33:212 EDT] 75667566 SessionFactor I org.hibernate.impl.SessionFactoryImpl building session factory [10/11/07 10:07:33:961 EDT] 75667566 SessionFactor I org.hibernate.impl.SessionFactoryObjectFactory Factory name: java:comp/HibernateSessionFactory [10/11/07 10:07:33:961 EDT] 75667566 NamingHelper I org.hibernate.util.NamingHelper JNDI InitialContext properties:{} [10/11/07 10:07:33:961 EDT] 75667566 SessionFactor I org.hibernate.impl.SessionFactoryObjectFactory Bound factory to JNDI name: java:comp/HibernateSessionFactory [10/11/07 10:07:33:961 EDT] 75667566 SessionFactor W org.hibernate.impl.SessionFactoryObjectFactory InitialContext did not implement EventContext[10/11/07 10:08:31:814 EDT] 75667566 SystemOut O !!!Error from HibernateUserDAO.setUserBean :save is not valid without active transaction
That error ir a bit of a red herring. Hibernate reports that error when the context used does not implement javax.naming.event.EventContext. All this will do is prevent Hibernate registering a naming listener, Hibernate itself should be working fine.
It soulds like Hibernate cannot look up JTA. Does WebSphere bind this in JNDI at java:comp/UserTransaction ? My memory is that in 5.1. it does not. JNDI in WebSphere is awkward full stop; again I remember that you needed to bootstrap some IBM classes unless you were running in an IBM JVM. I'm a bit hazy here - you might ask someone in the WebSphere forum to help?
Yep you always have to start a transaction when you open a Session.
Transaction transaction = session.getTransaction(); or was that Transaction transaction = session.beginTransaction();
They have to go hand in hand. a one to one relationship. And you have to make sure you commit your transaction when you want Hibernate to go to the database, when you are done (Well not exactly all the time, but for starting off we will say that). or rollback your transaction if an exception occurs.
transaction.commit(); or transaction.rollback(); Mark
>They have to go hand in hand. a one to one relationship. And you have to make sure you commit your transaction when you want Hibernate to go to the database, when you are done (Well not exactly all the time, but for starting off we will say that). or rollback your transaction if an exception occurs.
>transaction.commit(); or transaction.rollback();
My code works without using jndi for the transaction: