Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Entity automatically getting Detached and failing on insert for integrity constrain(Entity automatically getting Detached and failing on insert for integrity constrain)
Entity automatically getting Detached and failing on insert for integrity constrain [message #1731267] Wed, 04 May 2016 04:58
Prashant Saraf is currently offline Prashant SarafFriend
Messages: 10
Registered: February 2015
Junior Member
Same Topic is also posted on

http://stackoverflow.com/questions/37018740/eclipselink-detaching-entity-and-performing-insert-for-existing-entity


I have following M-M relationship scenario

Employee and Project are connected with each other by EmployeeProjectRlsp

I have below Relationship defined

In Employee

@OneToMany(mappedBy = "employee", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private List<EmployeeProjectRlsp> employeeProjectRlsp;

In Project
@OneToMany(mappedBy = "project", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private List<EmployeeProjectRlsp> employeeProjectRlsp;


In EmployeeProjectRlsp
// bi-directional many-to-one association to Agreement
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "EMPLOYEE_ID", nullable = false)
private Employee employee;

// bi-directional many-to-one association to Category
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "PROJECT_ID", nullable = false)
private Project project;


Now issue : We are doing persist for each employee we have everything as cascade. Here requirement is if Project is not there in DB then create new Project

Coding is doing something like below

Project dbProject = projectDAO.getProject(xmlProject);
if(dbProject != null)
xmlProject = dbProject;
EmployeeProjectRlsp employeeProjectRlsp = emproRlspFactory.getEmployeeProjectRlsp(xmlProject, xmlEmployee);
xmlEmploye.setEmployeeProjectRlsp(employeeProjectRlsp);
employeDao.persist(xmlEmploye);

when I run above code in single thread environment everything works fine. when I am having 100 thread coming in same time I am getting integrity constrain on Project Object where project is saved days back.

I have all the Entities and their relationship marked with cascade

cascade = { CascadeType.PERSIST, CascadeType.MERGE }

Now this issue of integrity constrain coming to any of existing object coming from DB by either egar/lezy fetch or DAO call its keep failing at random places.

Can someone help me here what need to be done.
Previous Topic:CacheCoordination with synchronization type INVALIDATE_CHANGED_OBJECTS issues
Next Topic:[moxy] Marshalling empty collection as absent elements for XML
Goto Forum:
  


Current Time: Sun Mar 29 22:29:33 GMT 2020

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

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

Back to the top