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.