Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Embeddables, association-override and cascade-merge

okay:
* i have a entity ItemOption, a Entity Currency and an Embeddable Money
* ItemOption has several properties of type Money
* Money has a property of type Currency
* finding/persisting/deleting-Operations with Entities in persistence-layer
on server, manipulating Entities can take place at a client 
* everytime i call methods in my persistence-layer spring opens a
transaction, leaving the layer commits the transaction
* now pseudo-code, i try to keep it as simple as possible:
--start transaction--
currency = query.getResultList().iterator.next();
currencyCopied = entityManager.copy(currency, copygroup);
--end transaction--
itemOption = new ItemOption();
money = new Money(amount, currencyCopied);
itemOption.setExampleMoney(money);
--start transaction--
ioAttached = entityManager.merge(itemOption);
flush();
ioCopied = entityManager.copy(ioAttached, copyGroup);
--end transaction--
//everythings fine i see the itemOption in database, the ioCopied is
detached
--start transaction--
anotherCurrency = query.getResultList().iterator.next();
anotherCurrencyCopied = entityManager.copy(currency, copygroup);
--end transaction--
anotherMoney = new Money(anotherAmount, anotherCurrencyCopied );
ioCopied .setExampleMoney(anotherMoney);
--start transaction--
ioAttached = entityManager.merge(ioCopied);
flush();
---> now eclipselink tries to insert the currency into database ...


tware wrote:
> 
> I am not sure I understand what you are doing. It is not clear to me where
> your 
> transactions begin and end and where data gets sent to the DB.  Can you
> provide 
> some JPA-style pseudo code.
> 
> On 28/02/2012 12:24 PM, sr_dd wrote:
>>
>> Hi,
>>
>> i tried some more things with the information:
>> * the curreny-Object is an existing entity loaded from db.
>> * the creation of a new entity with a money-field works fine, when i hang
>> in
>> a Money-Object(the embeddable) with an existing currency-Object
>> * the saved entity is reloaded, transaction closed, em cleared.
>> * now i have the detached entity and another detached Currency loaded
>> from
>> db, out of the currency i create a new Money-Object(my embeddable) with
>> the
>> currency in it
>> * now updating the detached entity with setting the other money-Object
>> * new transaction + em.merge + flush brings me to an insert for currency.
>> this ends up in a db-Exception (integrity-constraint, because the id
>> already
>> exists).
>>
>> to the second question: props of persistence-unit
>>      <properties>
>>        <property name="eclipselink.weaving.changetracking" value="false"
>> />
>>        <property name="eclipselink.weaving" value="static" />
>>        <property name="eclipselink.weaving.lazy" value="true" />
>>        <property name="eclipselink.session.customizer"
>> value="sharedkernel.base.eclipselink.SessionCustomizer" />
>>        <property name="eclipselink.allow-zero-id" value="true" />
>>        <property name="eclipselink.cache.shared.default" value="false" />
>>      </properties>
>>
>> my properties
>>
>>
>> tware wrote:
>>>
>>> If you are getting an insert for currency, cascading is likely working.
>>> The
>>> issue seems to be that, for some reason, we do not know the Currency
>>> object you
>>> have created already exists.
>>>
>>> To what degree does the Currency object actually exist?  Does the insert
>>> result
>>> in a SQLException due to it's existence?
>>>
>>> How is your persistence unit defined?  Are you using any persistence
>>> unit
>>> properties related to caching or querying?
>>>
>>> -Tom
>>>
>>> On 28/02/2012 9:55 AM, sr_dd wrote:
>>>>
>>>> Hello,
>>>>
>>>> following problem:
>>>>
>>>> i have defined an embeddable with mapping:
>>>>     <orm:embeddable class="Money">
>>>>       <orm:attributes>
>>>>         <orm:basic name="amount"/>
>>>>         <orm:many-to-one name="currency"  fetch="LAZY">
>>>>         	<orm:join-column column-definition="decimal"
>>>> name="ID_CURRENCY"
>>>> referenced-column-name="ID"/>
>>>>         	<orm:cascade>
>>>>             <orm:cascade-merge />
>>>>           </orm:cascade>
>>>>         </orm:many-to-one>
>>>>       </orm:attributes>
>>>>     </orm:embeddable>
>>>> </orm:entity-mappings>
>>>>
>>>> Currency is specified as follows:
>>>>     <orm:entity class="Currency">
>>>>       <orm:table name="SYSP.CURRENCY"/>
>>>>       <orm:attributes>
>>>>         <orm:id name="id">
>>>>           <orm:column name="ID"/>
>>>>         </orm:id>
>>>>         <orm:basic name="name">
>>>>           <orm:column name="NAME" nullable="false"/>
>>>>         </orm:basic>
>>>> ...
>>>>       </orm:attributes>
>>>>     </orm:entity>
>>>>
>>>> in another mapping i use the embeddable:
>>>> <orm:embedded name="airfreightRisk">
>>>>           <orm:attribute-override name="amount">
>>>>             <orm:column name="AIRFREIGHTRISK" nullable="true" />
>>>>           </orm:attribute-override>
>>>>           <orm:association-override name="currency">
>>>>             <orm:join-column name="ID_CURRENCY_AIRFREIGHTRISK"
>>>> nullable="true"
>>>> referenced-column-name="ID" />
>>>>             <orm:cascade>
>>>>             <orm:cascade-merge />
>>>>           </orm:cascade>
>>>>           </orm:association-override>
>>>>         </orm:embedded>
>>>>
>>>> In my CLF Test i create a new Entity and set the Attribute
>>>> airfreightRisk
>>>> with a Money-Object which carries a loaded and already persisted
>>>> Currency-Object.
>>>>
>>>> Trying to persist the new Entity brings me to the following problem:
>>>> * everything works fine staying attached.
>>>> * building the Object-Tree with detached Objects and merge the whole
>>>> tree
>>>> results in an insert for currency
>>>> -->   the cascade-merge in embeddables seems not to work?!
>>>>
>>>> Any ideas?
>>>>
>>>> Stefan
>>>>
>>>>
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>
>>>
>>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 

-- 
View this message in context: http://old.nabble.com/Embeddables%2C-association-override-and-cascade-merge-tp33407178p33422434.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top