Fornax-Platform
Forum

Hiberanate Cascade Delete Issue in many to many relationship

View: New views
11 Messages — Rating Filter:   Alert me  

Hiberanate Cascade Delete Issue in many to many relationship

by arpan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

We have a many to many relationship defined as follows in model.design:

 

abstract Entity First  {

aggregateRoot

reference Set<@Second> second

      Repository FirstRepository {

            findById;

            save;

            delete;

}

    }

 

ValueObject Second {

cache

immutable

Repository SecondRepository {

            findById;

}

    }

   

All the Hibernate, EJB and Spring layers are generated/override and working properly.

It creates 3 tables in Oracle DB: First (id as the primary key), Second (id as the primary key) and Second_First (first and second combined as primary key).

We explicitly added one Cascade Delete constrain in the SECOND_FIRST table directly in DB

 

CREATE TABLE SECOND_FIRST

   (            "SECOND" NUMBER(20,0) NOT NULL ENABLE,

                "FIRST" NUMBER(20,0) NOT NULL ENABLE,

                 CONSTRAINT "PK_SECOND_FIRST" PRIMARY KEY ("SECOND", "FIRST")

  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)

  TABLESPACE "USERS"  ENABLE,

                 CONSTRAINT "FK_SECOND_FIRST_SECOND" FOREIGN KEY ("SECOND")

                  REFERENCES “SECOND" ("ID") ENABLE,

                 CONSTRAINT "FK_SECOND_FIRST_FIRST" FOREIGN KEY ("FIRST")

                  REFERENCES "FIRST" ("ID") ON DELETE CASCADE ENABLE

   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)

  TABLESPACE "USERS" ;

 

There are no Cascade delete option set for SECOND table.

 

But when using the delete repository function of First Entity (firstRepository.delete(id);), it is getting following exception:

 

19:12:04,223 INFO  [STDOUT] Hibernate: delete from SECOND_FIRST where FIRST=?

19:12:04,254 INFO  [STDOUT] Hibernate: delete from SECOND where id=? and version=?

19:12:04,551 WARN  [JDBCExceptionReporter] SQL Error: 2292, SQLState: 23000

19:12:04,551 ERROR [JDBCExceptionReporter] ORA-02292: integrity constraint (PTPUSER.FK_THIRD_SECOND) violated - child record found

 

19:12:04,551 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session

org.hibernate.exception.ConstraintViolationException: could not delete: [com.my.services.new.domain.Second#100]

        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)

        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

        at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2541)

 

You can see it is generating the delete statement for Second table also. But should not be generated. While running directly in db (delete from first where id=?) it is deleting properly in first and second_first table. It is rightly not trying to delete second table.

 

I have tried with putting db.oracle.onDeleteCascade=true properties in sculptor-generator.properties, but getting the same result.

 

Any clue why it is behaving like this? Or is there anything I’m missing?

 

 

--
Regards,

Arpan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: Hiberanate Cascade Delete Issue in many to many relationship

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have to look at this in more detail, but in the mean time you can read up on the following annotation and try if it helps adding it (if it is missing in the generated code).

@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)

I think the meaning is that this annotation tells hibernate that it should not delete, since it is done by the database, but look in the hibernate documentation to make sure.

Let me know if any progress.

/Patrik


arpan wrote:
We have a many to many relationship defined as follows in model.design:



*abstract* *Entity* First  {

*aggregateRoot*

reference *Set*<@Second> second

      *Repository* FirstRepository {

            findById;

            save;

            delete;

}

    }



*ValueObject* Second {

*cache*

*immutable*

*Repository* SecondRepository {

            findById;

}

    }



All the Hibernate, EJB and Spring layers are generated/override and working
properly.

It creates 3 tables in Oracle DB: First (id as the primary key), Second (id
as the primary key) and Second_First (first and second combined as primary
key).

We explicitly added one Cascade Delete constrain in the *SECOND_FIRST* table
directly in DB



*CREATE TABLE SECOND_FIRST *

