Figured it out - I didn't understand the semantics of "Supports" - switching it to "Required" fixes the issue.
Thanks for the patience to anyone who reads this and thinks RTM :)
I am obviously slower than you so could you please explain what you fixed to get this to work? I am using jboss 4 and hibernate 3. Here is what I try:
sessionFactory = new Configuration().configure().buildSessionFactory();
s = sessionFactory.getCurrentSession();
I get the error thtat Unable to locate current JTA transaction at ....getCurrentSession
I see that you are calling getSession(with jndi) instead of getCurrentSession(), why?
The call that I am making is the same as getCurrentSession(); I had just written this code before I was aware of that method. I have since switched to calling getCurrentSession().
To fix this code, I changed the transactionality of the EJB from Supports to type="Required" - supports indicates that if a transaction already exists, I will take part in it, required creates a transaction if one does not already exist, but if one exists, it simply joins it.
If you use getCurrentSession, you must require a transaction exists.
I hope that helps!
I was trying to get around using EJB's but I may be forced to. I want to use just pojo's but I can't seem to get things up and running fully. Have you always used EJB? From all that I have read it seems that I should be able to use just pojo and dao pattern but the question is ??????
Yes, you can use POJO and dao pattern, which I've done most of the time with my Hibernate work. However, if you do that, then consider using springs "HibernateDaoSupport" instead of getCurrentSession for session management. You cannot use getCurrentSession unless you or the container has set up a JTA Transaction.
I hope that helps!
Thanks for the response and I started looking at Spring but have not downloaded it yet. We do have JTA configured in our hibernate-service.xml and Jboss does support it so I believe I can go that route and not add another layer (Spring)? Our debug says we are getting a JTA transaction but we changed our code to use session.get() and openSession. getCurrentSession kept throwing up an error that no transaction existed. It looks as if all is going well but our query does not return any rows. It should return 1.
Do you by chance have a quick configuration for installing and setting up spring. I am currently using hibernate 3, jboss 4, struts and sybase 12.5? I have a hibernate.cfg.xml and a hiberante-service.xml. If it is a 5 minutes thing then that might be a viable solution. What does Spring do exactly?
In the event you might be able to email me some samples: email@example.com