Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Contained eObject referenced by another eObject?
[Teneo] Contained eObject referenced by another eObject? [message #424531] Wed, 29 October 2008 15:54 Go to next message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------040107000901050302080802
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi

I've got this scenario:
Budget, BudgetLine, SetInicator, Indicator are all EObjects.


A Budget has a list of BudgetLine's. "budget.getBudgetLines" gives the
list of BudgetLine's. This reference is an explicit containment
(Cotainment = true)

The same goes for SetIndicator and Indicator, meaning that SetIndicator
has a list of Indicator's with a "Containment=true" reference.


Budget has a simple reference (not a list and not a containment) for a
SetIndicator (budget.getSetIndicator).

BudgetLine has a simple reference(not a list and not a containment) for
an Indicator.


When I try to save a Budget I get the exception attached in case1.txt.

CASE 2: If I put:
CASCADE_POLICY_ON_CONTAINMENT = "REMOVE,REFRESH,PERSIST,MERGE" then
saving works but deleting a Budget won't work - I suppose I should
manually delete BudetLines but then again it's not practical 'cause I
should change too much.
Yet another trick in this case is that apparently the Indicator looses
its relation to the SetIndicator in that it is no longer contained in it.

NOTE: SET_CASCADE_ALL_ON_CONTAINMENT is not set in neither cases.


Question: Can a contained eObject (Indicator whitch s contained by
SetIndicator) be referenced from another eObject (BudgetLine whitch
itself is contained by Budget) without changing the relationship between
the Indicator and the SetIndicator?


Many thanks
Liviu


--------------040107000901050302080802
Content-Type: text/plain;
name="case1.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="case1.txt"

org.eclipse.emf.teneo.hibernate.HbMapperException: Exception when saving resource AgentiDataStore
at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:364)
at org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou rce.java:396)
at ro.spad.client.conta.buget.editors.FisaBugetEditor$9.execute (FisaBugetEditor.java:696)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(Worksp aceModifyOperation.java:104)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1800)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(Workspac eModifyOperation.java:116)
at org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:121)
Caused by: org.hibernate.exception.ConstraintViolationException: could not delete: [Indicator#917504]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateCo nverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExce ptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.delet e(AbstractEntityPersister.java:2546)
at org.hibernate.persister.entity.AbstractEntityPersister.delet e(AbstractEntityPersister.java:2702)
at org.hibernate.action.EntityDeleteAction.execute(EntityDelete Action.java:77)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue. java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue. java:172)
at org.hibernate.event.def.AbstractFlushingEventListener.perfor mExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(De faultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.eclipse.emf.teneo.hibernate.HbSessionWrapper.flush(HbSes sionWrapper.java:161)
at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:358)
... 6 more
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationE xception: Cannot delete or update a parent row: a foreign key constraint fails (`spad/liniebuget`, CONSTRAINT `liniebuget_indicator` FOREIGN KEY (`indicator_indicator_myid`) REFERENCES `indicator` (`myid`))
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:101 1)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956 )
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:25 42)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedSta tement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:1922)
at org.hibernate.persister.entity.AbstractEntityPersister.delet e(AbstractEntityPersister.java:2528)
... 16 more

