This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have been facing an issue with the find() method of the EntityManager(EJB 3.0). I have an entity bean which has composite primary key. When i try to find an object with the primary key the find() method of the EntityManager returns null. When i check the database the entity that i am searching for exists. The user with which i am creating the entity in the DB is the same as the user with which i am searching for it. Can anybody let me know whether i am missing anything? Is there something incorrect that i am doing? The code works fine when i have entity beans without composite primary keys. Its a Java SE application. The entity bean and its corresponding primary key class are as shown below:
I don't know if it's the reason of your problem, but you must have all your annotations either in the attributes or in the getter methods. You cannot mix. Either you put the @EmbededId annotation before the pk attribute or put the @Column annotation before the getDatbis() method.
Joined: Jan 17, 2006
I tried to put all the annotations in the attributes and then i tried putting them before the getter methods but both these solutions dont seem to work. I still get null from the find() method.
Joined: Feb 29, 2008
When you set the date in the pk using pk.setDatab(new Date()), you're setting the current date. Is it the exactly date that's stored in the database? (Considering hours, minutes and seconds)
You can configure the log to show the SQL query that's being executed, and then check which values it's using in the parameters. If it's hibernate, add the following to the persistence.xml