-->
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: CGLIB and interfaces
PostPosted: Fri May 12, 2006 7:30 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
I have a parent abstract java class that implements an interface with child objects that each implement their own interfaces. Each of the child interfaces extends the partens interface.

Where I run this:

Offending Java code:
Code:
   
    public ZoneDesignationEZFacade getZoneDesignationEz() {
        Iterator i = this.zoneDesignations.iterator();
       
        while ( i.hasNext() ) {
            ZoneDesignationFacade designation = (ZoneDesignationFacade)i.next();
            if ( designation instanceof ZoneDesignationEZFacade ) {
                return (ZoneDesignationEZFacade)designation;
            }           
        }       
        return null;
    }


It returns items that are not instances of ZoneDesignationEZFacade, it will return any ZoneDesignation.

When I debug it the proxied designation has in its interfaces property references to all parent and child interfaces. So it gets returned even if its underlying type only implements one interface.

How do I get it to only return when the underlying class implements the given interface.

Thank you for your time and any help you maybe able to offer.

Hibernate version:

3.1.3

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="com.ccg.domain.ZoneDesignation"
table="zoneDesignation"
proxy="com.ccg.domain.ZoneDesignationFacade"
>

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="identity">
</generator>
</id>

<discriminator
column="type"
/>

<property
name="designation"
type="date"
column="designation"
/>

<property
name="expiration"
type="date"
column="expiration"
/>

<property
name="name"
type="string"
column="name"
/>

<property
name="alias"
type="string"
column="alias"
/>

<many-to-one
name="parentZone"
class="com.ccg.domain.Zone"
cascade="none"
outer-join="false"
column="zoneId"
not-null="true"
/>
<subclass
name="com.ccg.domain.ZoneDesignationTTA"
proxy="com.ccg.domain.ZoneDesignationTTAFacade"
>
</subclass>
<subclass
name="com.ccg.domain.ZoneDesignationEZ"
proxy="com.ccg.domain.ZoneDesignationEZFacade"
>
</subclass>
<subclass
name="com.ccg.domain.ZoneDesignationLARZ"
proxy="com.ccg.domain.ZoneDesignationLARZFacade"
>
</subclass>

</class>

</hibernate-mapping>
POJO's
Code:

package com.ccg.domain;

import java.util.Date;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

public abstract class ZoneDesignation extends Persistent implements ZoneDesignationFacade {

   protected String name;
   protected String alias;
   protected Date designation;
   protected Date expiration;
        protected Zone parentZone;

   public  ZoneDesignation() {
    }
   

   public Date getDesignation() {
      return designation;
   }
   

   public void setDesignation(Date designation) {
      this.designation = designation;
   }
   

   public Date getExpiration() {
      return expiration;
   }
   

   public void setExpiration(Date expiration) {
      this.expiration = expiration;
   }
   

   public String getName() {
      return name;
   }
   
   public void setName(String name) {
      this.name = name;
   }
   

   public String getAlias() {
      return alias;
   }

   public void setAlias(String alias) {
      this.alias = alias;
   }
   

    public Zone getParentZone() {
        return this.parentZone;
    }

    public void setParentZone(Zone parentZone) {
        this.parentZone = parentZone;
    }

   public boolean equals(Object o) {
        if ( !(o instanceof ZoneDesignation ) ) {
            return false;
        }
       
        ZoneDesignationFacade z = (ZoneDesignationFacade) o;       
        return new EqualsBuilder()
            .append(name, z.getName())
            .append(alias, z.getAlias())
            .append(parentZone.getId(), z.getParentZone().getId())
            .append(designation, z.getDesignation())
            .append(expiration, z.getExpiration())
            .isEquals();
   }
   
    public int hashCode() {       
        return new HashCodeBuilder()
            .append(name)
            .append(alias)
            .append(parentZone.getId())
            .append(designation)
            .append(expiration)
            .toHashCode();
    }
   
    public String toString() {
        return new ToStringBuilder(this)
            .append("name", name)
            .append("alias", alias)
            .append("parentZoneAlias", parentZone.getAlias())
            .append("designation", designation)
            .append("expiration", expiration)
            .toString();
    }
}

package com.ccg.domain;

import java.util.Date;

public interface ZoneDesignationFacade extends PersistentFacade{

   public abstract Date getDesignation();

   public abstract void setDesignation(Date designation);

   public abstract Date getExpiration();

   public abstract void setExpiration(Date expiration);

   public abstract String getName();

   public abstract void setName(String name);

   public abstract String getAlias();

   public abstract void setAlias(String alias);

   public abstract Zone getParentZone();

   public abstract void setParentZone(Zone parentZone);

   public abstract boolean equals(Object o);

   public abstract int hashCode();

   public abstract String toString();

}

package com.ccg.domain;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

public class ZoneDesignationEZ extends ZoneDesignation implements ZoneDesignationEZFacade {

   private static final long serialVersionUID = 1L;


   public ZoneDesignationEZ() { }
   
    public boolean equals(Object o) {
        if ( !(o instanceof ZoneDesignationEZ ) ) {
            return false;
        }
       
        ZoneDesignationEZ z = (ZoneDesignationEZ) o;       
        return new EqualsBuilder()
            .appendSuper(super.equals(o))
            .append(parentZone.getId(), z.parentZone.getId())
            .isEquals();
    }

   
    public String toString() {
        return new ToStringBuilder(this)
            .appendSuper(super.toString())
            .append("parentZone", parentZone)
            .toString();
    }

   
    public int hashCode() {
        return new HashCodeBuilder()
            .appendSuper(super.hashCode())
            .append(parentZone)
            .toHashCode();
    }
}

package com.ccg.domain;

public interface ZoneDesignationEZFacade extends ZoneDesignationFacade{

   public abstract boolean equals(Object o);

   public abstract String toString();

   public abstract int hashCode();

}


Name and version of the database you are using:
mySQL 4.0


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