Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
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). 
> … 
> @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…). 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 
>   Exception Description: The value of an aggregate in object
> [anObject] is null.  Null values not allowed for Aggregate mappings
> unless "Allow Null" is specified. 
>   
> In EL 1.x.x this worked? 
> How can we get things working? 
>   
> Thanks in advance, Markus 
>   
>   
>   
> 
> 


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



Back to the top