Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

JPAContainer- how to get the id of commited item

Andre Peters
1 decade ago Feb 24, 2012 7:40am
Marko Grönroos
1 decade ago Mar 01, 2012 1:20pm
Andre Peters
1 decade ago Mar 02, 2012 9:40am
Victor Röder
8 years ago Jun 05, 2014 7:29am

Hello Andre,

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.


JPAContainer<Contact> contactContainer = JPAContainerFactory.make(...);

Contact contact = new Contact();

UUID uuid = (UUID) contactContainer.addEntity(contact);

EntityItem<Contact> contactEntityItem = contactContainer.getItem(uuid); // use UUID to retrieve the EntityItem

contactContainer.commit(); // *now* the entity item is persisted to the db

EntityItem<Contact> item2 = contactContainer.getItem(contact.getId()); // *now* we have to use the ID of the database 

Hope this helps,

Kim Zeevaarders
8 years ago Jun 06, 2014 8:32am