*   (            "SECOND" NUMBER(20,0) NOT NULL ENABLE, *

*                "FIRST" NUMBER(20,0) NOT NULL ENABLE, *

*                 CONSTRAINT "PK_SECOND_FIRST" PRIMARY KEY ("SECOND",
"FIRST")*

*  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 *

*  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*

*  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*

*  TABLESPACE "USERS"  ENABLE, *

*                 CONSTRAINT "FK_SECOND_FIRST_SECOND" FOREIGN KEY ("SECOND")
*

*                  REFERENCES “SECOND" ("ID") ENABLE, *

*                ** CONSTRAINT "FK_SECOND_FIRST_FIRST" FOREIGN KEY ("FIRST")
*

*                  REFERENCES "FIRST" ("ID") ON DELETE CASCADE ENABLE*

*   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*

*  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*

*  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*

*  TABLESPACE "USERS" ;*



There are no Cascade delete option set for SECOND table.



But when using the delete repository function of First Entity
(firstRepository.delete(id);), it is getting following exception:



19:12:04,223 INFO  [STDOUT] Hibernate: delete from SECOND_FIRST where
FIRST=?

*19:12:04,254 INFO  [STDOUT] Hibernate: delete from SECOND where id=? and
version=?*

19:12:04,551 WARN  [JDBCExceptionReporter] SQL Error: 2292, SQLState: 23000

19:12:04,551 ERROR [JDBCExceptionReporter] ORA-02292: integrity constraint
(PTPUSER.FK_THIRD_SECOND) violated - child record found



19:12:04,551 ERROR [AbstractFlushingEventListener] Could not synchronize
database state with session

org.hibernate.exception.ConstraintViolationException: could not delete:
[com.my.services.new.domain.Second#100]

        at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)

        at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

        at
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2541)





You can see it is generating the delete statement for Second table also. But
should not be generated. While running directly in db (delete from first
where id=?) it is deleting properly in first and second_first table. It is
rightly not trying to delete second table.



I have tried with putting db.oracle.onDeleteCascade=true properties in
sculptor-generator.properties, but getting the same result.



Any clue why it is behaving like this? Or is there anything I’m missing?




--
Regards,

Arpan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: Hiberanate Cascade Delete Issue in many to many relationship

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I noticed one thing. The constraint that is failing is named FK_THIRD_SECOND. Is there another association also?

/P


I have to look at this in more detail, but in the mean time you can read up on the following annotation and try if it helps adding it (if it is missing in the generated code).

@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)

I think the meaning is that this annotation tells hibernate that it should not delete, since it is done by the database, but look in the hibernate documentation to make sure.

Let me know if any progress.

/Patrik


arpan wrote:
We have a many to many relationship defined as follows in model.design:



*abstract* *Entity* First  {

*aggregateRoot*

reference *Set*<@Second> second

      *Repository* FirstRepository {

            findById;

            save;

            delete;

}

    }



*ValueObject* Second {

*cache*

*immutable*

*Repository* SecondRepository {

            findById;

}

    }



All the Hibernate, EJB and Spring layers are generated/override and working
properly.

It creates 3 tables in Oracle DB: First (id as the primary key), Second (id
as the primary key) and Second_First (first and second combined as primary
key).

We explicitly added one Cascade Delete constrain in the *SECOND_FIRST* table
directly in DB



*CREATE TABLE SECOND_FIRST *

