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.m...@gmail.com>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.nordw...@gmail.com> 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@lists.sourceforge.net
>> >> 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@lists.sourceforge.net
>> 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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Reply via email to