JPAContainer + Hibernate + CRUD table -> duplicate key

Hi there,

we are trying to implement a CRUD table with Vaadin using JPAContainer+Hibernate, all the CRUD funcionality seems fine during the first session, but once we restart the application server, if we try to change one of the objects, we get a duplicate key exception.

We have seen that hibernate tries to update the entity (without issue) and then tries to insert it again, giving an exception an rolling back the transaction.

Hibernate: update ServicePeople set responsibleFunction=? where autoId=? and instance_insta
nceId=? and person_peopleEmail=?

Hibernate: insert into ServicePeople (responsibleFunction, autoId, instance_instanceId, person_peopleEmail) values (?, ?, ?, ?)

mar 04, 2014 6:08:54 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions

WARN: SQL Error: 1062, SQLState: 23000

mar 04, 2014 6:08:54 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions

ERROR: Duplicate entry 'be25efb2-da8c-4ec6-a821-21a4c3942b6e-i-0ecd9642-xxx.yyyy@roc' for key 'PRIMARY'

The code we use for the table and the JPAContainer is:

private void buildTeamsTable() {

teams = JPAContainerFactory.make(ServicePeople.class, "com.servicepeople.jpa");
teamsTable.setContainerDataSource(teams);
teamsTable.setSelectable(true);

// Build button bar for teams
final Button editTeamsButton = new Button("Edit Teams");
editTeamsButton.addClickListener( new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if ( teamsTable.isEditable() ) {
teamsTable.setEditable(false);
editTeamsButton.setCaption("Edit Teams");
} else {
teamsTable.setEditable(true);
editTeamsButton.setCaption("Save changes");
}
}
});
teamsButtonsLayout.addComponent(editTeamsButton);

Adding new registers to the table works fine, but again, if we restart the application server, we cannot modify them.

Any ideas?

Many thanks
Jordi

Hello there,

just to let you know that we found the issue…

The issue was caused by the cascade options of the involved entities.
Blocking cascade (with cascade={}) in some of them fixed the issue.

Just in case somebody find this useful…