Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Cascade deletes causing not null constraint violations.
[Teneo] Cascade deletes causing not null constraint violations. [message #121555] Wed, 30 April 2008 19:19 Go to next message
Alex Black is currently offline Alex BlackFriend
Messages: 15
Registered: July 2009
Junior Member
Hello,
I'm having difficulty deleting child objects on a merge call. I have a
parent object, Lab, which contains a list of Contacts:

------------------------------------------------------------ ---------------------

<xsd:complexType name="Lab">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Entity
@Table(
name="LabTable"
)
</xsd:appinfo>
</xsd:annotation>

<xsd:sequence>

<!--lots of irrelevent stuff--->

<xsd:element maxOccurs="unbounded" minOccurs="0" name="contactList"
type="Contact">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@OneToMany(indexed=false)
@JoinColumn(name="LAB_SK", nullable=false)
</xsd:appinfo>
</xsd:annotation>
</xsd:element>

</xsd:sequence>

</xsd:complexType>



<xsd:complexType name="Contact">

<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Entity
@Table(
name="ContactTable"
)
</xsd:appinfo>
</xsd:annotation>

<xsd:sequence>

<xsd:element default="0" name="contactSK" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id
@GeneratedValue(strategy=SEQUENCE, generator="labSequence")
@Column(name=Contact_SK,nullable="false",updatable=false)
</xsd:appinfo>
</xsd:annotation>
</xsd:element>


<!--lots of irrelevent stuff--->


</xsd:sequence>
</xsd:complexType>

------------------------------------------------------------ ---------------------

The Lab is loaded by a client via a web service, so it is completely
serialized and deserialized before it comes back into the system as a
detatched object. The client has monkeyed with the data he pulled down, and
occasionally removes a contact from the contactList. To handle the incoming
changes, I'm using the hibernate merge method:


------------------------------------------------------------ ---------------------
//bunch of deserialization code

outputLab = (Lab)session.merge(inputLab)

//bunch of serialization code
------------------------------------------------------------ ---------------------

Beautifully simple, and works as advertised. My problem is that when
hibernate removes a row from the ContactTable, it nulls out the foreign key
first (summarized SQL):

------------------------------------------------------------ ---------------------

--bunch of selects
update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
delete from ContactTable where contact_sk=?

------------------------------------------------------------ ---------------------


This causes a foreign key not null constraint violation. I have "fixed" the
issue by asking the DBA to drop the not null constraints for the moment
(then repremanding myself sternly for even suggesting the idea), but would
like hibernate to please just delete the row without nulling it.

It appears that the standard hibernate way to do this is to add an
'inverse="true"' to the oneToMany:

http://forum.hibernate.org/viewtopic.php?p=2383090

but I can't figure out how to get a Teneo annotation to do that.

Any thoughts or ideas? Is this the right approach?

Thanks,

-Alex
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #121734 is a reply to message #121555] Fri, 02 May 2008 05:53 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Alex,
I am not sure that I understand the relational schema, but maybe I am missing something.

When removing the contact the following sql is executed:
> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
> delete from ContactTable where contact_sk=?

But why is there a contact_sk column in the LabTable as this is the table containing the Lab
instances? And why is it nulling the lab_sk while this is the pk of the LabTable (afaics).
As the Contact is contained by the Lab, I would expect a fk from ContactTable to LabTable.

gr. Martin

Alex Black wrote:
> Hello,
> I'm having difficulty deleting child objects on a merge call. I have a
> parent object, Lab, which contains a list of Contacts:
>
> ------------------------------------------------------------ ---------------------
>
> <xsd:complexType name="Lab">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Entity
> @Table(
> name="LabTable"
> )
> </xsd:appinfo>
> </xsd:annotation>
>
> <xsd:sequence>
>
> <!--lots of irrelevent stuff--->
>
> <xsd:element maxOccurs="unbounded" minOccurs="0" name="contactList"
> type="Contact">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @OneToMany(indexed=false)
> @JoinColumn(name="LAB_SK", nullable=false)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>

>
> </xsd:sequence>
>
> </xsd:complexType>
>
>
>
> <xsd:complexType name="Contact">
>
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Entity
> @Table(
> name="ContactTable"
> )
> </xsd:appinfo>
> </xsd:annotation>
>
> <xsd:sequence>
>
> <xsd:element default="0" name="contactSK" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id
> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
> @Column(name=Contact_SK,nullable="false",updatable=false)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
>
> <!--lots of irrelevent stuff--->
>
>
> </xsd:sequence>
> </xsd:complexType>
>
> ------------------------------------------------------------ ---------------------
>
> The Lab is loaded by a client via a web service, so it is completely
> serialized and deserialized before it comes back into the system as a
> detatched object. The client has monkeyed with the data he pulled down, and
> occasionally removes a contact from the contactList. To handle the incoming
> changes, I'm using the hibernate merge method:
>
>
> ------------------------------------------------------------ ---------------------
> //bunch of deserialization code
>
> outputLab = (Lab)session.merge(inputLab)
>
> //bunch of serialization code
> ------------------------------------------------------------ ---------------------
>
> Beautifully simple, and works as advertised. My problem is that when
> hibernate removes a row from the ContactTable, it nulls out the foreign key
> first (summarized SQL):
>
> ------------------------------------------------------------ ---------------------
>
> --bunch of selects
> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
> delete from ContactTable where contact_sk=?
>
> ------------------------------------------------------------ ---------------------
>
>
> This causes a foreign key not null constraint violation. I have "fixed" the
> issue by asking the DBA to drop the not null constraints for the moment
> (then repremanding myself sternly for even suggesting the idea), but would
> like hibernate to please just delete the row without nulling it.
>
> It appears that the standard hibernate way to do this is to add an
> 'inverse="true"' to the oneToMany:
>
> http://forum.hibernate.org/viewtopic.php?p=2383090
>
> but I can't figure out how to get a Teneo annotation to do that.
>
> Any thoughts or ideas? Is this the right approach?
>
> Thanks,
>
> -Alex
>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #121776 is a reply to message #121734] Fri, 02 May 2008 15:49 Go to previous messageGo to next message
Alex Black is currently offline Alex BlackFriend
Messages: 15
Registered: July 2009
Junior Member
Hi Martin,
I apologize, you are correct, when I translated the SQL from our own
incomprehensible table names I made a mistake, the summarized sql should
look like this:

update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
delete from ContactTable where contact_sk=?

The behavior I'd like is simply:

delete from ContactTable where contact_sk=?


The generated hibernate mapping for the list might help too:

<bag name="contactList" lazy="true" cascade="all,delete-orphan">
<key update="true" foreign-key="lab_contactlist">
<column name="lab_sk" not-null="true" unique="false"/>
</key>
<one-to-many entity-name="Contact"/>
</bag>


The hibernate discussion forums seem to say that adding 'inverse="true"':

<bag name="contactList" lazy="true" cascade="all,delete-orphan"
inverse="true">
<key update="true" foreign-key="lab_contactlist">
<column name="lab_sk" not-null="true" unique="false"/>
</key>
<one-to-many entity-name="Contact"/>
</bag>

will allow this. I'm curious if you think that is correct and if so, how to
get teneo to do that?

Thanks for all your help!

-Alex


"Martin Taal" <mtaal@elver.org> wrote in message
news:fveap3$716$3@build.eclipse.org...
> Hi Alex,
> I am not sure that I understand the relational schema, but maybe I am
> missing something.
>
> When removing the contact the following sql is executed:
> > update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
> > delete from ContactTable where contact_sk=?
>
> But why is there a contact_sk column in the LabTable as this is the table
> containing the Lab instances? And why is it nulling the lab_sk while this
> is the pk of the LabTable (afaics).
> As the Contact is contained by the Lab, I would expect a fk from
> ContactTable to LabTable.
>
> gr. Martin
>
> Alex Black wrote:
>> Hello,
>> I'm having difficulty deleting child objects on a merge call. I have a
>> parent object, Lab, which contains a list of Contacts:
>>
>> ------------------------------------------------------------ ---------------------
>>
>> <xsd:complexType name="Lab">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Entity
>> @Table(
>> name="LabTable"
>> )
>> </xsd:appinfo>
>> </xsd:annotation>
>>
>> <xsd:sequence>
>>
>> <!--lots of irrelevent stuff--->
>>
>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>> name="contactList" type="Contact">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @OneToMany(indexed=false)
>> @JoinColumn(name="LAB_SK", nullable=false)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>
>>
>> </xsd:sequence>
>>
>> </xsd:complexType>
>>
>>
>>
>> <xsd:complexType name="Contact">
>>
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Entity
>> @Table(
>> name="ContactTable"
>> )
>> </xsd:appinfo>
>> </xsd:annotation>
>>
>> <xsd:sequence>
>>
>> <xsd:element default="0" name="contactSK" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id
>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>> @Column(name=Contact_SK,nullable="false",updatable=false)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>>
>> <!--lots of irrelevent stuff--->
>>
>>
>> </xsd:sequence>
>> </xsd:complexType>
>>
>> ------------------------------------------------------------ ---------------------
>>
>> The Lab is loaded by a client via a web service, so it is completely
>> serialized and deserialized before it comes back into the system as a
>> detatched object. The client has monkeyed with the data he pulled down,
>> and occasionally removes a contact from the contactList. To handle the
>> incoming changes, I'm using the hibernate merge method:
>>
>>
>> ------------------------------------------------------------ ---------------------
>> //bunch of deserialization code
>>
>> outputLab = (Lab)session.merge(inputLab)
>>
>> //bunch of serialization code
>> ------------------------------------------------------------ ---------------------
>>
>> Beautifully simple, and works as advertised. My problem is that when
>> hibernate removes a row from the ContactTable, it nulls out the foreign
>> key first (summarized SQL):
>>
>> ------------------------------------------------------------ ---------------------
>>
>> --bunch of selects
>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>> delete from ContactTable where contact_sk=?
>>
>> ------------------------------------------------------------ ---------------------
>>
>>
>> This causes a foreign key not null constraint violation. I have "fixed"
>> the issue by asking the DBA to drop the not null constraints for the
>> moment (then repremanding myself sternly for even suggesting the idea),
>> but would like hibernate to please just delete the row without nulling
>> it.
>>
>> It appears that the standard hibernate way to do this is to add an
>> 'inverse="true"' to the oneToMany:
>>
>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>
>> but I can't figure out how to get a Teneo annotation to do that.
>>
>> Any thoughts or ideas? Is this the right approach?
>>
>> Thanks,
>>
>> -Alex
>>
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> Tel: +31 (0)84 420 2397
> Fax: +31 (0)84 225 9307
> Mail: mtaal@springsite.com - mtaal@elver.org
> Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #121868 is a reply to message #121776] Mon, 05 May 2008 17:18 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Alex,
I understand what you mean. However, teneo on purpose does not set inverse=true because
bidirectional relations are handled by emf and if hibernate also handles bi-directional relations
then it does not work well. I re-tested this yesterday and many of my testcases fail if I add
inverse=true. So I will need to look in more detail at this.

Can you enter a bugzilla for this? Then I can take some more time to look at it.

I am on holiday, so I can't spend to much time on this, this week.

gr. Martin

Alex Black wrote:
> Hi Martin,
> I apologize, you are correct, when I translated the SQL from our own
> incomprehensible table names I made a mistake, the summarized sql should
> look like this:
>
> update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
> delete from ContactTable where contact_sk=?
>
> The behavior I'd like is simply:
>
> delete from ContactTable where contact_sk=?
>
>
> The generated hibernate mapping for the list might help too:
>
> <bag name="contactList" lazy="true" cascade="all,delete-orphan">
> <key update="true" foreign-key="lab_contactlist">
> <column name="lab_sk" not-null="true" unique="false"/>
> </key>
> <one-to-many entity-name="Contact"/>
> </bag>
>
>
> The hibernate discussion forums seem to say that adding 'inverse="true"':
>
> <bag name="contactList" lazy="true" cascade="all,delete-orphan"
> inverse="true">
> <key update="true" foreign-key="lab_contactlist">
> <column name="lab_sk" not-null="true" unique="false"/>
> </key>
> <one-to-many entity-name="Contact"/>
> </bag>
>
> will allow this. I'm curious if you think that is correct and if so, how to
> get teneo to do that?
>
> Thanks for all your help!
>
> -Alex
>
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fveap3$716$3@build.eclipse.org...
>> Hi Alex,
>> I am not sure that I understand the relational schema, but maybe I am
>> missing something.
>>
>> When removing the contact the following sql is executed:
>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>> delete from ContactTable where contact_sk=?
>> But why is there a contact_sk column in the LabTable as this is the table
>> containing the Lab instances? And why is it nulling the lab_sk while this
>> is the pk of the LabTable (afaics).
>> As the Contact is contained by the Lab, I would expect a fk from
>> ContactTable to LabTable.
>>
>> gr. Martin
>>
>> Alex Black wrote:
>>> Hello,
>>> I'm having difficulty deleting child objects on a merge call. I have a
>>> parent object, Lab, which contains a list of Contacts:
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>> <xsd:complexType name="Lab">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Entity
>>> @Table(
>>> name="LabTable"
>>> )
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>>
>>> <xsd:sequence>
>>>
>>> <!--lots of irrelevent stuff--->
>>>
>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>> name="contactList" type="Contact">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @OneToMany(indexed=false)
>>> @JoinColumn(name="LAB_SK", nullable=false)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>> </xsd:sequence>
>>>
>>> </xsd:complexType>
>>>
>>>
>>>
>>> <xsd:complexType name="Contact">
>>>
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Entity
>>> @Table(
>>> name="ContactTable"
>>> )
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>>
>>> <xsd:sequence>
>>>
>>> <xsd:element default="0" name="contactSK" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id
>>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>>> @Column(name=Contact_SK,nullable="false",updatable=false)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>>
>>> <!--lots of irrelevent stuff--->
>>>
>>>
>>> </xsd:sequence>
>>> </xsd:complexType>
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>> The Lab is loaded by a client via a web service, so it is completely
>>> serialized and deserialized before it comes back into the system as a
>>> detatched object. The client has monkeyed with the data he pulled down,
>>> and occasionally removes a contact from the contactList. To handle the
>>> incoming changes, I'm using the hibernate merge method:
>>>
>>>
>>> ------------------------------------------------------------ ---------------------
>>> //bunch of deserialization code
>>>
>>> outputLab = (Lab)session.merge(inputLab)
>>>
>>> //bunch of serialization code
>>> ------------------------------------------------------------ ---------------------
>>>
>>> Beautifully simple, and works as advertised. My problem is that when
>>> hibernate removes a row from the ContactTable, it nulls out the foreign
>>> key first (summarized SQL):
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>> --bunch of selects
>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>> delete from ContactTable where contact_sk=?
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>>
>>> This causes a foreign key not null constraint violation. I have "fixed"
>>> the issue by asking the DBA to drop the not null constraints for the
>>> moment (then repremanding myself sternly for even suggesting the idea),
>>> but would like hibernate to please just delete the row without nulling
>>> it.
>>>
>>> It appears that the standard hibernate way to do this is to add an
>>> 'inverse="true"' to the oneToMany:
>>>
>>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>>
>>> but I can't figure out how to get a Teneo annotation to do that.
>>>
>>> Any thoughts or ideas? Is this the right approach?
>>>
>>> Thanks,
>>>
>>> -Alex
>>>
>>>
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> Tel: +31 (0)84 420 2397
>> Fax: +31 (0)84 225 9307
>> Mail: mtaal@springsite.com - mtaal@elver.org
>> Web: www.springsite.com - www.elver.org
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #127755 is a reply to message #121868] Wed, 30 July 2008 18:04 Go to previous messageGo to next message
Alex Black is currently offline Alex BlackFriend
Messages: 15
Registered: July 2009
Junior Member
Hi Martin,
I apologize for being three months late with this, but this has recently
become an issue for us again. I've created a bug and submitted it:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=242479


Thanks!

-Alex

"Martin Taal" <mtaal@elver.org> wrote in message
news:fvnfgs$cfi$1@build.eclipse.org...
> Hi Alex,
> I understand what you mean. However, teneo on purpose does not set
> inverse=true because bidirectional relations are handled by emf and if
> hibernate also handles bi-directional relations then it does not work
> well. I re-tested this yesterday and many of my testcases fail if I add
> inverse=true. So I will need to look in more detail at this.
>
> Can you enter a bugzilla for this? Then I can take some more time to look
> at it.
>
> I am on holiday, so I can't spend to much time on this, this week.
>
> gr. Martin
>
> Alex Black wrote:
>> Hi Martin,
>> I apologize, you are correct, when I translated the SQL from our own
>> incomprehensible table names I made a mistake, the summarized sql should
>> look like this:
>>
>> update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
>> delete from ContactTable where contact_sk=?
>>
>> The behavior I'd like is simply:
>>
>> delete from ContactTable where contact_sk=?
>>
>>
>> The generated hibernate mapping for the list might help too:
>>
>> <bag name="contactList" lazy="true" cascade="all,delete-orphan">
>> <key update="true" foreign-key="lab_contactlist">
>> <column name="lab_sk" not-null="true" unique="false"/>
>> </key>
>> <one-to-many entity-name="Contact"/>
>> </bag>
>>
>>
>> The hibernate discussion forums seem to say that adding 'inverse="true"':
>>
>> <bag name="contactList" lazy="true" cascade="all,delete-orphan"
>> inverse="true">
>> <key update="true" foreign-key="lab_contactlist">
>> <column name="lab_sk" not-null="true" unique="false"/>
>> </key>
>> <one-to-many entity-name="Contact"/>
>> </bag>
>>
>> will allow this. I'm curious if you think that is correct and if so, how
>> to get teneo to do that?
>>
>> Thanks for all your help!
>>
>> -Alex
>>
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:fveap3$716$3@build.eclipse.org...
>>> Hi Alex,
>>> I am not sure that I understand the relational schema, but maybe I am
>>> missing something.
>>>
>>> When removing the contact the following sql is executed:
>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>> delete from ContactTable where contact_sk=?
>>> But why is there a contact_sk column in the LabTable as this is the
>>> table containing the Lab instances? And why is it nulling the lab_sk
>>> while this is the pk of the LabTable (afaics).
>>> As the Contact is contained by the Lab, I would expect a fk from
>>> ContactTable to LabTable.
>>>
>>> gr. Martin
>>>
>>> Alex Black wrote:
>>>> Hello,
>>>> I'm having difficulty deleting child objects on a merge call. I have
>>>> a parent object, Lab, which contains a list of Contacts:
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> <xsd:complexType name="Lab">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Entity
>>>> @Table(
>>>> name="LabTable"
>>>> )
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>>
>>>> <xsd:sequence>
>>>>
>>>> <!--lots of irrelevent stuff--->
>>>>
>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>> name="contactList" type="Contact">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @OneToMany(indexed=false)
>>>> @JoinColumn(name="LAB_SK", nullable=false)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>> </xsd:sequence>
>>>>
>>>> </xsd:complexType>
>>>>
>>>>
>>>>
>>>> <xsd:complexType name="Contact">
>>>>
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Entity
>>>> @Table(
>>>> name="ContactTable"
>>>> )
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>>
>>>> <xsd:sequence>
>>>>
>>>> <xsd:element default="0" name="contactSK" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Id
>>>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>>>> @Column(name=Contact_SK,nullable="false",updatable=false)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>>
>>>>
>>>> <!--lots of irrelevent stuff--->
>>>>
>>>>
>>>> </xsd:sequence>
>>>> </xsd:complexType>
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> The Lab is loaded by a client via a web service, so it is completely
>>>> serialized and deserialized before it comes back into the system as a
>>>> detatched object. The client has monkeyed with the data he pulled
>>>> down, and occasionally removes a contact from the contactList. To
>>>> handle the incoming changes, I'm using the hibernate merge method:
>>>>
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>> //bunch of deserialization code
>>>>
>>>> outputLab = (Lab)session.merge(inputLab)
>>>>
>>>> //bunch of serialization code
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> Beautifully simple, and works as advertised. My problem is that when
>>>> hibernate removes a row from the ContactTable, it nulls out the foreign
>>>> key first (summarized SQL):
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> --bunch of selects
>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>> delete from ContactTable where contact_sk=?
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>>
>>>> This causes a foreign key not null constraint violation. I have
>>>> "fixed" the issue by asking the DBA to drop the not null constraints
>>>> for the moment (then repremanding myself sternly for even suggesting
>>>> the idea), but would like hibernate to please just delete the row
>>>> without nulling it.
>>>>
>>>> It appears that the standard hibernate way to do this is to add an
>>>> 'inverse="true"' to the oneToMany:
>>>>
>>>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>>>
>>>> but I can't figure out how to get a Teneo annotation to do that.
>>>>
>>>> Any thoughts or ideas? Is this the right approach?
>>>>
>>>> Thanks,
>>>>
>>>> -Alex
>>>>
>>>>
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> Tel: +31 (0)84 420 2397
>>> Fax: +31 (0)84 225 9307
>>> Mail: mtaal@springsite.com - mtaal@elver.org
>>> Web: www.springsite.com - www.elver.org
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> Tel: +31 (0)84 420 2397
> Fax: +31 (0)84 225 9307
> Mail: mtaal@springsite.com - mtaal@elver.org
> Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #127768 is a reply to message #127755] Wed, 30 July 2008 18:08 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Alex,
No problem, I have seen the bugzilla. I will probably add an annotation attribute on the one-to-many
or many-to-one to signal that inverse=true should be put in the mapping. I hope to solve this and
some other issues around this weekend.

Btw, support for Teneo is now given on the EMF newsgroup which I cc-ed.

gr. Martin

Alex Black wrote:
> Hi Martin,
> I apologize for being three months late with this, but this has recently
> become an issue for us again. I've created a bug and submitted it:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=242479
>
>
> Thanks!
>
> -Alex
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fvnfgs$cfi$1@build.eclipse.org...
>> Hi Alex,
>> I understand what you mean. However, teneo on purpose does not set
>> inverse=true because bidirectional relations are handled by emf and if
>> hibernate also handles bi-directional relations then it does not work
>> well. I re-tested this yesterday and many of my testcases fail if I add
>> inverse=true. So I will need to look in more detail at this.
>>
>> Can you enter a bugzilla for this? Then I can take some more time to look
>> at it.
>>
>> I am on holiday, so I can't spend to much time on this, this week.
>>
>> gr. Martin
>>
>> Alex Black wrote:
>>> Hi Martin,
>>> I apologize, you are correct, when I translated the SQL from our own
>>> incomprehensible table names I made a mistake, the summarized sql should
>>> look like this:
>>>
>>> update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
>>> delete from ContactTable where contact_sk=?
>>>
>>> The behavior I'd like is simply:
>>>
>>> delete from ContactTable where contact_sk=?
>>>
>>>
>>> The generated hibernate mapping for the list might help too:
>>>
>>> <bag name="contactList" lazy="true" cascade="all,delete-orphan">
>>> <key update="true" foreign-key="lab_contactlist">
>>> <column name="lab_sk" not-null="true" unique="false"/>
>>> </key>
>>> <one-to-many entity-name="Contact"/>
>>> </bag>
>>>
>>>
>>> The hibernate discussion forums seem to say that adding 'inverse="true"':
>>>
>>> <bag name="contactList" lazy="true" cascade="all,delete-orphan"
>>> inverse="true">
>>> <key update="true" foreign-key="lab_contactlist">
>>> <column name="lab_sk" not-null="true" unique="false"/>
>>> </key>
>>> <one-to-many entity-name="Contact"/>
>>> </bag>
>>>
>>> will allow this. I'm curious if you think that is correct and if so, how
>>> to get teneo to do that?
>>>
>>> Thanks for all your help!
>>>
>>> -Alex
>>>
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:fveap3$716$3@build.eclipse.org...
>>>> Hi Alex,
>>>> I am not sure that I understand the relational schema, but maybe I am
>>>> missing something.
>>>>
>>>> When removing the contact the following sql is executed:
>>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>>> delete from ContactTable where contact_sk=?
>>>> But why is there a contact_sk column in the LabTable as this is the
>>>> table containing the Lab instances? And why is it nulling the lab_sk
>>>> while this is the pk of the LabTable (afaics).
>>>> As the Contact is contained by the Lab, I would expect a fk from
>>>> ContactTable to LabTable.
>>>>
>>>> gr. Martin
>>>>
>>>> Alex Black wrote:
>>>>> Hello,
>>>>> I'm having difficulty deleting child objects on a merge call. I have
>>>>> a parent object, Lab, which contains a list of Contacts:
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> <xsd:complexType name="Lab">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Entity
>>>>> @Table(
>>>>> name="LabTable"
>>>>> )
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>>
>>>>> <xsd:sequence>
>>>>>
>>>>> <!--lots of irrelevent stuff--->
>>>>>
>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>> name="contactList" type="Contact">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @OneToMany(indexed=false)
>>>>> @JoinColumn(name="LAB_SK", nullable=false)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>> </xsd:sequence>
>>>>>
>>>>> </xsd:complexType>
>>>>>
>>>>>
>>>>>
>>>>> <xsd:complexType name="Contact">
>>>>>
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Entity
>>>>> @Table(
>>>>> name="ContactTable"
>>>>> )
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>>
>>>>> <xsd:sequence>
>>>>>
>>>>> <xsd:element default="0" name="contactSK" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Id
>>>>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>>>>> @Column(name=Contact_SK,nullable="false",updatable=false)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>>
>>>>>
>>>>> <!--lots of irrelevent stuff--->
>>>>>
>>>>>
>>>>> </xsd:sequence>
>>>>> </xsd:complexType>
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> The Lab is loaded by a client via a web service, so it is completely
>>>>> serialized and deserialized before it comes back into the system as a
>>>>> detatched object. The client has monkeyed with the data he pulled
>>>>> down, and occasionally removes a contact from the contactList. To
>>>>> handle the incoming changes, I'm using the hibernate merge method:
>>>>>
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>> //bunch of deserialization code
>>>>>
>>>>> outputLab = (Lab)session.merge(inputLab)
>>>>>
>>>>> //bunch of serialization code
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> Beautifully simple, and works as advertised. My problem is that when
>>>>> hibernate removes a row from the ContactTable, it nulls out the foreign
>>>>> key first (summarized SQL):
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> --bunch of selects
>>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>>> delete from ContactTable where contact_sk=?
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>>
>>>>> This causes a foreign key not null constraint violation. I have
>>>>> "fixed" the issue by asking the DBA to drop the not null constraints
>>>>> for the moment (then repremanding myself sternly for even suggesting
>>>>> the idea), but would like hibernate to please just delete the row
>>>>> without nulling it.
>>>>>
>>>>> It appears that the standard hibernate way to do this is to add an
>>>>> 'inverse="true"' to the oneToMany:
>>>>>
>>>>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>>>>
>>>>> but I can't figure out how to get a Teneo annotation to do that.
>>>>>
>>>>> Any thoughts or ideas? Is this the right approach?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> -Alex
>>>>>
>>>>>
>>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> Tel: +31 (0)84 420 2397
>>>> Fax: +31 (0)84 225 9307
>>>> Mail: mtaal@springsite.com - mtaal@elver.org
>>>> Web: www.springsite.com - www.elver.org
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> Tel: +31 (0)84 420 2397
>> Fax: +31 (0)84 225 9307
>> Mail: mtaal@springsite.com - mtaal@elver.org
>> Web: www.springsite.com - www.elver.org
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #617983 is a reply to message #121555] Fri, 02 May 2008 05:53 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Alex,
I am not sure that I understand the relational schema, but maybe I am missing something.

When removing the contact the following sql is executed:
> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
> delete from ContactTable where contact_sk=?

But why is there a contact_sk column in the LabTable as this is the table containing the Lab
instances? And why is it nulling the lab_sk while this is the pk of the LabTable (afaics).
As the Contact is contained by the Lab, I would expect a fk from ContactTable to LabTable.

gr. Martin

Alex Black wrote:
> Hello,
> I'm having difficulty deleting child objects on a merge call. I have a
> parent object, Lab, which contains a list of Contacts:
>
> ------------------------------------------------------------ ---------------------
>
> <xsd:complexType name="Lab">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Entity
> @Table(
> name="LabTable"
> )
> </xsd:appinfo>
> </xsd:annotation>
>
> <xsd:sequence>
>
> <!--lots of irrelevent stuff--->
>
> <xsd:element maxOccurs="unbounded" minOccurs="0" name="contactList"
> type="Contact">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @OneToMany(indexed=false)
> @JoinColumn(name="LAB_SK", nullable=false)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>

>
> </xsd:sequence>
>
> </xsd:complexType>
>
>
>
> <xsd:complexType name="Contact">
>
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Entity
> @Table(
> name="ContactTable"
> )
> </xsd:appinfo>
> </xsd:annotation>
>
> <xsd:sequence>
>
> <xsd:element default="0" name="contactSK" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id
> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
> @Column(name=Contact_SK,nullable="false",updatable=false)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
>
> <!--lots of irrelevent stuff--->
>
>
> </xsd:sequence>
> </xsd:complexType>
>
> ------------------------------------------------------------ ---------------------
>
> The Lab is loaded by a client via a web service, so it is completely
> serialized and deserialized before it comes back into the system as a
> detatched object. The client has monkeyed with the data he pulled down, and
> occasionally removes a contact from the contactList. To handle the incoming
> changes, I'm using the hibernate merge method:
>
>
> ------------------------------------------------------------ ---------------------
> //bunch of deserialization code
>
> outputLab = (Lab)session.merge(inputLab)
>
> //bunch of serialization code
> ------------------------------------------------------------ ---------------------
>
> Beautifully simple, and works as advertised. My problem is that when
> hibernate removes a row from the ContactTable, it nulls out the foreign key
> first (summarized SQL):
>
> ------------------------------------------------------------ ---------------------
>
> --bunch of selects
> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
> delete from ContactTable where contact_sk=?
>
> ------------------------------------------------------------ ---------------------
>
>
> This causes a foreign key not null constraint violation. I have "fixed" the
> issue by asking the DBA to drop the not null constraints for the moment
> (then repremanding myself sternly for even suggesting the idea), but would
> like hibernate to please just delete the row without nulling it.
>
> It appears that the standard hibernate way to do this is to add an
> 'inverse="true"' to the oneToMany:
>
> http://forum.hibernate.org/viewtopic.php?p=2383090
>
> but I can't figure out how to get a Teneo annotation to do that.
>
> Any thoughts or ideas? Is this the right approach?
>
> Thanks,
>
> -Alex
>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #617986 is a reply to message #121734] Fri, 02 May 2008 15:49 Go to previous message
Alex Black is currently offline Alex BlackFriend
Messages: 15
Registered: July 2009
Junior Member
Hi Martin,
I apologize, you are correct, when I translated the SQL from our own
incomprehensible table names I made a mistake, the summarized sql should
look like this:

update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
delete from ContactTable where contact_sk=?

The behavior I'd like is simply:

delete from ContactTable where contact_sk=?


The generated hibernate mapping for the list might help too:

<bag name="contactList" lazy="true" cascade="all,delete-orphan">
<key update="true" foreign-key="lab_contactlist">
<column name="lab_sk" not-null="true" unique="false"/>
</key>
<one-to-many entity-name="Contact"/>
</bag>


The hibernate discussion forums seem to say that adding 'inverse="true"':

<bag name="contactList" lazy="true" cascade="all,delete-orphan"
inverse="true">
<key update="true" foreign-key="lab_contactlist">
<column name="lab_sk" not-null="true" unique="false"/>
</key>
<one-to-many entity-name="Contact"/>
</bag>

will allow this. I'm curious if you think that is correct and if so, how to
get teneo to do that?

Thanks for all your help!

-Alex


"Martin Taal" <mtaal@elver.org> wrote in message
news:fveap3$716$3@build.eclipse.org...
> Hi Alex,
> I am not sure that I understand the relational schema, but maybe I am
> missing something.
>
> When removing the contact the following sql is executed:
> > update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
> > delete from ContactTable where contact_sk=?
>
> But why is there a contact_sk column in the LabTable as this is the table
> containing the Lab instances? And why is it nulling the lab_sk while this
> is the pk of the LabTable (afaics).
> As the Contact is contained by the Lab, I would expect a fk from
> ContactTable to LabTable.
>
> gr. Martin
>
> Alex Black wrote:
>> Hello,
>> I'm having difficulty deleting child objects on a merge call. I have a
>> parent object, Lab, which contains a list of Contacts:
>>
>> ------------------------------------------------------------ ---------------------
>>
>> <xsd:complexType name="Lab">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Entity
>> @Table(
>> name="LabTable"
>> )
>> </xsd:appinfo>
>> </xsd:annotation>
>>
>> <xsd:sequence>
>>
>> <!--lots of irrelevent stuff--->
>>
>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>> name="contactList" type="Contact">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @OneToMany(indexed=false)
>> @JoinColumn(name="LAB_SK", nullable=false)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>
>>
>> </xsd:sequence>
>>
>> </xsd:complexType>
>>
>>
>>
>> <xsd:complexType name="Contact">
>>
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Entity
>> @Table(
>> name="ContactTable"
>> )
>> </xsd:appinfo>
>> </xsd:annotation>
>>
>> <xsd:sequence>
>>
>> <xsd:element default="0" name="contactSK" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id
>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>> @Column(name=Contact_SK,nullable="false",updatable=false)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>>
>> <!--lots of irrelevent stuff--->
>>
>>
>> </xsd:sequence>
>> </xsd:complexType>
>>
>> ------------------------------------------------------------ ---------------------
>>
>> The Lab is loaded by a client via a web service, so it is completely
>> serialized and deserialized before it comes back into the system as a
>> detatched object. The client has monkeyed with the data he pulled down,
>> and occasionally removes a contact from the contactList. To handle the
>> incoming changes, I'm using the hibernate merge method:
>>
>>
>> ------------------------------------------------------------ ---------------------
>> //bunch of deserialization code
>>
>> outputLab = (Lab)session.merge(inputLab)
>>
>> //bunch of serialization code
>> ------------------------------------------------------------ ---------------------
>>
>> Beautifully simple, and works as advertised. My problem is that when
>> hibernate removes a row from the ContactTable, it nulls out the foreign
>> key first (summarized SQL):
>>
>> ------------------------------------------------------------ ---------------------
>>
>> --bunch of selects
>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>> delete from ContactTable where contact_sk=?
>>
>> ------------------------------------------------------------ ---------------------
>>
>>
>> This causes a foreign key not null constraint violation. I have "fixed"
>> the issue by asking the DBA to drop the not null constraints for the
>> moment (then repremanding myself sternly for even suggesting the idea),
>> but would like hibernate to please just delete the row without nulling
>> it.
>>
>> It appears that the standard hibernate way to do this is to add an
>> 'inverse="true"' to the oneToMany:
>>
>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>
>> but I can't figure out how to get a Teneo annotation to do that.
>>
>> Any thoughts or ideas? Is this the right approach?
>>
>> Thanks,
>>
>> -Alex
>>
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> Tel: +31 (0)84 420 2397
> Fax: +31 (0)84 225 9307
> Mail: mtaal@springsite.com - mtaal@elver.org
> Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #617993 is a reply to message #121776] Mon, 05 May 2008 17:18 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Alex,
I understand what you mean. However, teneo on purpose does not set inverse=true because
bidirectional relations are handled by emf and if hibernate also handles bi-directional relations
then it does not work well. I re-tested this yesterday and many of my testcases fail if I add
inverse=true. So I will need to look in more detail at this.

Can you enter a bugzilla for this? Then I can take some more time to look at it.

I am on holiday, so I can't spend to much time on this, this week.

gr. Martin

Alex Black wrote:
> Hi Martin,
> I apologize, you are correct, when I translated the SQL from our own
> incomprehensible table names I made a mistake, the summarized sql should
> look like this:
>
> update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
> delete from ContactTable where contact_sk=?
>
> The behavior I'd like is simply:
>
> delete from ContactTable where contact_sk=?
>
>
> The generated hibernate mapping for the list might help too:
>
> <bag name="contactList" lazy="true" cascade="all,delete-orphan">
> <key update="true" foreign-key="lab_contactlist">
> <column name="lab_sk" not-null="true" unique="false"/>
> </key>
> <one-to-many entity-name="Contact"/>
> </bag>
>
>
> The hibernate discussion forums seem to say that adding 'inverse="true"':
>
> <bag name="contactList" lazy="true" cascade="all,delete-orphan"
> inverse="true">
> <key update="true" foreign-key="lab_contactlist">
> <column name="lab_sk" not-null="true" unique="false"/>
> </key>
> <one-to-many entity-name="Contact"/>
> </bag>
>
> will allow this. I'm curious if you think that is correct and if so, how to
> get teneo to do that?
>
> Thanks for all your help!
>
> -Alex
>
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fveap3$716$3@build.eclipse.org...
>> Hi Alex,
>> I am not sure that I understand the relational schema, but maybe I am
>> missing something.
>>
>> When removing the contact the following sql is executed:
>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>> delete from ContactTable where contact_sk=?
>> But why is there a contact_sk column in the LabTable as this is the table
>> containing the Lab instances? And why is it nulling the lab_sk while this
>> is the pk of the LabTable (afaics).
>> As the Contact is contained by the Lab, I would expect a fk from
>> ContactTable to LabTable.
>>
>> gr. Martin
>>
>> Alex Black wrote:
>>> Hello,
>>> I'm having difficulty deleting child objects on a merge call. I have a
>>> parent object, Lab, which contains a list of Contacts:
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>> <xsd:complexType name="Lab">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Entity
>>> @Table(
>>> name="LabTable"
>>> )
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>>
>>> <xsd:sequence>
>>>
>>> <!--lots of irrelevent stuff--->
>>>
>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>> name="contactList" type="Contact">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @OneToMany(indexed=false)
>>> @JoinColumn(name="LAB_SK", nullable=false)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>> </xsd:sequence>
>>>
>>> </xsd:complexType>
>>>
>>>
>>>
>>> <xsd:complexType name="Contact">
>>>
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Entity
>>> @Table(
>>> name="ContactTable"
>>> )
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>>
>>> <xsd:sequence>
>>>
>>> <xsd:element default="0" name="contactSK" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id
>>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>>> @Column(name=Contact_SK,nullable="false",updatable=false)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>>
>>> <!--lots of irrelevent stuff--->
>>>
>>>
>>> </xsd:sequence>
>>> </xsd:complexType>
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>> The Lab is loaded by a client via a web service, so it is completely
>>> serialized and deserialized before it comes back into the system as a
>>> detatched object. The client has monkeyed with the data he pulled down,
>>> and occasionally removes a contact from the contactList. To handle the
>>> incoming changes, I'm using the hibernate merge method:
>>>
>>>
>>> ------------------------------------------------------------ ---------------------
>>> //bunch of deserialization code
>>>
>>> outputLab = (Lab)session.merge(inputLab)
>>>
>>> //bunch of serialization code
>>> ------------------------------------------------------------ ---------------------
>>>
>>> Beautifully simple, and works as advertised. My problem is that when
>>> hibernate removes a row from the ContactTable, it nulls out the foreign
>>> key first (summarized SQL):
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>> --bunch of selects
>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>> delete from ContactTable where contact_sk=?
>>>
>>> ------------------------------------------------------------ ---------------------
>>>
>>>
>>> This causes a foreign key not null constraint violation. I have "fixed"
>>> the issue by asking the DBA to drop the not null constraints for the
>>> moment (then repremanding myself sternly for even suggesting the idea),
>>> but would like hibernate to please just delete the row without nulling
>>> it.
>>>
>>> It appears that the standard hibernate way to do this is to add an
>>> 'inverse="true"' to the oneToMany:
>>>
>>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>>
>>> but I can't figure out how to get a Teneo annotation to do that.
>>>
>>> Any thoughts or ideas? Is this the right approach?
>>>
>>> Thanks,
>>>
>>> -Alex
>>>
>>>
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> Tel: +31 (0)84 420 2397
>> Fax: +31 (0)84 225 9307
>> Mail: mtaal@springsite.com - mtaal@elver.org
>> Web: www.springsite.com - www.elver.org
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #620164 is a reply to message #121868] Wed, 30 July 2008 18:04 Go to previous message
Alex Black is currently offline Alex BlackFriend
Messages: 15
Registered: July 2009
Junior Member
Hi Martin,
I apologize for being three months late with this, but this has recently
become an issue for us again. I've created a bug and submitted it:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=242479


Thanks!

-Alex

"Martin Taal" <mtaal@elver.org> wrote in message
news:fvnfgs$cfi$1@build.eclipse.org...
> Hi Alex,
> I understand what you mean. However, teneo on purpose does not set
> inverse=true because bidirectional relations are handled by emf and if
> hibernate also handles bi-directional relations then it does not work
> well. I re-tested this yesterday and many of my testcases fail if I add
> inverse=true. So I will need to look in more detail at this.
>
> Can you enter a bugzilla for this? Then I can take some more time to look
> at it.
>
> I am on holiday, so I can't spend to much time on this, this week.
>
> gr. Martin
>
> Alex Black wrote:
>> Hi Martin,
>> I apologize, you are correct, when I translated the SQL from our own
>> incomprehensible table names I made a mistake, the summarized sql should
>> look like this:
>>
>> update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
>> delete from ContactTable where contact_sk=?
>>
>> The behavior I'd like is simply:
>>
>> delete from ContactTable where contact_sk=?
>>
>>
>> The generated hibernate mapping for the list might help too:
>>
>> <bag name="contactList" lazy="true" cascade="all,delete-orphan">
>> <key update="true" foreign-key="lab_contactlist">
>> <column name="lab_sk" not-null="true" unique="false"/>
>> </key>
>> <one-to-many entity-name="Contact"/>
>> </bag>
>>
>>
>> The hibernate discussion forums seem to say that adding 'inverse="true"':
>>
>> <bag name="contactList" lazy="true" cascade="all,delete-orphan"
>> inverse="true">
>> <key update="true" foreign-key="lab_contactlist">
>> <column name="lab_sk" not-null="true" unique="false"/>
>> </key>
>> <one-to-many entity-name="Contact"/>
>> </bag>
>>
>> will allow this. I'm curious if you think that is correct and if so, how
>> to get teneo to do that?
>>
>> Thanks for all your help!
>>
>> -Alex
>>
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:fveap3$716$3@build.eclipse.org...
>>> Hi Alex,
>>> I am not sure that I understand the relational schema, but maybe I am
>>> missing something.
>>>
>>> When removing the contact the following sql is executed:
>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>> delete from ContactTable where contact_sk=?
>>> But why is there a contact_sk column in the LabTable as this is the
>>> table containing the Lab instances? And why is it nulling the lab_sk
>>> while this is the pk of the LabTable (afaics).
>>> As the Contact is contained by the Lab, I would expect a fk from
>>> ContactTable to LabTable.
>>>
>>> gr. Martin
>>>
>>> Alex Black wrote:
>>>> Hello,
>>>> I'm having difficulty deleting child objects on a merge call. I have
>>>> a parent object, Lab, which contains a list of Contacts:
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> <xsd:complexType name="Lab">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Entity
>>>> @Table(
>>>> name="LabTable"
>>>> )
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>>
>>>> <xsd:sequence>
>>>>
>>>> <!--lots of irrelevent stuff--->
>>>>
>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>> name="contactList" type="Contact">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @OneToMany(indexed=false)
>>>> @JoinColumn(name="LAB_SK", nullable=false)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>> </xsd:sequence>
>>>>
>>>> </xsd:complexType>
>>>>
>>>>
>>>>
>>>> <xsd:complexType name="Contact">
>>>>
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Entity
>>>> @Table(
>>>> name="ContactTable"
>>>> )
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>>
>>>> <xsd:sequence>
>>>>
>>>> <xsd:element default="0" name="contactSK" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Id
>>>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>>>> @Column(name=Contact_SK,nullable="false",updatable=false)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>>
>>>>
>>>> <!--lots of irrelevent stuff--->
>>>>
>>>>
>>>> </xsd:sequence>
>>>> </xsd:complexType>
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> The Lab is loaded by a client via a web service, so it is completely
>>>> serialized and deserialized before it comes back into the system as a
>>>> detatched object. The client has monkeyed with the data he pulled
>>>> down, and occasionally removes a contact from the contactList. To
>>>> handle the incoming changes, I'm using the hibernate merge method:
>>>>
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>> //bunch of deserialization code
>>>>
>>>> outputLab = (Lab)session.merge(inputLab)
>>>>
>>>> //bunch of serialization code
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> Beautifully simple, and works as advertised. My problem is that when
>>>> hibernate removes a row from the ContactTable, it nulls out the foreign
>>>> key first (summarized SQL):
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>> --bunch of selects
>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>> delete from ContactTable where contact_sk=?
>>>>
>>>> ------------------------------------------------------------ ---------------------
>>>>
>>>>
>>>> This causes a foreign key not null constraint violation. I have
>>>> "fixed" the issue by asking the DBA to drop the not null constraints
>>>> for the moment (then repremanding myself sternly for even suggesting
>>>> the idea), but would like hibernate to please just delete the row
>>>> without nulling it.
>>>>
>>>> It appears that the standard hibernate way to do this is to add an
>>>> 'inverse="true"' to the oneToMany:
>>>>
>>>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>>>
>>>> but I can't figure out how to get a Teneo annotation to do that.
>>>>
>>>> Any thoughts or ideas? Is this the right approach?
>>>>
>>>> Thanks,
>>>>
>>>> -Alex
>>>>
>>>>
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> Tel: +31 (0)84 420 2397
>>> Fax: +31 (0)84 225 9307
>>> Mail: mtaal@springsite.com - mtaal@elver.org
>>> Web: www.springsite.com - www.elver.org
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> Tel: +31 (0)84 420 2397
> Fax: +31 (0)84 225 9307
> Mail: mtaal@springsite.com - mtaal@elver.org
> Web: www.springsite.com - www.elver.org
Re: [Teneo] Cascade deletes causing not null constraint violations. [message #620165 is a reply to message #127755] Wed, 30 July 2008 18:08 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi Alex,
No problem, I have seen the bugzilla. I will probably add an annotation attribute on the one-to-many
or many-to-one to signal that inverse=true should be put in the mapping. I hope to solve this and
some other issues around this weekend.

Btw, support for Teneo is now given on the EMF newsgroup which I cc-ed.

gr. Martin

Alex Black wrote:
> Hi Martin,
> I apologize for being three months late with this, but this has recently
> become an issue for us again. I've created a bug and submitted it:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=242479
>
>
> Thanks!
>
> -Alex
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fvnfgs$cfi$1@build.eclipse.org...
>> Hi Alex,
>> I understand what you mean. However, teneo on purpose does not set
>> inverse=true because bidirectional relations are handled by emf and if
>> hibernate also handles bi-directional relations then it does not work
>> well. I re-tested this yesterday and many of my testcases fail if I add
>> inverse=true. So I will need to look in more detail at this.
>>
>> Can you enter a bugzilla for this? Then I can take some more time to look
>> at it.
>>
>> I am on holiday, so I can't spend to much time on this, this week.
>>
>> gr. Martin
>>
>> Alex Black wrote:
>>> Hi Martin,
>>> I apologize, you are correct, when I translated the SQL from our own
>>> incomprehensible table names I made a mistake, the summarized sql should
>>> look like this:
>>>
>>> update ContactTable set lab_sk=null where lab_sk=? and contact_sk=?
>>> delete from ContactTable where contact_sk=?
>>>
>>> The behavior I'd like is simply:
>>>
>>> delete from ContactTable where contact_sk=?
>>>
>>>
>>> The generated hibernate mapping for the list might help too:
>>>
>>> <bag name="contactList" lazy="true" cascade="all,delete-orphan">
>>> <key update="true" foreign-key="lab_contactlist">
>>> <column name="lab_sk" not-null="true" unique="false"/>
>>> </key>
>>> <one-to-many entity-name="Contact"/>
>>> </bag>
>>>
>>>
>>> The hibernate discussion forums seem to say that adding 'inverse="true"':
>>>
>>> <bag name="contactList" lazy="true" cascade="all,delete-orphan"
>>> inverse="true">
>>> <key update="true" foreign-key="lab_contactlist">
>>> <column name="lab_sk" not-null="true" unique="false"/>
>>> </key>
>>> <one-to-many entity-name="Contact"/>
>>> </bag>
>>>
>>> will allow this. I'm curious if you think that is correct and if so, how
>>> to get teneo to do that?
>>>
>>> Thanks for all your help!
>>>
>>> -Alex
>>>
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:fveap3$716$3@build.eclipse.org...
>>>> Hi Alex,
>>>> I am not sure that I understand the relational schema, but maybe I am
>>>> missing something.
>>>>
>>>> When removing the contact the following sql is executed:
>>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>>> delete from ContactTable where contact_sk=?
>>>> But why is there a contact_sk column in the LabTable as this is the
>>>> table containing the Lab instances? And why is it nulling the lab_sk
>>>> while this is the pk of the LabTable (afaics).
>>>> As the Contact is contained by the Lab, I would expect a fk from
>>>> ContactTable to LabTable.
>>>>
>>>> gr. Martin
>>>>
>>>> Alex Black wrote:
>>>>> Hello,
>>>>> I'm having difficulty deleting child objects on a merge call. I have
>>>>> a parent object, Lab, which contains a list of Contacts:
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> <xsd:complexType name="Lab">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Entity
>>>>> @Table(
>>>>> name="LabTable"
>>>>> )
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>>
>>>>> <xsd:sequence>
>>>>>
>>>>> <!--lots of irrelevent stuff--->
>>>>>
>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>> name="contactList" type="Contact">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @OneToMany(indexed=false)
>>>>> @JoinColumn(name="LAB_SK", nullable=false)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>> </xsd:sequence>
>>>>>
>>>>> </xsd:complexType>
>>>>>
>>>>>
>>>>>
>>>>> <xsd:complexType name="Contact">
>>>>>
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Entity
>>>>> @Table(
>>>>> name="ContactTable"
>>>>> )
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>>
>>>>> <xsd:sequence>
>>>>>
>>>>> <xsd:element default="0" name="contactSK" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Id
>>>>> @GeneratedValue(strategy=SEQUENCE, generator="labSequence")
>>>>> @Column(name=Contact_SK,nullable="false",updatable=false)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>>
>>>>>
>>>>> <!--lots of irrelevent stuff--->
>>>>>
>>>>>
>>>>> </xsd:sequence>
>>>>> </xsd:complexType>
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> The Lab is loaded by a client via a web service, so it is completely
>>>>> serialized and deserialized before it comes back into the system as a
>>>>> detatched object. The client has monkeyed with the data he pulled
>>>>> down, and occasionally removes a contact from the contactList. To
>>>>> handle the incoming changes, I'm using the hibernate merge method:
>>>>>
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>> //bunch of deserialization code
>>>>>
>>>>> outputLab = (Lab)session.merge(inputLab)
>>>>>
>>>>> //bunch of serialization code
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> Beautifully simple, and works as advertised. My problem is that when
>>>>> hibernate removes a row from the ContactTable, it nulls out the foreign
>>>>> key first (summarized SQL):
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>> --bunch of selects
>>>>> update LabTable set lab_sk=null where lab_sk=? and contact_sk=?
>>>>> delete from ContactTable where contact_sk=?
>>>>>
>>>>> ------------------------------------------------------------ ---------------------
>>>>>
>>>>>
>>>>> This causes a foreign key not null constraint violation. I have
>>>>> "fixed" the issue by asking the DBA to drop the not null constraints
>>>>> for the moment (then repremanding myself sternly for even suggesting
>>>>> the idea), but would like hibernate to please just delete the row
>>>>> without nulling it.
>>>>>
>>>>> It appears that the standard hibernate way to do this is to add an
>>>>> 'inverse="true"' to the oneToMany:
>>>>>
>>>>> http://forum.hibernate.org/viewtopic.php?p=2383090
>>>>>
>>>>> but I can't figure out how to get a Teneo annotation to do that.
>>>>>
>>>>> Any thoughts or ideas? Is this the right approach?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> -Alex
>>>>>
>>>>>
>>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> Tel: +31 (0)84 420 2397
>>>> Fax: +31 (0)84 225 9307
>>>> Mail: mtaal@springsite.com - mtaal@elver.org
>>>> Web: www.springsite.com - www.elver.org
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> Tel: +31 (0)84 420 2397
>> Fax: +31 (0)84 225 9307
>> Mail: mtaal@springsite.com - mtaal@elver.org
>> Web: www.springsite.com - www.elver.org
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:Teneo and Hibernate's Session.load() issue
Next Topic:[Announce] EMFT COMPARE 0.8.0 M200808010333 is available
Goto Forum:
  


Current Time: Fri Dec 19 01:35:46 GMT 2014

Powered by FUDForum. Page generated in 0.06220 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software