You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Ahad javadi (JIRA)" <ji...@apache.org> on 2010/10/11 09:03:32 UTC

[jira] Created: (OPENJPA-1829) Problem using subclass object as query parameter

Problem using subclass object as query parameter
------------------------------------------------

                 Key: OPENJPA-1829
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1829
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 1.2.2
            Reporter: Ahad javadi


OpenJPA has a bug when using inheritance feature and using subclass as query parameter 
here is test case


@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() 


---------------------------------------
I am using openJPA 1.2.1 and I also have tested it with 1.2.2 . It doesn't work with both of them. 
I have tested it with runtime and build time enhancement.The problem exists with both. 
and my persistence.xml is something like this 

-------------------------------------------------------------------------------------------------------------- 
<property name="openjpa.jdbc.DBDictionary" value="oracle(batchLimit=0)" /> 
<property name="openjpa.jdbc.SynchronizeMappings" 
                                value="buildSchema(foreignKeys=true,schemaAction='none')" /> 
<property name="openjpa.jdbc.MappingDefaults" 
                                value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict" /> 

<property name="openjpa.RestoreState" value="all" /> 

<!-- Logging --> 
<property name="openjpa.Log" value="Tool=INFO,SQL=TRACE" /> 

<property name="openjpa.TransactionMode" value="managed" /> 
------------------------------------------------------------------------------------------------------- 

Any way I have tested it without any openJPA specific configuration and 
I am sure enhancement was done on the entities(I checked it by decompiling) 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.