Home Hibernate miss existing field
Reply: 0

Hibernate miss existing field

user2302
1#
user2302 Published in April 22, 2018, 12:34 am

I have such entity structure

@MappedSuperclass
public abstract class Base {
    UUID id;
}

@MappedSuperclass
public abstract class Parent<C extends Child> extends Base {
    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<C> children;
}

@MappedSuperclass
public abstract class Child<P extends Parent> extends Base {
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private P parent;
}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "ap")
public class AP extends Parent<AC> {}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "ac")
public class AC extends Child<AP> {}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "bp")
public class BP extends Parent<BC> {}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "bc")
public class BC extends Child<BP> {}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "cp")
public class CP extends Parent<CC> {}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "cc")
public class CC extends Child<CP> {
     String value;
}

I do criteria query

    CriteriaQuery<Long> cq = getEntityManager().getCriteriaBuilder().createQuery(Long.class);
    Root<CP> rt = cq.from(CP.class);
    Path child = rt.join("children");
    final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
    cq.select(criteriaBuilder.count(rt));
    cq.where(criteriaBuilder.equal(child.get("value"), "exists"));
    TypedQuery<Long> q = getEntityManager().createQuery(cq);
    Long res = q.getSingleResult()

and get error on line with where clause:

java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [value] on this ManagedType [Base]

After debugging a while I've found out that Parent meta class in entity manager's meta model keeps property children as List of AC. AC obviously doesn't contains field "value".

Any idea how to fix this error?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301513 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO