Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » complex merge fails with IntegrityConstraintException <SOLVED>
complex merge fails with IntegrityConstraintException <SOLVED> [message #1774647] Wed, 18 October 2017 10:18
Christian Eugster is currently offline Christian EugsterFriend
Messages: 142
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
After further analysis, I see, that the exception comes not from the merge I do but from another that is done before removing (the unmerged) tectonics entity. Sorry about that and thanks!

Hi
I have an interesting problem:

A parent entity (table) named tectonics that holds a list of tectonics_levels
A level entity that holds a list of tectonics levels
An entity tectonics_level that holds a reference to the parent tectonics and parent level entities.
and an entity tectonics_level_link, that links to a parent and child tectonics_levels to connect two tectonics_levels as parent, child respective.

When I try to merge the tectonics entity, that holds two tectonics_levels, which each of them references a different level and the tectonics_levels are linked via a tectonics_level_link entity (and non of them is already in the database), I get a integrity constraint exception due to a duplicate entry for one of the level's (unique) name.

With other words:

The tectonics entity has a name (say TEST) and a list of tectonics_levels.
One level entity has a (unique) name attribute (say Archive) and a tectonics_level list.
The other level entity has a (unique) name attribute (say Department) and a tectonics_level list
Each of these levels contains a single tectonics_level entity, that references the level (and is an entry in the respective list) and references the tectonics entity (where it is also an entry in the list).
One of the two tectonics_levels references the level entity Archive, the other references the level entity Department.
Another entity of type tectonics_level_link has a parent_tectonics_level (pointing to level Archive) and a child_tectonics_level (pointing to level Department).

the stack trace looks like:

[EL Warning]: 2017-10-18 11:50:06.244--UnitOfWork(2124261761)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'Department' for key 'level_name'
Error Code: 1062
Call: INSERT INTO herakles_level (level_id, level_deleted, level_image, level_inserted, level_name, level_predefined_level, level_updated, level_version, level_user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [9 parameters bound]
Query: InsertObjectQuery(ch.eugster.herakles.persistence.jpa.model.JpaLevel@149f5761)
[EL Warning]: 2017-10-18 11:50:06.269--UnitOfWork(233343686)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'Department' for key 'level_name'
Error Code: 1062
Call: INSERT INTO herakles_level (level_id, level_deleted, level_image, level_inserted, level_name, level_predefined_level, level_updated, level_version, level_user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [9 parameters bound]
Query: InsertObjectQuery(ch.eugster.herakles.persistence.jpa.model.JpaLevel@149f5761)

But I have only one level with name Department created. Can anybody give me a hint whats going wrong here (what I am doing wrong)?

The interfaces (to spare place) of the entities:

public interface Tectonics extends Entity, Nameable
{
void addTectonicsLevel(TectonicsLevel tectonicsLevel);
void removeTectonicsLevel(TectonicsLevel tectonicsLevel);
TectonicsLevel[] getTectonicsLevels();
TectonicsLevel[] getChildTectonicsLevels();
}

public interface Level extends Entity
{
String getName();
PredefinedLevel getPredefinedLevel();
void setImage(Image image);
Image getImage();
void addTectonicsLevel(TectonicsLevel tectonicsLevel);
void removeTectonicsLevel(TectonicsLevel tectonicsLevel);
TectonicsLevel[] getTectonicsLevels();
TectonicsLevel getTectonicsLevel(Tectonics tectonics);
}

public interface TectonicsLevel extends Entity
{
Tectonics getTectonics();
Level getLevel();
void addParentTectonicsLevelLink(TectonicsLevelLink tectonicsLevelLink);
void removeParentTectonicsLevelLink(TectonicsLevelLink tectonicsLevelLink);
TectonicsLevelLink[] getParentTectonicsLevelLinks();
void addChildTectonicsLevelLink(TectonicsLevelLink tectonicsLevelLink);
void removeChildTectonicsLevelLink(TectonicsLevelLink tectonicsLevelLink);
TectonicsLevelLink[] getChildTectonicsLevelLinks();
boolean containsChildTectonicsLevelLinkToLevel(Level level);
}

public interface TectonicsLevelLink extends Entity
{
TectonicsLevel getParentTectonicsLevel();
TectonicsLevel getChildTectonicsLevel();
}
Any help is appreciated!

Christian

[Updated on: Wed, 18 October 2017 11:21]

Report message to a moderator

Previous Topic:Multi tenancy with schema per tenant
Next Topic:how to write DDL sql for create table in Eclipselink JPA
Goto Forum:
  


Current Time: Mon Dec 11 00:28:09 GMT 2017

Powered by FUDForum. Page generated in 0.01753 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software