Ok, I'm trying to do a ManyToMany relationship between a Role entity and a Task entity, the MySQL schema and dummy data is:
Which leaves me with a bi-directional relationship like this: role <- roletask -> task
Now, on my java entities, the Role is the owner, as I'm gonna be adding tasks to a certain Role, so, the definition of Role is:
And for the Task entity, I'm defining this:
Now, when I get a Role from a session bean using the method: Role role = em.find(Role.class, new BigDecimal(1)); and then, when using the getter in Role for taskList, the taskList only has one item instead of the five defined in the database!
I'm using a code like this somewhere else and it works as it should, but here it's not working, I'm using eclipselink with glassfish 3.1.2 and, on the persistence.xml, I enabled the generated SQL log, and this is what eclipselink is executing when fetching the taskList:
So it looks like it's running two queries for fetching the objects, and the first one, when I run it in MySQL it fetches all tasks correctly, but the second one only fetches the first one, now, I don't know why is running two queries for this, but I know that the one that I actually get on my entity objects is the second one which is wrong, instead of the first one which is correct.
Is there something wrong with my code? or what am I doing wrong to fetch my taskList and get the data I'm supposed to get?
Actually, on an act of despair, I updated my JDK to jdk 7 update 11, and suddenly it started working again, I was using update 5, and I dunno what was going on, but now that I updated, everything's working as it should.
It would be good to have more time to research on what happened and why the issue, but for now it works and I can get the job done.
The only thing is that I was getting an exception on the glassfish log stating that it wasn't able to load the DataSourceSpec class on startup, and I didn't review the glassfish log until after the update, so I didn't know that glassfish was failing before. Is just one of those really weird bugs.