*   (            "SECOND" NUMBER(20,0) NOT NULL ENABLE, *

*                "FIRST" NUMBER(20,0) NOT NULL ENABLE, *

*                 CONSTRAINT "PK_SECOND_FIRST" PRIMARY KEY ("SECOND",
"FIRST")*

*  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 *

*  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*

*  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*

*  TABLESPACE "USERS"  ENABLE, *

*                 CONSTRAINT "FK_SECOND_FIRST_SECOND" FOREIGN KEY ("SECOND")
*

*                  REFERENCES “SECOND" ("ID") ENABLE, *

*                ** CONSTRAINT "FK_SECOND_FIRST_FIRST" FOREIGN KEY ("FIRST")
*

*                  REFERENCES "FIRST" ("ID") ON DELETE CASCADE ENABLE*

*   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*

*  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*

*  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*

*  TABLESPACE "USERS" ;*



There are no Cascade delete option set for SECOND table.



But when using the delete repository function of First Entity
(firstRepository.delete(id);), it is getting following exception:



19:12:04,223 INFO  [STDOUT] Hibernate: delete from SECOND_FIRST where
FIRST=?

*19:12:04,254 INFO  [STDOUT] Hibernate: delete from SECOND where id=? and
version=?*

19:12:04,551 WARN  [JDBCExceptionReporter] SQL Error: 2292, SQLState: 23000

19:12:04,551 ERROR [JDBCExceptionReporter] ORA-02292: integrity constraint
(PTPUSER.FK_THIRD_SECOND) violated - child record found



19:12:04,551 ERROR [AbstractFlushingEventListener] Could not synchronize
database state with session

org.hibernate.exception.ConstraintViolationException: could not delete:
[com.my.services.new.domain.Second#100]

        at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)

        at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

        at
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2541)





You can see it is generating the delete statement for Second table also. But
should not be generated. While running directly in db (delete from first
where id=?) it is deleting properly in first and second_first table. It is
rightly not trying to delete second table.



I have tried with putting db.oracle.onDeleteCascade=true properties in
sculptor-generator.properties, but getting the same result.



Any clue why it is behaving like this? Or is there anything I’m missing?




--
Regards,

Arpan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fornax-developer


Re: Hiberanate Cascade Delete Issue in many to many relationship

by arpan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, there are many other table which refers Second table as foreign key.
But the delete statement on Second should not be generated (while deleting on First table).


On Wed, Oct 28, 2009 at 2:21 AM, Patrik Nordwall <patrik.nordwall@...> wrote:

I noticed one thing. The constraint that is failing is named FK_THIRD_SECOND.
Is there another association also?

/P


