NULL value in the "key_" column of the "am_location" relation violates the NOT NULL constraint

79 Views Asked by At

I ran into the following problem: there is a “Copy” button in my interface, I have it implemented as follows:

    public void execute() {
        BaseUuidEntity entity = (BaseUuidEntity) metadata.getTools().deepCopy(target.getSingleSelected());
        entity.setId(UUID.randomUUID());
        screenBuilders.editor(target)
                .newEntity(entity)
                .build()
                .show();
    }

Implementation of the deepCopy() method from the platform itself:

    public <T extends Entity> T deepCopy(T source) {
        CachingEntitiesHolder entityFinder = new CachingEntitiesHolder();
        Entity destination = entityFinder.create(source.getClass(), source.getId());
        deepCopy(source, destination, entityFinder);

        return (T) destination;
    }

As you can see, I use the deepCopy() method to copy an entity, but it doesn’t always work correctly for me. For example, I have two entries: Main and Virtual warehouse. And when copying the Main warehouse, an errors occurs at the DB level: the NULL value in the “key_” column of the “am_location” relation violates the NOT NULL constraint. I debugged and seems I understand what the problem is: the refLocation attribute in the key column is assigned a null value. And in the Location table, I have a not null constraint on KEY. And probably therefore the copied entity is not saved. Screenshot from link enter image description here

I tried using the copy() method instead the deepCopy() method, but I started getting an IllegalStateException with unfetched attributes. Apparently the copy() method doesn’t suit me because I have nested collections for many entities and still deepCopy() method is more suitable, but it doesn’t work as it should.

I understand that I need my own implementation copy method?

0

There are 0 best solutions below