I try everything that i know, the cascade attribute setup on both the mappings with the value of delete, and nothing, this is the error that its throws..
ERROR: update or delete on "estudiante" violates foreign key constraint on estudiante_profesor
DETAIL key(solapin_e)=(12454) is still referenced from table estudiante_profesor
so, when i check de source code for the generated data base, and more especificaly for the link table i found this:
CREATE TABLE "public"."estudiante_profesor" (
"solapin_p" INTEGER NOT NULL,
"solapin_e" INTEGER NOT NULL,
CONSTRAINT "estudiante_profesor_pkey" PRIMARY KEY("solapin_e", "solapin_p"),
CONSTRAINT "solapin_e" FOREIGN KEY ("solapin_e")
REFERENCES "public"."profesor"("solapin_p")
ON DELETE NO ACTION
ON UPDATE NO ACTION
NOT DEFERRABLE,
CONSTRAINT "solapin_p" FOREIGN KEY ("solapin_p")
REFERENCES "public"."estudiante"("solapin_e")
ON DELETE NO ACTION
ON UPDATE NO ACTION
NOT DEFERRABLE
) WITHOUT OIDS;
like you can see, the actions on delete, on update are disabled, and i don't have any idea about it.
Making a summarize, hibernate is not generate te correct sentences of SQL that corresponding with my mappings, i don't know what, check the mappings files:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
this is the mapping for the bean Estudiante
<hibernate-mapping schema="public" package="beans">
<class name="Estudiante" table="estudiante" schema="public" optimistic-lock="none">
<id name="solapin_e" type="integer" unsaved-value="null" column="solapin_e">
<generator class="increment"/>
</id>
<property name="nombre" type="string" column="nombre"/>
<set name="profesores" table="estudiante_profesor" inverse="true" cascade="delete">
<key foreign-key="solapin_p" column="solapin_p"/>
<many-to-many entity-name="beans.Profesor" foreign-key="solapin_e" column="solapin_e"/>
</set>
</class>
</hibernate-mapping>
this is the mapping for the bean Profesor
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="public" package="beans">
<class name="Profesor" table="profesor" schema="public" optimistic-lock="none">
<id name="solapin_p" type="integer" unsaved-value="null" column="solapin_p">
<generator class="increment"/>
</id>
<property name="nombre" type="string" column="nombre"/>
<set name="estudiantes" table="estudiante_profesor" cascade="delete">
<key foreign-key="solapin_e" column="solapin_e"/>
<many-to-many entity-name="beans.Estudiante" foreign-key="solapin_p" column="solapin_p"/>
</set>
</class>
</hibernate-mapping>
and this is the hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/pp1</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.order_updates">true</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="beans/Estudiante.hbm.xml"/>
<mapping resource="beans/Profesor.hbm.xml"/>
</session-factory>
</hibernate-configuration>
WHAT DO YOU THINK???????
|