Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] embedded objects with null values / next try

Hello James,
thanks. We use a DescriptorCustomizer in this case
#######
public class DescriptorCustomizerEmbeddedNullAllowed implements
    org.eclipse.persistence.config.DescriptorCustomizer {

  public void customize(ClassDescriptor descriptor) throws Exception {

    Vector<DatabaseMapping> mappings = descriptor.getMappings();
    for (DatabaseMapping mapping : mappings) {
      if (mapping instanceof AggregateObjectMapping) {
        ((AggregateObjectMapping) mapping).allowNull();
      }
    }

  }
}
In persistence.xml:
      <property name="eclipselink.descriptor.customizer.ItemEffortDSP" value="com.ottogroup.buying.sharedkernel.base.eclipselink.DescriptorCustomizerEmbeddedNullAllowed" />
#######
but unfortunately, despite of the customizer we get the same exception.

I found a link: https://forums.oracle.com/forums/thread.jspa?threadID=2224339
There, it sounds like allowNull is not possible anymore (in case of relationships in embedabbles) - can that be true?
In my opinion, this change would not be acceptable...

Best regards, Markus




-----Ursprüngliche Nachricht-----
Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] Im Auftrag von James Sutherland
Gesendet: Donnerstag, 8. September 2011 17:34
An: eclipselink-users@xxxxxxxxxxx
Betreff: Re: [eclipselink-users] embedded objects with null values


The default for allowNull was changed for embeddable with relationships, as
it cannot be determined if the relationship is null, so from the row it is
unknown if the embeddable is null or not (EclipseLink cannot tell the
difference from a null versus an empty object).

Either initialize the value to not null.  Or use a DescriptorCustomizer to
set the mapping to allow null.


markus hahn wrote:
> 
> 
> Hi folks, 
> we encounter problems with embeddables. 
> Lets say we have this class Purchase like in EL test suite: a class with
> an embedabble which itself contains a relation (currency). 
> &#8230; 
> @Entity 
> public class Purchase { 
>  @Id 
>  @GeneratedValue 
>  private int id; 
>  
>  @AttributeOverride( 
> 
> name=amount, 
> 
> column=@Column(name=FEE_AMOUNT,
> nullable=true)) 
>  @AssociationOverride( 
> 
> name=currency, 
> 
> joinColumns=@JoinColumn(name=FEE_ID, nullable=true))) 
>  @Embedded 
>  private Money fee; 
>  
>  public int getId() { 
>  return id; 
>  } 
>  
>  public Money getFee() { 
>  return fee; 
>  } 
>  
>  public void setFee(Money fee) { 
>  this.fee = fee; 
>  } 
>  
> In our use cases, we create Purchase with the embedded money = null
> (business logic says we add price later&#8230;). This should be legal
> because we defined all contained attributes as nullable. But we get an
> exception: 
> Exception [EclipseLink-68] (Eclipse Persistence Services -
> 2.1.2.v20101206-r8635):
> org.eclipse.persistence.exceptions.DescriptorException 
> &nbsp; Exception Description: The value of an aggregate in object
> [anObject] is null.&nbsp; Null values not allowed for Aggregate mappings
> unless &quot;Allow Null&quot; is specified. 
> &nbsp; 
> In EL 1.x.x this worked? 
> How can we get things working? 
> &nbsp; 
> Thanks in advance, Markus 
> &nbsp; 
> &nbsp; 
> &nbsp; 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/embedded-objects-with-null-values-tp32407678p32424806.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
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


Back to the top