Hello everyone
I have a problem using inheritance in OpenJPA.
Here is my code 


@Entity
@Table(name = "BASEBRN")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="TYPE",discriminatorType=DiscriminatorType.INTEGER)
public class BaseBranch  {

        @Id
        @Column(name = "BASEID")
        private Long id;

        @Column(name="TYPE")
        @Enumerated(value = EnumType.ORDINAL)
        private BaseBranchType baseBranchType;

        public BaseBranch(Long id) {
                this.id = id;
        }

        public BaseBranch() {
                super();
        }

        public Long getId() {
                return id;
        }

        public void setId(Long id) {
                this.id = id;
        }

        
        public BaseBranchType getBaseBranchType() {
                return baseBranchType;
        }

        public void setBaseBranchType(BaseBranchType baseBranchType) {
                this.baseBranchType = baseBranchType;
        }       

        @Override
        public boolean equals(Object object) {
                if (object != null && !(object instanceof BaseBranch))
                        return false;
                BaseBranch other = (BaseBranch) object;
                if (this.id != null && other.id != null
                                && (this.id.longValue() == 
other.id.longValue()))
                        return true;
                return false;

        }

        @Override
        public int hashCode() {
                int hashCode = 0;
                if (id != null)
                        hashCode += id.hashCode();
                return hashCode;
        }

}
--------------------------------------------------------------------------------------------

@Table(name = "BRANCH")
@DiscriminatorValue("1")
@PrimaryKeyJoinColumn(name="BRANCHID", referencedColumnName="BASEID")
public class Branch extends BaseBranch {

        @Column(name = "CODE")
        private String code;

        public Branch() {

        }

        public Branch(Long id) {
                this.setId(id);
        }

        public Branch(String code) {
                this.code = code;
        }


    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Branch other = (Branch) obj;
        if ((this.getId() == null) ? (other.getId() != null) :
!this.getId().equals(other.getId())) {
            return false;
        }
        return true;
    }


    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + (this.getId() != null ? this.getId().hashCode() :
0);
        return hash;
    }


}

------------------------------------------------------------------------------------
After runing this code block 

Query q = entityManager.createNamedQuery(""select b from Branch b where
b=:branch"");
q.setParameter("branch", new Branch(1L));
b=q.getResultList();

-----------------------------------------------------------------
result query is something like this

 SELECT t1.BASEID, t1.TYPE, t0.CODE FROM BRANCH t0, BASEBRN t1 WHERE (1 <>
1) AND t1.TYPE = ? AND t0.BRANCHID = t1.BASEID [params=(int) 1]
 ----------------------------------------------------------------
 
 
 OpenJPA never takes the parameter and always raises NoResultException.
 It seems for openJPA both following two params are the same .
 new Branch(1L) 
 and  
 new Branch()
 
 What's wrong with my code or is this maybe an openJPA bug?
 Any idea or help is appreciated
 thanks

-- 
View this message in context: 
http://openjpa.208410.n2.nabble.com/problem-using-subclass-object-as-query-parameter-tp5506089p5506089.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to