cancel
Showing results for 
Search instead for 
Did you mean: 

Referential integrity violated in ManyToMany EJB

Former Member
0 Kudos

Referential integrity violated in ManyToMany EJB

Iu2019m using EJB 3 in NWCE 7.1 with entity beans. In a ManyToMany association the Server seems to first delete the main entity and after tries to delete the entry of the join table, which causes a violation of the foreign key on the join table. If I remove the foreign key from the table all works correctly!

Caused by: com.sap.dbtech.jdbc.exceptions.DatabaseException: [350]: Referential integrity violated:FK_USER2GROUP_USER,SP1DB,UM_USER2GROUP at com.sap.dbtech.jdbc.packet.ReplyPacket.createException(ReplyPacket.java:64) at com.sap.dbtech.jdbc.ConnectionSapDB.throwSQLError(ConnectionSapDB.java:959) at com.sap.dbtech.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:597) at com.sap.dbtech.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:465) at com.sap.dbtech.jdbc.CallableStatementSapDB.execute(CallableStatementSapDB.java:443) at com.sap.dbtech.jdbc.CallableStatementSapDB.execute(CallableStatementSapDB.java:315) at com.sap.dbtech.jdbc.CallableStatementSapDB.executeUpdate(CallableStatementSapDB.java:769) at com.sap.dbtech.jdbc.trace.PreparedStatement.executeUpdate(PreparedStatement.java:81) at com.sap.engine.services.dbpool.wrappers.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:279) at com.sap.engine.services.orpersistence.core.StoreManager.executeStatement(StoreManager.java:653) at com.sap.engine.services.orpersistence.core.StoreManager.removeEntity(StoreManager.java:572) at com.sap.engine.services.orpersistence.core.PersistenceContextImpl.flush(PersistenceContextImpl.java:284)

I donu2019t need any cascade and cascading doesn't solve the problem (tried it already). I've got a User object which contains a list of Group objects. The Group object doesn't contain any users and adding the User list would cause performance problems:


@Entity
@Table(name = "UM_USER")
public class User implements Serializable {
...

    /**
     * Returns the groups property
     * 
     * @return the groups property
     */
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "UM_USER2GROUP", joinColumns = { @JoinColumn(name = "FK_USER_ID",
    referencedColumnName = "ID") }, inverseJoinColumns = { @JoinColumn(name = "FK_GROUP_NAME",
    referencedColumnName = "NAME") })
    public List<Group> getGroups() {
        return groups;
    }
...
}

The User entity is persisted in the following two tables:


CREATE TABLE UM_USER
(
	ID VARCHAR(64) NOT NULL PRIMARY KEY,
	LOGIN VARCHAR(255),
	ACCOUNT_TYPE VARCHAR(32),
	CONSTRAINT UNQ_USER_LOGIN UNIQUE(LOGIN)
);

CREATE TABLE UM_USER2GROUP
(
	FK_USER_ID VARCHAR(64) NOT NULL,
	FK_GROUP_NAME VARCHAR(128) NOT NULL,
	PRIMARY KEY(FK_USER_ID, FK_GROUP_NAME),
	CONSTRAINT FK_USER2GROUP_USER FOREIGN KEY(FK_USER_ID) REFERENCES UM_USER(ID),
	CONSTRAINT FK_USER2GROUP_GROUP FOREIGN KEY(FK_GROUP_NAME) REFERENCES UM_GROUP(NAME)
);

Is there a way to get this running on NetWeaver CE 7.1 without having to remove the foreign keys?

Regards,

Tarik

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member185086
Active Contributor
0 Kudos

Hi

Referential integrity violated Problem comes when Problem with association with Primary Key and Foreign Key relationship.

So I think references are not consistent

Best Regards

Satish Kumar

Former Member
0 Kudos

Hi Tarik,

I think foreign keys with SAP JPA implementation are not well supported.

Former Member
0 Kudos

Thank you.. Yes, seems so... Iu2019m now just using indexes instead.