Patrik Nordwall wrote:
>
> I have to look at this in more detail, but in the mean time you can read
> up on the following annotation and try if it helps adding it (if it is
> missing in the generated code).
>
> @org.hibernate.annotations.OnDelete(action =
> org.hibernate.annotations.OnDeleteAction.CASCADE)
>
> I think the meaning is that this annotation tells hibernate that it should
> not delete, since it is done by the database, but look in the hibernate
> documentation to make sure.
>
> Let me know if any progress.
>
> /Patrik
>
>
>
> arpan wrote:
>>
>> We have a many to many relationship defined as follows in model.design:
>>
>>
>>
>> *abstract* *Entity* First  {
>>
>> *aggregateRoot*
>>
>> reference *Set*<@Second> second
>>
>>       *Repository* FirstRepository {
>>
>>             findById;
>>
>>             save;
>>
>>             delete;
>>
>> }
>>
>>     }
>>
>>
>>
>> *ValueObject* Second {
>>
>> *cache*
>>
>> *immutable*
>>
>> *Repository* SecondRepository {
>>
>>             findById;
>>
>> }
>>
>>     }
>>
>>
>>
>> All the Hibernate, EJB and Spring layers are generated/override and
>> working
>> properly.
>>
>> It creates 3 tables in Oracle DB: First (id as the primary key), Second
>> (id
>> as the primary key) and Second_First (first and second combined as
>> primary
>> key).
>>
>> We explicitly added one Cascade Delete constrain in the *SECOND_FIRST*
>> table
>> directly in DB
>>
>>
>>
>> *CREATE TABLE SECOND_FIRST *
>>
>> *   (            "SECOND" NUMBER(20,0) NOT NULL ENABLE, *
>>
>> *                "FIRST" NUMBER(20,0) NOT NULL ENABLE, *
>>
>> *                 CONSTRAINT "PK_SECOND_FIRST" PRIMARY KEY ("SECOND",
>> "FIRST")*
>>
>> *  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 *
>>
>> *  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*
>>
>> *  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*
>>
>> *  TABLESPACE "USERS"  ENABLE, *
>>
>> *                 CONSTRAINT "FK_SECOND_FIRST_SECOND" FOREIGN KEY
>> ("SECOND")
>> *
>>
>> *                  REFERENCES “SECOND" ("ID") ENABLE, *
>>
>> *                ** CONSTRAINT "FK_SECOND_FIRST_FIRST" FOREIGN KEY
>> ("FIRST")
>> *
>>
>> *                  REFERENCES "FIRST" ("ID") ON DELETE CASCADE ENABLE*
>>
>> *   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
>>
>> *  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*
>>
>> *  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*
>>
>> *  TABLESPACE "USERS" ;*
>>
>>
>>
>> There are no Cascade delete option set for SECOND table.
>>
>>
>>
>> But when using the delete repository function of First Entity
>> (firstRepository.delete(id);), it is getting following exception:
>>
>>
>>
>> 19:12:04,223 INFO  [STDOUT] Hibernate: delete from SECOND_FIRST where
>> FIRST=?
>>
>> *19:12:04,254 INFO  [STDOUT] Hibernate: delete from SECOND where id=? and
>> version=?*
>>
>> 19:12:04,551 WARN  [JDBCExceptionReporter] SQL Error: 2292, SQLState:
>> 23000
>>
>> 19:12:04,551 ERROR [JDBCExceptionReporter] ORA-02292: integrity
>> constraint
>> (PTPUSER.FK_THIRD_SECOND) violated - child record found
>>
>>
>>
>> 19:12:04,551 ERROR [AbstractFlushingEventListener] Could not synchronize
>> database state with session
>>
>> org.hibernate.exception.ConstraintViolationException: could not delete:
>> [com.my.services.new.domain.Second#100]
>>
>>         at
>> org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
>>
>>         at
>> org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
>>
>>         at
>> org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2541)
>>
>> …
>>
>>
>>
>> You can see it is generating the delete statement for Second table also.
>> But
>> should not be generated. While running directly in db (delete from first
>> where id=?) it is deleting properly in first and second_first table. It
>> is
>> rightly not trying to delete second table.
>>
>>
>>
>> I have tried with putting db.oracle.onDeleteCascade=true properties in
>> sculptor-generator.properties, but getting the same result.
>>
>>
>>
>> Any clue why it is behaving like this? Or is there anything I’m missing?
>>
>>
>>
>>
>> --
>> Regards,
>>
>> Arpan
>>
>> ------------------------------------------------------------------------------
>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>> is the only developer event you need to attend this year. Jumpstart your
>> developing skills, take BlackBerry mobile applications to market and stay
>> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>> http://p.sf.net/sfu/devconference
>> _______________________________________________
>> Fornax-developer mailing list
>> Fornax-developer@...
>> https://lists.sourceforge.net/lists/listinfo/fornax-developer
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Hiberanate-Cascade-Delete-Issue-in-many-to-many-relationship-tp26080397s17564p26084849.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer



--
Regards,

Arpan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: Hiberanate Cascade Delete Issue in many to many relationship

by arpan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oh!
it is getting solved by putting cascade="none"

reference Set<@Second> second cascade="none"

I dont know why it is automatically generating delete orphan script in hibernate.


On Wed, Oct 28, 2009 at 5:26 PM, Arpan Mukherjee <arpan.mukh@...> wrote:
Yes, there are many other table which refers Second table as foreign key.
But the delete statement on Second should not be generated (while deleting on First table).



On Wed, Oct 28, 2009 at 2:21 AM, Patrik Nordwall <patrik.nordwall@...> wrote:

I noticed one thing. The constraint that is failing is named FK_THIRD_SECOND.
Is there another association also?

/P


Patrik Nordwall wrote:
>
> I have to look at this in more detail, but in the mean time you can read
> up on the following annotation and try if it helps adding it (if it is
> missing in the generated code).
>
> @org.hibernate.annotations.OnDelete(action =
> org.hibernate.annotations.OnDeleteAction.CASCADE)
>
> I think the meaning is that this annotation tells hibernate that it should
> not delete, since it is done by the database, but look in the hibernate
> documentation to make sure.
>
> Let me know if any progress.
>
> /Patrik
>
>
>
> arpan wrote:
>>
>> We have a many to many relationship defined as follows in model.design:
>>
>>
>>
>> *abstract* *Entity* First  {
>>
>> *aggregateRoot*
>>
>> reference *Set*<@Second> second
>>
>>       *Repository* FirstRepository {
>>
>>             findById;
>>
>>             save;
>>
>>             delete;
>>
>> }
>>
>>     }
>>
>>
>>
>> *ValueObject* Second {
>>
>> *cache*
>>
>> *immutable*
>>
>> *Repository* SecondRepository {
>>
>>             findById;
>>
>> }
>>
>>     }
>>
>>
>>
>> All the Hibernate, EJB and Spring layers are generated/override and
>> working
>> properly.
>>
>> It creates 3 tables in Oracle DB: First (id as the primary key), Second
>> (id
>> as the primary key) and Second_First (first and second combined as
>> primary
>> key).
>>
>> We explicitly added one Cascade Delete constrain in the *SECOND_FIRST*
>> table
>> directly in DB
>>
>>
>>
>> *CREATE TABLE SECOND_FIRST *
>>
>> *   (            "SECOND" NUMBER(20,0) NOT NULL ENABLE, *
>>
>> *                "FIRST" NUMBER(20,0) NOT NULL ENABLE, *
>>
>> *                 CONSTRAINT "PK_SECOND_FIRST" PRIMARY KEY ("SECOND",
>> "FIRST")*
>>
>> *  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 *
>>
>> *  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*
>>
>> *  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*
>>
>> *  TABLESPACE "USERS"  ENABLE, *
>>
>> *                 CONSTRAINT "FK_SECOND_FIRST_SECOND" FOREIGN KEY
>> ("SECOND")
>> *
>>
>> *                  REFERENCES “SECOND" ("ID") ENABLE, *
>>
>> *                ** CONSTRAINT "FK_SECOND_FIRST_FIRST" FOREIGN KEY
>> ("FIRST")
>> *
>>
>> *                  REFERENCES "FIRST" ("ID") ON DELETE CASCADE ENABLE*
>>
>> *   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
>>
>> *  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645*
>>
>> *  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)*
>>
>> *  TABLESPACE "USERS" ;*
>>
>>
>>
>> There are no Cascade delete option set for SECOND table.
>>
>>
>>
>> But when using the delete repository function of First Entity
>> (firstRepository.delete(id);), it is getting following exception:
>>
>>
>>
>> 19:12:04,223 INFO  [STDOUT] Hibernate: delete from SECOND_FIRST where
>> FIRST=?
>>
>> *19:12:04,254 INFO  [STDOUT] Hibernate: delete from SECOND where id=? and
>> version=?*
>>
>> 19:12:04,551 WARN  [JDBCExceptionReporter] SQL Error: 2292, SQLState:
>> 23000
>>
>> 19:12:04,551 ERROR [JDBCExceptionReporter] ORA-02292: integrity
>> constraint
>> (PTPUSER.FK_THIRD_SECOND) violated - child record found
>>
>>
>>
>> 19:12:04,551 ERROR [AbstractFlushingEventListener] Could not synchronize
>> database state with session
>>
>> org.hibernate.exception.ConstraintViolationException: could not delete:
>> [com.my.services.new.domain.Second#100]
>>
>>         at
>> org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
>>
>>         at
>> org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
>>
>>         at
>> org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2541)
>>
>> …
>>
>>
>>
>> You can see it is generating the delete statement for Second table also.
>> But
>> should not be generated. While running directly in db (delete from first
>> where id=?) it is deleting properly in first and second_first table. It
>> is
>> rightly not trying to delete second table.
>>
>>
>>
>> I have tried with putting db.oracle.onDeleteCascade=true properties in
>> sculptor-generator.properties, but getting the same result.
>>
>>
>>
>> Any clue why it is behaving like this? Or is there anything I’m missing?
>>
>>
>>
>>
>> --
>> Regards,
>>
>> Arpan
>>
>> ------------------------------------------------------------------------------
>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>> is the only developer event you need to attend this year. Jumpstart your
>> developing skills, take BlackBerry mobile applications to market and stay
>> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>> http://p.sf.net/sfu/devconference
>> _______________________________________________
>> Fornax-developer mailing list
>> Fornax-developer@...
>> https://lists.sourceforge.net/lists/listinfo/fornax-developer
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Hiberanate-Cascade-Delete-Issue-in-many-to-many-relationship-tp26080397s17564p26084849.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer



--
Regards,

Arpan



--
Regards,

Arpan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: Hiberanate Cascade Delete Issue in many to many relationship

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Aha, that was a little bit to simple :-)

