[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4278) Polymorphic query on abstract function

radu (JIRA) noreply at atlassian.com
Wed Oct 21 02:23:30 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34246#action_34246 ] 

radu commented on HHH-4278:
---------------------------

I see that this issue was closed. But, if you can see implementation of function getCode() is different in classes Child1 and Child2, for this reason in base class was declared abstract.
I'm still waiting for a solution or answer to this problem.

> Polymorphic query on abstract function
> --------------------------------------
>
>                 Key: HHH-4278
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4278
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: annotations
>            Reporter: radu
>            Priority: Blocker
>
> I have the following classes adnnotated with hibernate:
> <pre><code>
> @Entity
> @Inheritance(strategy=InheritanceType.JOINED)
> public abstract class Symbol 
>     implements Serializable {
>     
>     @Id
>     @GeneratedValue(strategy = GenerationType.AUTO)
>     private Integer id;
>     @AccessType("property")
>     public abstract String getCode();
>     
>     @AccessType("property")
>     public abstract void setCode(String code);
>  }
>  
> @javax.persistence.Entity
> @AttributeOverride( name="code", column = @Column(name="field1") )
> public class Child1 extends Symbol {
>     
>     @Basic
>     @Column(nullable = false)
>     private String field1;
>     
>     @AccessType("property")
>     public String getCode() {
>         return getField1();
>     }
>     
>     @AccessType("property")
>     public void setCode(String code) {
>         setField1(code);
>     }
>     
>     public void setField1(String field1) {
>         this.field1 = field1;
>     }
>     public String getField1() {
>         return field1;
>     }
> }
> @javax.persistence.Entity
> @AttributeOverride( name="code", column = @Column(name="field2") )
> public class Child2 extends Symbol {
>     
>     @Basic
>     @Column(nullable = false)
>     private String field2;
>     
>     @AccessType("property")
>     public String getCode() {
>         return getField2();
>     }
>     
>     @AccessType("property")
>     public void setCode(String code) {
>         setField1(code);
>     }
>     
>     public void setField1(String field2) {
>         this.field2 = field2;
>     }
>     public String getField2() {
>         return field2;
>     }
> }
> </code></pre>
> As objectual rules about polymorphisms the following query should be valid and to retrieve correct field value:
> session.createQuery("from Symbol s where s.code = :code");
> but it give me the error:
> org.hibernate.QueryException: could not resolve property: code of: ...
> Please give some advices how to work around this problem if this situation does not follow hibernate concept or JPA specs and is not possible to implement it.
> Idea is that it should be possible to work at hight level without changing database or existing classes.
> Thanks

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list