Monday, May 27, 2013

Netbeans entity - EclipseLink: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails

I was getting this error:

Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`bismarksi/orders`, CONSTRAINT `FK_Orders_CLIENTID` FOREIGN KEY (`CLIENTID`) REFERENCES `clients` (`ID`))Error Code: 1452Call: INSERT INTO Orders (ID, CLIENTID, MODIFIEDDATE, ORDERSTATUSID, PROJECTID, RECEIPTDATE, SELLERID) VALUES (?, ?, ?, ?, ?, ?, ?)bind => [7 parameters bound]Query: InsertObjectQuery(com.expertix.bismark.si.entities.Order[ id=1 , projectId=1 , orderStatusId=1  ])

I solved the error adding to the entity the set and get method for the clientId Attribute:

   public int getClientId() {
        return clientId;
    }

    public void setClientId(int clientId) {
        this.clientId = clientId;
    }


No comments: