-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: CascadeType.ALL ignored
PostPosted: Fri Apr 22, 2005 9:08 am 
Newbie

Joined: Fri Apr 22, 2005 8:40 am
Posts: 3
The cascade = CascadeType.ALL annotation parameter seems to be ignored, what am I doing wrong?

I want the following two java classes make persistent. As you see, the expected 'on delete cascade' clause in the foreign key constraint is missing in the generated sql script.

After debugging I realised, that the flag for generating 'on delete cascade' is always set to false.

Code:
package de.gabo.converter.common.data.rackdesign;

import javax.persistence.*;
import java.util.Set;

@Entity(access = AccessType.PROPERTY)
@Table(name = "HBMTESTPARENT")
public class HbmTestParent
{
    Long m_Id;
    String m_aParentField;

    Set<HbmTestChild> m_children;

    @Id
    public Long getId()
    {
        return m_Id;
    }

    public void setId(Long id_)
    {
        m_Id = id_;
    }

    public String getaParentField()
    {
        return m_aParentField;
    }

    public void setaParentField(String aParentField_)
    {
        m_aParentField = aParentField_;
    }

    @OneToMany( cascade = CascadeType.ALL)
    @JoinColumn(name="HBMTESTPARENT_ID")
    public Set<HbmTestChild> getChildren()
    {
        return m_children;
    }

    public void setChildren(Set<HbmTestChild> children_)
    {
        m_children = children_;
    }
}


Code:
package de.gabo.converter.common.data.rackdesign;

import javax.persistence.*;

@Entity(access = AccessType.PROPERTY)
@Table(name = "HBMTESTCHILD")
public class HbmTestChild
{
    Long m_Id;
    String m_aChildFild;

    HbmTestParent m_parent;

    @Id
    public Long getId()
    {
        return m_Id;
    }

    public void setId(Long id_)
    {
        m_Id = id_;
    }

    public String getaChildFild()
    {
        return m_aChildFild;
    }

    public void setaChildFild(String childFild_)
    {
        m_aChildFild = childFild_;
    }

    @ManyToOne( cascade = CascadeType.ALL, optional = false)
    @JoinColumn(name="HBMTESTPARENT_ID")
    public HbmTestParent getParent()
    {
        return m_parent;
    }

    public void setParent(HbmTestParent parent_)
    {
        m_parent = parent_;
    }
}


Code:
Method

    setCascadeDeleteEnabled(boolean cascadeDeleteEnabled):void of class org.hibernate.mapping.SimpleValue

Found usages ( 5 usages in 3 files )

    org.hibernate.cfg ( in D:\work\converter\src\converter\trunk\3rdparty\hibernate-annotations\src ) ( 1 usage in 1 file )

        AnnotationBinder.java ( 1 usage )

            (406, 8) key.setCascadeDeleteEnabled(false);

    org.hibernate.cfg ( in D:\work\converter\src\converter\trunk\3rdparty\hibernate\src ) ( 3 usages in 1 file )

        HbmBinder.java ( 3 usages )

            (789, 7) key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );

            (844, 7) key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );

            (1990, 9) key.setCascadeDeleteEnabled( "cascade"

    org.hibernate.cfg.annotations ( in D:\work\converter\src\converter\trunk\3rdparty\hibernate-annotations\src ) ( 1 usage in 1 file )

        EntityBinder.java ( 1 usage )

            (339, 7) key.setCascadeDeleteEnabled(false);



Hibernate version:
3.0.1.,
hibernate-annotations: 3.0beta1

Mapping documents:
NA (see annotations)

Code between sessionFactory.openSession() and session.close():
NA

Full stack trace of any exception that occurs:
NA

Name and version of the database you are using:
Oracle 8i

The generated SQL (show_sql=true):
drop table HBMTESTCHILD cascade constraints;
drop table HBMTESTPARENT cascade constraints;

create table HBMTESTCHILD (
id number(19,0) not null,
aChildFild varchar2(255),
HBMTESTPARENT_ID number(19,0) not null,
primary key (id)
);
create table HBMTESTPARENT (
id number(19,0) not null,
aParentField varchar2(255),
primary key (id)
);

alter table HBMTESTCHILD add constraint FK66F76A779F5BFA6A foreign key (HBMTESTPARENT_ID) references HBMTESTPARENT;

Debug level Hibernate log excerpt:
- Hibernate 3.0.1
- hibernate.properties not found
- using CGLIB reflection optimizer
- using JDK 1.4 java.sql.Timestamp handling
- configuring from resource: hibernate/configuration.xml
- Configuration resource: hibernate/configuration.xml
- Mapping resource: hibernate\DCapStage.xml
- Mapping class: de.gabo.converter.common.data.DCapStage -> CON_CAPSTAGE
- Mapping resource: hibernate\DEventLogEntry.xml
- Mapping class: de.gabo.converter.common.data.DEventLogEntry -> CON_EVENT_LOG
- Mapping resource: hibernate\DOrder.xml
- Mapping class: de.gabo.converter.common.data.DOrder -> CON_ORDER
- Mapping resource: hibernate\DSoiBaseRecord.xml
- Mapping class: de.gabo.converter.common.data.soi.DSoiBaseRecord -> CON_SOI_RECORD
- Mapping resource: hibernate\DSoiData.xml
- Mapping class: de.gabo.converter.common.data.soi.DSoiData -> CON_SOI_HEADER_DATA
- Mapping class using metadata: de.gabo.converter.common.data.rackdesign.DEquipment
- Mapping class using metadata: de.gabo.converter.common.data.rackdesign.DFuse
- Mapping class using metadata: de.gabo.converter.common.data.rackdesign.DRackDesign
- Mapping class using metadata: de.gabo.converter.common.data.rackdesign.DWire
- Mapping class using metadata:
de.gabo.converter.common.data.rackdesign.HbmTestChild
- Mapping class using metadata: de.gabo.converter.common.data.rackdesign.HbmTestParent
- Configured SessionFactory: null
- Using dialect: org.hibernate.dialect.OracleDialect
- processing extends queue
- processing collection mappings
- Mapping collection: de.gabo.converter.common.data.soi.DSoiData.m_listSoiRecords -> CON_SOI_RECORD
- Mapping collection: de.gabo.converter.common.data.rackdesign.DEquipment.fuseList -> CON_FUSE
- Mapping collection: de.gabo.converter.common.data.rackdesign.DEquipment.wireList -> CON_WIRE
- Mapping collection: de.gabo.converter.common.data.rackdesign.DRackDesign.m_equipmentList -> CON_EQUIPMENT
- Mapping collection: de.gabo.converter.common.data.rackdesign.HbmTestParent.children -> HBMTESTCHILD
- processing association property references
- processing foreign key constraints
- processing extends queue
- processing collection mappings
- processing association property references
- processing foreign key constraints
- Running hbm2ddl schema export
- writing generated schema to file: ./schema-export.sql
- exporting generated schema to database
- Using Hibernate built-in connection pool (not for production use!)
- Hibernate connection pool size: 20
- autocommit mode: false
- using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:@marathon:1521:COMET
- connection properties: {user=con_dev_tor, password=****}
- schema export complete
- cleaning up connection pool: jdbc:oracle:thin:@marathon:1521:COMET

Code:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 11:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
CascadeType.ALL or cascade="all" in hbm does not mean 'on delete cascade'. You can't enable on delete cascade right now through annotations. Contribution welcome :-)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.