-->
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.  [ 12 posts ] 
Author Message
 Post subject: Hibernate silently ignoring rows
PostPosted: Fri Feb 23, 2007 1:26 pm 
Newbie

Joined: Fri Feb 23, 2007 12:50 pm
Posts: 7
I know I'm breaking most of the rules, as I'm hoping that I can get a bit of help before I start completely deconstructing the database schema.

The issue is that I have a very simple query:
Query q = session.createQuery("from com.example.Table");
List result = q.list();

And I'm not getting all the rows I should be getting.

Specifically, if I'm getting the first 9 rows and not the 10th one:
Query q = session.createQuery("from com.example.Table where id=1");
List result = q.list();
would get me the proper row while
Query q = session.createQuery("from com.example.Table where id=10");
List result = q.list();
would return an empty set.

The most surprising thing is that the Debug logs for those two queries are identical, I cannot find any mention that a row was returned and dropped. I have tested the SQL query that is generated in both cases and each returns the proper row.

The rows are there with the command-line client, so I don't see any reason why the rows would be dropped silently.

The two complicating factors right now is that this happens with somewhat long tables with various relations. I haven't started to make a copy of the database and cut it down into pieces to see how it fails exactly.

This is also data that was recently added and there is a possibility that some of it was not entered properly, but all key constraints are respected. No matter the error, I don't see why Hibernate would ignore rows silently.

Short of someone magically knowing the answer (or even the cause) for this problem, I would appreciate hints as to where in the Hibernate code should I be putting additional debug statements to get a better idea of what is happening.

Please tell me if (and which) more details are needed.

Francois

Hibernate version: 3.2

Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using: MySQL 4.1.20

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: POst the code
PostPosted: Sat Feb 24, 2007 2:35 pm 
Newbie

Joined: Mon Feb 19, 2007 12:54 am
Posts: 16
Location: banglore, india
Can u ppost me the code

_________________
Banglore Developer


Top
 Profile  
 
 Post subject: sample code
PostPosted: Sun Feb 25, 2007 3:23 pm 
Newbie

Joined: Fri Feb 23, 2007 12:50 pm
Posts: 7
I've changed the class name and we're more explicit in the configuration, but the code should be equivalent. The table is kind of complex (20 columns) and has key contraints to another table. IDs 496 and 497 are chosen because all id<=496 work and all >=497 are ignored.

This happens on several (but not all) of our tables, some of which do not share any relations with each other.

Code:
sessionFactory = new Configuration().configure().buildSessionFactory();
Session sess=sessionFactory.openSession();

Query q = sess.createQuery("from com.example.MA where maid=497");
List result=q.list();
System.out.println(result.size()); //0

q = sess.createQuery("from com.example.MA where maid=496");
result=q.list();
System.out.println(result.size()); //1



In SQL:
Code:
mysql> select maid from MA where maid=496 or maid=497;
+------+
| maid |
+------+
|  496 |
|  497 |
+------+
2 rows in set (0.01 sec)


An interesting test is duplicating those two rows:
Code:
mysql> create temporary table temp like MA;
mysql> insert into temp select * from MA where maid=496 or maid=497;
mysql> update temp set maid=maid+1000;
mysql> insert into MA select * from temp;
mysql> select maid from MA where maid=1496 or maid=1497;
+------+
| maid |
+------+
| 1496 |
| 1497 |
+------+
2 rows in set (0.00 sec)


And then they are both ignored in hibernate:
Code:
q = sess.createQuery("from com.example.MA where maid>1000");
result=q.list();
System.out.println(result.size()); //0


Interestingly, the only way I can predict which rows will be ignored in any tables by when they've been added. All recent additions have are being ignored, which would seem to point to a weird interaction between mysql and hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 11:51 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi

i would recommand to use alias in from com.example.MA ma where ma.maid=497. and second thing that check that you have commited your changes in DB or not .Have you used Ehcache, then you have to wait till expire

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 12:09 pm 
Newbie

Joined: Fri Feb 23, 2007 12:50 pm
Posts: 7
The alias doesn't change anything in the result of the queries.

I don't think it could be a transaction. The rows have been committed properly. I ended up restarting the database when I was investigating this, so any uncommitted changes would have disappeared if that was the problem.

As for the caching, I tried it with several sessions as well as setting
Code:
sess.setCacheMode(CacheMode.IGNORE);

They all give me exactly the same results. If there is another way I should be checking, I'd be happy to try.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 12:15 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
hi lanceur,

set log4J.property for Hibernate and check all the binding value to query.Try to execute Hibernate generated SQl if this return result and you are not getting then it might be problem in your code

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 11:55 am 
Newbie

Joined: Fri Feb 23, 2007 12:50 pm
Posts: 7
I had done that at the very beginning and the SQL that is generated is working fine. I also have the same result when I use direct SQL queries and I can ask for the whole table and only the first half of the table gets returned.

Francois


Top
 Profile  
 
 Post subject: Do this
PostPosted: Thu Mar 01, 2007 2:34 am 
Newbie

Joined: Mon Feb 19, 2007 12:54 am
Posts: 16
Location: banglore, india
Try dto do the operation in transaction boundaries and check.

1. Did u mapped the maid column of table to the maid column of bean.

Check this once.

_________________
Banglore Developer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 4:37 pm 
Newbie

Joined: Fri Feb 23, 2007 12:50 pm
Posts: 7
Doing this inside of a transaction changes nothing.

yes, the MaID column is present as in the hibernate mapping, although we're not using beans.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 5:10 pm 
Newbie

Joined: Mon Mar 05, 2007 4:58 pm
Posts: 4
Are you using Hibernate to insert the values in the table? If so, make sure you flush before you do a SELECT if you're not using the same Session.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 6:03 pm 
Newbie

Joined: Fri Feb 23, 2007 12:50 pm
Posts: 7
No, the first values were already there and the others were insert using the command-line client.

As I mentioned, there was a restart of the database betwen the insertion and the querying, so I'm confident this is not a transaction issue.

Francois


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 5:36 pm 
Newbie

Joined: Fri Feb 23, 2007 12:50 pm
Posts: 7
Sorry and thanks for those who have tried to help.

There was a problem with my configuration that connected to an older database instead. Hibernate is working just as advertised.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.