-->
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.  [ 1 post ] 
Author Message
 Post subject: Validation of proxy declaration in mapping files is broken ?
PostPosted: Tue Mar 14, 2006 7:41 am 
Newbie

Joined: Tue Jan 25, 2005 3:03 am
Posts: 11
Location: Bangalore, India
Hi,

In a particular parent-child use case, my object graph looks like this :

Code:
[ParentImpl] <implements> [ParentInterface]
[ChildInterface] <extends> [ParentInterface]
[ChildImpl] <extends> [ParentImpl], <implements> [ChildInterface]

While mapping them as hibernate entities, I had specified "proxy=[ParentImpl]" for the parent class and "proxy=[ChildInterface]" for the child one. However, this resulted in Hibernate cribbing "org.hibernate.MappingException: proxy must be either an interface, or the class itself: [ChildImpl]". This looked strange since the proxy specified for child was indeed an interface (as mentioned above).

From the stack trace, I was able to get the piece of code that does this validation. Here is it, from org.hibernate.tuple.PojoTuplizer.buildProxyFactory(...),with my comments added :

Code:
    [...]
Class mappedClass = persistentClass.getMappedClass();
        Class proxyInterface = persistentClass.getProxyInterface();

        if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) {
            if ( !proxyInterface.isInterface() ) {
                throw new MappingException(
                        "proxy must be either an interface, or the class itself: " +
                        getEntityName()
                );
            }
            proxyInterfaces.add( proxyInterface );
        }

        if ( mappedClass.isInterface() ) {
            proxyInterfaces.add( mappedClass );
        }

        Iterator iter = persistentClass.getSubclassIterator();
        while ( iter.hasNext() ) {
            Subclass subclass = ( Subclass ) iter.next();
            Class subclassProxy = subclass.getProxyInterface();
            Class subclassClass = subclass.getMappedClass();

            // *** [Vikas S] : This correctly checks subclassProxy ***
            if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {

                // *** [Vikas S] : But why proxyInterface ??? Shouldn't this be subclassProxy ??? ***
                if ( !proxyInterface.isInterface() ) {
                    throw new MappingException(
                            "proxy must be either an interface, or the class itself: " +
                            subclass.getEntityName()
                    );
                }
                proxyInterfaces.add( subclassProxy );
            }
        }
      [...]


As mentioned in my inline comment, while iterating through the sub-class mappings it is validating proxyInterface (proxy defined for parent) instead of subclassProxy. Is this intended ??

_________________
Rgds,
Vikas.

"Quidquid latine dictum sit, altum sonatur".
Whatever is said in Latin, sounds profound


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.