But, do you mean that the generated annotation is all-delete-orphan for this case.
I will have to look at then, it feels wrong.

The default values are documented here:
http://fornax.itemis.de/confluence/display/fornax/3.+Advanced+Tutorial+(CSC)#3.AdvancedTutorial(CSC)-CascadeandFetch

/Patrik

Re: Hiberanate Cascade Delete Issue in many to many relationship

by arpan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For many to many relationship, it is creating all-delete-orphan automatically.
If Table1 has reference Set<@Table2> table2
It is creating Table2_Table1 lookup table and putting delete orphan in hibernate for Table2.

But it is not always true that Table2 will be child of Table1 right?


On Wed, Oct 28, 2009 at 8:10 PM, Patrik Nordwall <patrik.nordwall@...> wrote:

Aha, that was a little bit to simple :-)

But, do you mean that the generated annotation is all-delete-orphan for this
case.
I will have to look at then, it feels wrong.

The default values are documented here:
http://fornax.itemis.de/confluence/display/fornax/3.+Advanced+Tutorial+(CSC)#3.AdvancedTutorial(CSC)-CascadeandFetch

/Patrik
--
View this message in context: http://www.nabble.com/Hiberanate-Cascade-Delete-Issue-in-many-to-many-relationship-tp26080397s17564p26095863.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer



