org.hibernate.QueryException: not an association


Jones

I want to add order by restricting a condition in Hibernate. I have two tables Event and MainEvent with a one-to-many relationship (MainEvent has many events).

    final Criteria criteria = getCurrentSession().createCriteria(
            Event.class);
    criteria.createAlias("mainEvent.date", "deadline");
    criteria.addOrder(Order.asc("deadline"));
    return criteria.list();

When I try to run this command I get the following error:

org.hibernate.QueryException: Not associated with: Date.

MainEvent entity:

@Entity
@Table(name = "MAIN_EVENT")
public class MainEventEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "MAIN_EVENT_ID")
    private int id;

    @Column(name = "MAIN_EVENT_DATE")
    private Date date;

    @OneToMany(mappedBy = "mainEvent", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<EventEntity> events = new ArrayList<EventEntity>();

}

Event entity:

@Entity
@Table(name = "EVENT")
public class EventEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "EVENT_ID")
    private int id;

    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "MAIN_EVENT_ID", nullable = false)
    private MainEventEntity mainEvent;

}
Caitanya

According to the API of Criteria.createAlias , you can only create aliases for associations , not for association fields .

createAlias

Criteria createAlias(String associationPath,
                     String alias)
                     throws HibernateException
Join an association, assigning an alias to the joined association.



Parameters:
associationPath - A dot-seperated property path
alias - The alias to assign to the joined association (for later reference).
Returns:
this (for method chaining)

Related


Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property

South Africa I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property

Chen Yuhua I want to get the sum of a column in a table. public class PaymentLogDAO extends AbstractModel<PaymentLog> { public PaymentLogDAO() { super(PaymentLog.class); } public BigDecimal sum(String keyword) { try {

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp