According to the annotation @OnDelete(DeletePolicy.DENY) this message is shown when you try to delete an instance which has a non-null value in the numbermask field. Moreover, you have made the field mandatory, so it cannot be null. Please check it.
I find solution in documentation. I use @OnDeleteInverse annotations and @OneToMany(mappedBy = "DocTypes")
annotations in numbermask entity, but I have to use soft deleted mechanism. Is there any way to use mechanism base
on foreign key ?
Referential integrity on the database level (foreign keys) cannot prevent from soft deletion by definition: soft deletion does not delete records from the database. This is why we need these annotations for soft-deleted entities.
Ok, but when I switch of soft delete mechanism I give a message like below, when
I delete record. I expect then in this case I give message
e.g "Can't delete record because there is relation to other position
com.haulmont.cuba.core.global.RemoteException:
---
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.2.cuba23): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The DELETE statement conflicted with the REFERENCE constraint "FK_RENTAL_ARTICLES_GROUPID". The conflict occurred in database "rental", table "dbo.RENTAL_ARTICLES", column 'GROUPID_ID'.
Error Code: 547
Call: DELETE FROM RENTAL_GROUP WHERE ((ID = ?) AND (VERSION = ?))
bind => [201, 1]
Query: DeleteObjectQuery(com.company.rental.entity.Group-201 [managed,removed])
---
javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.2.cuba23): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The DELETE statement conflicted with the REFERENCE constraint "FK_RENTAL_ARTICLES_GROUPID". The conflict occurred in database "rental", table "dbo.RENTAL_ARTICLES", column 'GROUPID_ID'.
Error Code: 547
Call: DELETE FROM RENTAL_GROUP WHERE ((ID = ?) AND (VERSION = ?))
bind => [201, 1]
Query: DeleteObjectQuery(com.company.rental.entity.Group-201 [managed,removed])
---
org.eclipse.persistence.exceptions.DatabaseException:
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The DELETE statement conflicted with the REFERENCE constraint "FK_RENTAL_ARTICLES_GROUPID". The conflict occurred in database "rental", table "dbo.RENTAL_ARTICLES", column 'GROUPID_ID'.
Error Code: 547
Call: DELETE FROM RENTAL_GROUP WHERE ((ID = ?) AND (VERSION = ?))
bind => [201, 1]
Query: DeleteObjectQuery(com.company.rental.entity.Group-201 [detached,removed])