we use the jpacontainer 2.0 with eclipselink and postgres.
I need to know, how i get the generated id from an new created item after calling jpacontainer.commit()?
I supposed that the item will be updated after commit with the generated id, but the id is still 0 and item.isPersistent() returns false.
Are you trying to get it from the new container item or from the entity that you added? If you try to get it from an entity that you’ve added with addEntity(), you need to get the persisted entity from the container using the item ID that you get with addEntity().
Hmm, ok i have try it, but the JPAContainer does not know the generated UUID. After some investigation i have found the function clear() in BufferdeContainerDelegate. This function delets all known items from the JPAContainer. And this function will be called at the end of
commit() ;
So, if i called
getItem() with the UUID after the commit(), the cache is empty and the result is an Exception: “You have provided an instance of an incorrect PK class for this find operation. Class expected : class java.lang.Long, Class received : class java.util.UUID.”
maybe a little bit too late, but maybe others are interested in the answer as well. When you are using JPAContainer with a buffered entity provider (such as CachingBatchableLocalEntityProvider - which is the default one, I think), you get back an UUID as Item-ID from the JPAContainer, as long as you do not do a commit on the container. After that you have to use the ID given by the database to retrieve your EntityItem again.