-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Are optional embedded properties possible?
PostPosted: Tue Jul 08, 2008 11:27 am 
Newbie

Joined: Tue Jul 08, 2008 11:09 am
Posts: 12
I would like to use an @Embeddable object in my Entity, but it must be an optional (nullable) property.

My entity looks like this (besides some other regular properties):

Code:
    @Embeddable
    private static class Fubar {
        private String aap;
       
        String getAap(){
            return aap;
        }
       
        void setAap(String a) {
            aap = a;
        }
    }
   
    Fubar fu;
    @Embedded
    Fubar getFubar() {
        return fu;
    }
   
    void setFubar(Fubar bar) {
        fu = bar;
    }


When I persist my entity after having set a Fubar instance, it works fine.

But when I try to persist my entity with the embeddable object = null, I'm getting a NullPointerException:

Quote:
java.lang.NullPointerException
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:86)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:348)
at org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:556)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:366)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:195)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:228)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:193)


I can't really imagine that it's not allowed or possible to have an optional embedded property, or am I wrong?

How can I use an optional embedded property?


Cheers,
Tom


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 8:01 am 
Newbie

Joined: Tue Jul 08, 2008 11:09 am
Posts: 12
It appears to be a bug, that has been solved in Hibernate 3.2.6 and 3.3.0CR1:

http://opensource.atlassian.com/project ... e/HHH-2542

I was using 3.2.5.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.