-->
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.  [ 6 posts ] 
Author Message
 Post subject: Inheritence of Embedded objects (@Embeddable)
PostPosted: Wed Oct 18, 2006 6:44 pm 
Newbie

Joined: Wed Oct 18, 2006 6:34 pm
Posts: 4
Hi there @Hibernate (must be a pretty often repeated joke in here...)

I have an @Embeddable object AllocationId which extends another @Embeddable
object (GenericId). AllocationId, is simply a marker class and has NO attributes in it,
while all attributes (String id; which I want to persist) are in GenericId (inherited in AllocationId).

I get the following exception:

Code:
org.hibernate.AnnotationException: com.xxx.yyy.AllocationId has no persistent id property
        at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1714)
        at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1171)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:706)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1207)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:844)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:382)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
        at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:102)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
        at sun.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Any Ideas ?

Code snippets as follow:

Code:
@Embeddable
public final class AllocationId extends GenericId {

   // ... serial UID here - removed as considered somewhat sensitive ...

    /**
     * @param id
     */
    public AllocationId(final String id) {
        super(id);
    }
}

Code:

@Embeddable
public abstract class GenericId implements Serializable {

    /**
     * The actual Id
     */
    protected String id; // THIS IS NOT BEING 'SEEN' AS INSIDE AllocationId

    /**
     * Constructor to create a generic Id.
     * Syntactic checks are performed here (not null and empty string)
     *
     * @param allocationId The allocation Id
     */
    protected GenericId(final String id) {
        validate(id);
        this.id = id;
    }

    /**
     * Performs syntactic checking of the generic id
     *
     * @param id may not be null or empty ""
     */
    private void validate(final String id) throws IllegalArgumentException {

        if (id == null) {
            throw new IllegalArgumentException("id cannot be null");
        }
        if (id.trim().length() == 0) {
            throw new IllegalArgumentException("id cannot be length 0");
        }
    }

    /**
     * @return the id
     */
    public String getId() {
        return this.id;
    }

    @Override
    public String toString() {
        return getId();
    }

    // some less interesting code here .equals overrides etc.
}


Let me know.

Many Thanks - for your attention and for your GREAT product,
Malta (MT).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 5:26 pm 
Newbie

Joined: Wed Oct 18, 2006 6:34 pm
Posts: 4
My dear self,

This wasn't that hard after all:

Code:
@MappedSuperclass
public abstract class GenericId implements Serializable {
   // rest of the broth...

}



You need to explicitly use the hibernate specific @MappedSuperclass - otherwise all super classes will be ignored.

Also note that this is not official EJB3 spec, but rather Hibernate extensions - so you are marrying Hibernate (which isn't too bad I guess)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 8:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
correct
Something that is not possible (read not tested nor supported) is to have a class both @Embeddable and @MappedSuperclass (ie inherited).
But I guess this kind of case is pretty uncommon

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 4:46 am 
Newbie

Joined: Wed Oct 18, 2006 6:34 pm
Posts: 4
Emmanuel,

do you see this as a shortcoming in the EJB3 spec ?

how come something as @MappedSuperclass didn't make it to the spec ? I would think that Id (and embeddable object) inheritence would be pretty much the common case rather than the exception.

cheers
JP


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 11:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no
@MappedSuperclass *is* in the spec and is usable for @Entity superclasses
@MappedSuperclass usable for @Embeddable superclasses is an hibernate extension (sowewhat useful I thing)
@MappedSuperclass and @Entity on the same class or @MappedSuperclass and @Embeddable on the same class or @Entity and @Embeddable on the same class are not supported by the spec nor Hibernate Annotations

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Inheritence of Embedded objects (@Embeddable)
PostPosted: Tue Jan 19, 2010 10:31 am 
Newbie

Joined: Wed Oct 18, 2006 6:34 pm
Posts: 4
Looks like all of a sudden (4 years down the line) this is supported (both @MappedSuperclass and @Embeddable) because we were having problems (attribute was null in the database) and when we marked the class with both annotations it worked.

Some development there.
JP


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.