简体   繁体   中英

Getting referential integrity constraint violation while trying to delete from OneToMany relation with cascadeType.ALL in hibernate

This is the relevant code for the table I'm deleting from:

/**
     * Liste der Aufgaben der Abgabe
     */
    @Setter
    @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    @JoinTable(
            name = "ABGABEAUFGABENZUORDNUNG",
            joinColumns = {@JoinColumn(name = "ABGABE")},
            inverseJoinColumns = {@JoinColumn(name = "AUFGABE")}
    )
    private List<Aufgabe> aufgaben = new ArrayList<>();

These are my hibernate functions for deleting and updating:

@Override
    public void update(Abgabe abgabe) throws NullPointerException {
        HibernateUtil.execute(s -> s.update(abgabe));
    }

    @Override
    public void delete(Abgabe abgabe) {
        HibernateUtil.execute(s -> s.delete(abgabe));
    }

These are my tables:

CREATE TABLE `Abgabe` (
                          `id` INT NOT NULL AUTO_INCREMENT,
                          `name` varchar(255) NOT NULL UNIQUE,
                          `gewicht` FLOAT NOT NULL,
                          `date` SMALLDATETIME NOT NULL UNIQUE,
                          `gruppenAbgabe` BOOLEAN,
                          `bewertet` BOOLEAN,
                          `kommentar` varchar(1000),
                          PRIMARY KEY (`id`)
);

CREATE TABLE `Aufgabe` (
                           `id` INT NOT NULL AUTO_INCREMENT,
                           `oberaufgabe_Id` INT,
                           `name` VARCHAR(255) NOT NULL,
                           `maxPunkte` FLOAT,
                           `maxPunkteMitGewicht` FLOAT,
                           `gewicht` FLOAT NOT NULL,
                           `bewertungskriterien` VARCHAR(255),
                           PRIMARY KEY (`id`)
);

CREATE TABLE `AbgabeAufgabenZuordnung` (
                                           `abgabe` INT NOT NULL,
                                           `aufgabe` INT NOT NULL
);

now when I try to delete a aufgabe from a abgabe I get this exception:

Caused by: org.hibernate.MappingException: Could not determine type for: de.unibremen.swp.model.benotung.Abgabe, at table: BEWERTETEABGABE, for columns: [org.hibernate.mapping.Column(ABGABE)]

I've seen other questions asked here where the answer was to use Cascade=CascadeType.ALl but this is not working for me.

This is not a runtime error "during delete" but a bootstrap error. Your model is not correctly mapped, but I can't help you unless you share your whole entity model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM