Hi,
We are using spring and hibernate with mysql, we have 3 tables:
--------------------------
----------
----------
-----
CREATE TABLE PRODUCT_LINE (
product_line_id INTEGER UNSIGNED NOT NULL,
product_line_name VARCHAR(64) NULL,
PRIMARY KEY(product_line_id)
)
TYPE=InnoDB;
CREATE TABLE PRODUCT_FAMILY (
product_family_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
product_family_name VARCHAR(64) NULL,
PRIMARY KEY(product_family_id)
)
TYPE=InnoDB;
CREATE TABLE PRODUCTFAMILY_PRODUCTLINE_
LINK (
product_family_id INTEGER UNSIGNED NOT NULL,
product_line_id INTEGER UNSIGNED NOT NULL,
FOREIGN KEY(product_line_id)
REFERENCES PRODUCT_LINE(product_line_
id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY(product_family_id)
REFERENCES PRODUCT_FAMILY(product_fam
ily_id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
TYPE=InnoDB;
--------------------------
----------
----------
-----
In my .hbm files, we have:
<class name="com.pcn.persistence.
domain.Pro
ductFamily
" table="PRODUCT_FAMILY">
...
<set name="productLines" inverse="true" table="PRODUCTFAMILY_PRODU
CTLINE_LIN
K">
<key>
<column name="product_family_id" not-null="true" />
</key>
<many-to-many entity-name="com.pcn.persi
stence.dom
ain.Produc
tLine">
<column name="product_line_id" not-null="true" />
</many-to-many>
</set>
</class>
-----------------
<class name="com.pcn.persistence.
domain.Pro
ductLine" table="PRODUCT_LINE">
<set name="productFamilies" inverse="true" table="PRODUCTFAMILY_PRODU
CTLINE_LIN
K" cascade="merge,save-update
,delete" lazy="true">
<key>
<column name="product_line_id" not-null="true" />
</key>
<many-to-many entity-name="com.sun.pcn.p
ersistence
.domain.Pr
oductFamil
y" >
<column name="product_family_id" not-null="true" />
</many-to-many>
</set>
</class>
--------------------------
----------
----------
-----
so when I try to delete the link between and product_family and product_line, i do this:
ProductLine pl = session1.get(ProductLine .class, ProductLineId);
ProductFamily pf = getFromSomeWhere();
if (pl.getProductFamilies().c
ontains(pf
))
pl.ProductFamilies.remove(
pf);
session1.merge(pl);
--------------------------
----------
----------
-------
However, the link won't remove, the row in table "PRODUCTFAMILY_PRODUCTLINE
_LINK" still exist.
I want to keep the product_family and product_line and just remove the link, how can i do it??
Please help.
Joe
Start Free Trial