Hibernate exception PropertyNotFoundException when using Transformer

前端 未结 2 675
攒了一身酷
攒了一身酷 2020-12-17 07:05

I\'m using hibernate and hql for querying in my Java codes. But I got an exception like this:

Caused by: org.hibernate.PropertyNotFoundException: Could not f         


        
相关标签:
2条回答
  • 2020-12-17 07:42

    Problem found:

    Even if the HQL can be translated to sql correctly, but when ResultTransformer gets the result, there will be only 3 fields in the result:

    1. A
    2. length
    3. unit
    

    No matter how many fields in A, they will be aggregated into a single field "A" and since I didn't set any alias to this field, it will be treated as "field 0".

    So the problem solved after I changed the HQL like this:

    select a.id as id, a.name as name, sum(c.length) as length, min(c.unit) as unit
    from A a
    left outer join a.b as b
    left outer join b.c as c
    group by
    a.id
    a.name
    
    0 讨论(0)
  • 2020-12-17 07:52

    @Access(AccessType.FIELD)

    add getter and setter of every field

     @Entity
        @Table(name="A")
        @Access(AccessType.FIELD)
        class A
        {
            @Id
            @Column(name="A_ID", updatable=false)
            private Long id;
    
           public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id= id;
        }
    }
    
    0 讨论(0)
提交回复
热议问题