These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Please help - data not being picked up until server restart
PostPosted: Wed Jul 23, 2008 6:39 am 
Newbie

Joined: Wed Jul 23, 2008 6:19 am
Posts: 4
Hello all,

I am new to Hibernate and have a seemingly simple issue - I have been googling all morning but can't sort it out. Sorry if it is an obvious question.

The issue is:
1) Using JDBC, I insert a row into a table.
2) Using Hibernate in a separate transaction, I then try to access the row. I can see in the MySQL log that Hibernate is hitting the database and the SQL is perfect - if I run the same query it retrieves the row. *However*, the List object I am getting back from Hibernate contains no rows. When I restart the server (Tomcat), then the row is retrieved fine.

Any thoughts?

Below is some more information:
- I am using Hibernate 3 with Spring 2.0.8, using <code>org.springframework.orm.hibernate3.LocalSessionFactoryBean</code>
- I have 'switched off' the second-level cache using <code><property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property></code>
- I have tried manually flushing the session before running the query, but it doesn't make any difference.
- The only suspicious message in the log is one that says:
"org.hibernate.impl.SessionImpl - setting flush mode to: NEVER".

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 3:26 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Could we see your mappings?

Make sure the collection is being accessed within an active session, and if not, then have the collection loaded in an eagar, not lazy, fashion.

I've got a little tutorial on the topic with some very simple examples.



Here's the code that loads and saved the one to many objects from the database. You might want to use something similar:


Hibernate Tutorial: Working with One To Many Relationships

Code:
Session session = HibernateUtil.beginTransaction();
Team team = new Team();
Player p1 = new Player();
Player p2 = new Player();
session.save(team);
session.save(p1);
session.save(p2);
team.setName("Pickering Atoms");
p1.setNickName("Lefty");
p1.setTeam(team);
p2.setNickName("Blinky");
p2.setTeam(team);
HibernateUtil.commitTransaction();



Hibernate Tutorial: Working with One To Many Relationships

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Problem solved - I think!
PostPosted: Fri Jul 25, 2008 10:18 am 
Newbie

Joined: Wed Jul 23, 2008 6:19 am
Posts: 4
Thanks for your suggestions.

I have been fighting with this all day and think I have found the solution. I went back through my Spring books and saw that they were passing the datasource to the sessionFactory in the applicationContext.

Code below:
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <!-- ADDED THIS PROPERTY: -->
  <property name="dataSource"><ref bean="dataSource" /></property>
  <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>


This code was originally generated by MyEclipse so I didn't think I would need to change it.

I have been repeatedly taking the line above out and putting it back and have been able to replicate the problem repeatedly so I am pretty sure it is the cause of the problem.

Thanks again for your help - it is much appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.