--
Regards,

Arpan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: Hiberanate Cascade Delete Issue in many to many relationship

by PaloT :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, we need information if relation is "association" or
"aggregation". I will need this kind of information also in
smartclient. For now I'm recognizing it by existence of service. If
service exist (it is independent entity) than it's association,
otherwise is aggregation. Is here some better way how to recognize
type of relation?

Pavel


On Thu, Oct 29, 2009 at 7:07 AM, Arpan Mukherjee <arpan.mukh@...> wrote:

> For many to many relationship, it is creating all-delete-orphan
> automatically.
> If Table1 has reference Set<@Table2> table2
> It is creating Table2_Table1 lookup table and putting delete orphan in
> hibernate for Table2.
>
> But it is not always true that Table2 will be child of Table1 right?
>
>
> On Wed, Oct 28, 2009 at 8:10 PM, Patrik Nordwall <patrik.nordwall@...>
> wrote:
>>
>> Aha, that was a little bit to simple :-)
>>
>> But, do you mean that the generated annotation is all-delete-orphan for
>> this
>> case.
>> I will have to look at then, it feels wrong.
>>
>> The default values are documented here:
>>
>> http://fornax.itemis.de/confluence/display/fornax/3.+Advanced+Tutorial+(CSC)#3.AdvancedTutorial(CSC)-CascadeandFetch
>>
>> /Patrik
>> --
>> View this message in context:
>> http://www.nabble.com/Hiberanate-Cascade-Delete-Issue-in-many-to-many-relationship-tp26080397s17564p26095863.html
>> Sent from the Fornax-Platform mailing list archive at Nabble.com.
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>> is the only developer event you need to attend this year. Jumpstart your
>> developing skills, take BlackBerry mobile applications to market and stay
>> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>> http://p.sf.net/sfu/devconference
>> _______________________________________________
>> Fornax-developer mailing list
>> Fornax-developer@...
>> https://lists.sourceforge.net/lists/listinfo/fornax-developer
>
>
>
> --
> Regards,
>
> Arpan
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Fornax-developer mailing list
> Fornax-developer@...
> https://lists.sourceforge.net/lists/listinfo/fornax-developer
>
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: Hiberanate Cascade Delete Issue in many to many relationship

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The original idea was to use the DDD concept for aggregate, as described briefly here.