--------------040107000901050302080802--
Re: [Teneo] Contained eObject referenced by another eObject? [message #424545 is a reply to message #424531] Wed, 29 October 2008 19:45 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Liviu,
The answer on your question is yes it is possible to have references between two contained objects.

The default cascade for containment is ALL which also includes delete-orphan. So I think not setting
this option is the right approach. Then when Budget is deleted also its budgetlines are deleted and
when removing a budgetline from budget, the budgetline will be removed.

Regarding your exception. Looking at the stacktrace I think the following happened:
there is a reference from budgetline to an indicator, the indicator gets deleted (I am not sure
why), which is not possible because the budgetline refers ot it.
So the question is why the indicator gets deleted.

gr. Martin

Liviu wrote:
> Hi
>
> I've got this scenario:
> Budget, BudgetLine, SetInicator, Indicator are all EObjects.
>
>
> A Budget has a list of BudgetLine's. "budget.getBudgetLines" gives the
> list of BudgetLine's. This reference is an explicit containment
> (Cotainment = true)
>
> The same goes for SetIndicator and Indicator, meaning that SetIndicator
> has a list of Indicator's with a "Containment=true" reference.
>
>
> Budget has a simple reference (not a list and not a containment) for a
> SetIndicator (budget.getSetIndicator).
>
> BudgetLine has a simple reference(not a list and not a containment) for
> an Indicator.
>
>
> When I try to save a Budget I get the exception attached in case1.txt.
>
> CASE 2: If I put:
> CASCADE_POLICY_ON_CONTAINMENT = "REMOVE,REFRESH,PERSIST,MERGE" then
> saving works but deleting a Budget won't work - I suppose I should
> manually delete BudetLines but then again it's not practical 'cause I
> should change too much.
> Yet another trick in this case is that apparently the Indicator looses
> its relation to the SetIndicator in that it is no longer contained in it.
>
> NOTE: SET_CASCADE_ALL_ON_CONTAINMENT is not set in neither cases.
>
>
> Question: Can a contained eObject (Indicator whitch s contained by
> SetIndicator) be referenced from another eObject (BudgetLine whitch
> itself is contained by Budget) without changing the relationship between
> the Indicator and the SetIndicator?
>
>
> Many thanks
> Liviu
>


--

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] Contained eObject referenced by another eObject? [message #424547 is a reply to message #424545] Wed, 29 October 2008 20:10 Go to previous messageGo to next message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
Hi Martin,

Thanks - I will reanalyze I might have omitted something.
I think your assumption is correct in regards to the deletion of the
Indicator - looking at the consoleLog I did see that the
hibernateResource.save tried to delete it and I thought that it was
related to the containment - hence my initial post. It was not included
in the removedEObjects list from HibernateResource.saveResource though.

I'll be back should I find a solution next 6 hours otherwise I will
condiser a model change and when I get the time I will try producing a
testcase for this.

Until then please accept the symbol of my deepest consideration,
Liviu

Martin Taal wrote:
> Hi Liviu,
> The answer on your question is yes it is possible to have references
> between two contained objects.
>
> The default cascade for containment is ALL which also includes
> delete-orphan. So I think not setting this option is the right approach.
> Then when Budget is deleted also its budgetlines are deleted and when
> removing a budgetline from budget, the budgetline will be removed.
>
> Regarding your exception. Looking at the stacktrace I think the
> following happened:
> there is a reference from budgetline to an indicator, the indicator gets
> deleted (I am not sure why), which is not possible because the
> budgetline refers ot it.
> So the question is why the indicator gets deleted.
>
> gr. Martin
>
> Liviu wrote:
>> Hi
>>
>> I've got this scenario:
>> Budget, BudgetLine, SetInicator, Indicator are all EObjects.
>>
>>
>> A Budget has a list of BudgetLine's. "budget.getBudgetLines" gives the
>> list of BudgetLine's. This reference is an explicit containment
>> (Cotainment = true)
>>
>> The same goes for SetIndicator and Indicator, meaning that SetIndicator
>> has a list of Indicator's with a "Containment=true" reference.
>>
>>
>> Budget has a simple reference (not a list and not a containment) for a
>> SetIndicator (budget.getSetIndicator).
>>
>> BudgetLine has a simple reference(not a list and not a containment) for
>> an Indicator.
>>
>>
>> When I try to save a Budget I get the exception attached in case1.txt.
>>
>> CASE 2: If I put:
>> CASCADE_POLICY_ON_CONTAINMENT = "REMOVE,REFRESH,PERSIST,MERGE" then
>> saving works but deleting a Budget won't work - I suppose I should
>> manually delete BudetLines but then again it's not practical 'cause I
>> should change too much.
>> Yet another trick in this case is that apparently the Indicator looses
>> its relation to the SetIndicator in that it is no longer contained in it.
>>
>> NOTE: SET_CASCADE_ALL_ON_CONTAINMENT is not set in neither cases.
>>
>>
>> Question: Can a contained eObject (Indicator whitch s contained by
>> SetIndicator) be referenced from another eObject (BudgetLine whitch
>> itself is contained by Budget) without changing the relationship between
>> the Indicator and the SetIndicator?
>>
>>
>> Many thanks
>> Liviu
>>
>
>
Re: [Teneo] Contained eObject referenced by another eObject? [message #425366 is a reply to message #424547] Sat, 22 November 2008 17:34 Go to previous message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
Hi Martin,

I did not have to change the model.

It seemed that it was a problem becous I used one session to create the
object I wanted to save but some of its references were loaded through
another session.

Thanks again
Liviu


Liviu wrote:
> Hi Martin,
>
> Thanks - I will reanalyze I might have omitted something.
> I think your assumption is correct in regards to the deletion of the
> Indicator - looking at the consoleLog I did see that the
> hibernateResource.save tried to delete it and I thought that it was
> related to the containment - hence my initial post. It was not included
> in the removedEObjects list from HibernateResource.saveResource though.
>
> I'll be back should I find a solution next 6 hours otherwise I will
> condiser a model change and when I get the time I will try producing a
> testcase for this.
>
> Until then please accept the symbol of my deepest consideration,
> Liviu
>
> Martin Taal wrote:
>> Hi Liviu,
>> The answer on your question is yes it is possible to have references
>> between two contained objects.
>>
>> The default cascade for containment is ALL which also includes
>> delete-orphan. So I think not setting this option is the right approach.
>> Then when Budget is deleted also its budgetlines are deleted and when
>> removing a budgetline from budget, the budgetline will be removed.
>>
>> Regarding your exception. Looking at the stacktrace I think the
>> following happened:
>> there is a reference from budgetline to an indicator, the indicator gets
>> deleted (I am not sure why), which is not possible because the
>> budgetline refers ot it.
>> So the question is why the indicator gets deleted.
>>
>> gr. Martin
>>
>> Liviu wrote:
>>> Hi
>>>
>>> I've got this scenario:
>>> Budget, BudgetLine, SetInicator, Indicator are all EObjects.
>>>
>>>
>>> A Budget has a list of BudgetLine's. "budget.getBudgetLines" gives the
>>> list of BudgetLine's. This reference is an explicit containment
>>> (Cotainment = true)
>>>
>>> The same goes for SetIndicator and Indicator, meaning that SetIndicator
>>> has a list of Indicator's with a "Containment=true" reference.
>>>
>>>
>>> Budget has a simple reference (not a list and not a containment) for a
>>> SetIndicator (budget.getSetIndicator).
>>>
>>> BudgetLine has a simple reference(not a list and not a containment) for
>>> an Indicator.
>>>
>>>
>>> When I try to save a Budget I get the exception attached in case1.txt.
>>>
>>> CASE 2: If I put:
>>> CASCADE_POLICY_ON_CONTAINMENT = "REMOVE,REFRESH,PERSIST,MERGE" then
>>> saving works but deleting a Budget won't work - I suppose I should
>>> manually delete BudetLines but then again it's not practical 'cause I
>>> should change too much.
>>> Yet another trick in this case is that apparently the Indicator looses
>>> its relation to the SetIndicator in that it is no longer contained in it.
>>>
>>> NOTE: SET_CASCADE_ALL_ON_CONTAINMENT is not set in neither cases.
>>>
>>>
>>> Question: Can a contained eObject (Indicator whitch s contained by
>>> SetIndicator) be referenced from another eObject (BudgetLine whitch
>>> itself is contained by Budget) without changing the relationship between
>>> the Indicator and the SetIndicator?
>>>
>>>
>>> Many thanks
>>> Liviu
>>>
>>
Previous Topic:[CDO] Some thoughts on enhancements
Next Topic:[TENEO] @GenericGenerator(name="hibseq", strategy = "hilo"...
Goto Forum:
  


Current Time: Fri Apr 19 07:07:07 GMT 2024

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

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

Back to the top