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

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
> 
> 

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



Back to the top