Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.2
Mapping documents: yes
Code between sessionFactory.openSession() and session.close():
Used both Entity Manager and Hibernate Session
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MySQL
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
I used EntityManager to persist the objects and then used Session from SessionFactory to query the saved data. The problem (I am not sure if this is a problem or intended behavior) is that when I query right after the EM persist call, I don't get the data, yet the data shows up in MySQL using Query Browser. After executing the same query using the session, I got the data randomly (when I got it, it is correct). If I restart Tomcat, then I can see the persisted data consistently. So I am wondering if there is some kind of delay (caching) between EM and Session? The part I don't understand is that why I would see the data (hit and miss) when I make the same call? Is certain function I didn't set up properly that caused this problem?
Edit: BTW, I tried persisting using the session instead of EM and the result is the same (has the delay).
The criteria based query (which hit and miss randomly) looks like this:
List<Object[]> results = session.createCriteria(Rating.class)
.createAlias("topic", "t")
.add(Restrictions.eq("campaign.id", campaignId))
.add(Restrictions.eq("target.id", targetId))
.addOrder(Order.desc("createTime"))
.addOrder(Order.desc("userId"))
.addOrder(Order.desc("t.index"))
.list();
Any explanation is welcome. Thanks!