You can define 'not aggregateRoot' on an Entity to indicate that it belongs to a parent aggregate.

Maybe that is not enough. Maybe we should make it possible to define aggregation on reference also.

/Patrik


PaloT wrote:
Yes, we need information if relation is "association" or
"aggregation". I will need this kind of information also in
smartclient. For now I'm recognizing it by existence of service. If
service exist (it is independent entity) than it's association,
otherwise is aggregation. Is here some better way how to recognize
type of relation?

Pavel

Re: Hiberanate Cascade Delete Issue in many to many relationship

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have added CSC-439 for the aggregation reference type. I don't think we will make it in 1.7.0.

I have also extracted the default cascade values to generator properties, i.e. you can define the default cascade value in your sculptor-generator.properties. This is documented in Developer's Guide. I suggest that you use persist,merge if you don't like the delete to be propagated.

/Patrik



The original idea was to use the DDD concept for aggregate, as described briefly here.

You can define 'not aggregateRoot' on an Entity to indicate that it belongs to a parent aggregate.

Maybe that is not enough. Maybe we should make it possible to define aggregation on reference also.

/Patrik


PaloT wrote:
Yes, we need information if relation is "association" or
"aggregation". I will need this kind of information also in
smartclient. For now I'm recognizing it by existence of service. If
service exist (it is independent entity) than it's association,
otherwise is aggregation. Is here some better way how to recognize
type of relation?

Pavel


[Closed] Re: Hiberanate Cascade Delete Issue in many to many relationship

by arpan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Patrik!

On Sat, Oct 31, 2009 at 4:24 AM, Patrik Nordwall <patrik.nordwall@...> wrote:

I have added  http://fornax.itemis.de/jira/browse/CSC-439 CSC-439  for the
aggregation reference type. I don't think we will make it in 1.7.0.

I have also extracted the default cascade values to generator properties,
i.e. you can define the default cascade value in your
sculptor-generator.properties. This is documented in
http://fornax.itemis.de/confluence/display/fornax/7.+Developer%27s+Guide+%28CSC%29#7.Developer%27sGuide%28CSC%29-Cascade
Developer's Guide . I suggest that you use persist,merge if you don't like
the delete to be propagated.

/Patrik



Patrik Nordwall wrote:
>
> The original idea was to use the DDD concept for aggregate, as described
> briefly
> http://fornax.itemis.de/confluence/display/fornax/3.+Advanced+Tutorial+(CSC)#3.AdvancedTutorial(CSC)-Aggregate
> here .
>
> You can define 'not aggregateRoot' on an Entity to indicate that it
> belongs to a parent aggregate.
>
> Maybe that is not enough. Maybe we should make it possible to define
> aggregation on reference also.
>
> /Patrik
>
>
>
> PaloT wrote:
>>
>> Yes, we need information if relation is "association" or
>> "aggregation". I will need this kind of information also in
>> smartclient. For now I'm recognizing it by existence of service. If
>> service exist (it is independent entity) than it's association,
>> otherwise is aggregation. Is here some better way how to recognize
>> type of relation?
>>
>> Pavel
>>
>
>

--
View this message in context: http://old.nabble.com/Hiberanate-Cascade-Delete-Issue-in-many-to-many-relationship-tp26080397s17564p26138020.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer



--
Regards,

Arpan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer