How to persist an aggregation relation where the related dependency was persited before?

Hello Bonita Community:

In my process I have defined some business variable called project of type Project, this class has some basic attributes and one particular attribute from another object defined (BDM) from class Client (this relationship was marked as aggregation ). A client object has 2 attributes and one in particular must be unique, so when I’m creating a new Project with a new Client there are no problems on do that, but when the client was previously persisted it throws an org.bonitasoft.engine.exception.BonitaRuntimeException, in particular org.hibernate.exception.ConstraintViolationException: could not execute statement, because previously I defined an Unique Constraint to the Client BDM.

My code to create the new Project and retrieve the existent client is:

import com.company.model.Client
import com.company.model.ClientDAO
import com.company.model.Project
import com.company.model.ProjectDAO

Client client = clientDAO.findByUniqueID(projectInput.client.clientUniqueID)
if( client == null )
{
client = clientDAO.newInstance(projectInput.client.name, projectInput.client.clientUniqueID)
}

return new Project(projectInput.projectUniqueID, projectInput.name, client)

If you have some clue on what or where is the problem your answer will be very helpful to solve my headache!!!

thanks in advance