-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Criteria for complex object
PostPosted: Wed Nov 08, 2006 5:47 am 
Newbie

Joined: Fri Sep 15, 2006 6:07 am
Posts: 5
Hi,
I have the following classes, the mapping with hibernate works fine but when i try to fetch by criteria as follows:
Code:
Criteria criteria = session.createCriteria(Alarm.class);

criteria.add(Expression.eq("alarmDetails.status.id", 1L));


I get the following error: org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: alarmDetails.status.id of: Alarm; nested exception is org.hibernate.QueryException: could not resolve property: alarmDetails.status.id of:

Code:

public class Alarm
{
    private AlarmDetails alarmDetails;

    public AlarmDetails getAlarmDetails()
    {
        return alarmDetails;
    }

    public void setAlarmDetails(AlarmDetails alarmDetails)
    {
        this.alarmDetails = alarmDetails;
    }
}


public class AlarmDetails
{
    private Status status;

    public Status getStatus()
    {
        return status;
    }

    public void setStatus(Status status)
    {
        this.status = status;
    }
}


public class Status
{
    private long id;

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }
}


when i create the following criteria:

Code:
Criteria criteria = session.createCriteria(Alarm.class);

criteria.add(Expression.eq("alarmDetails.status.id", 1L));


I get: org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: alarmDetails.status.id of: Alarm; nested exception is org.hibernate.QueryException: could not resolve property: alarmDetails.status.id of:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 11:35 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
I've seen confusion when attempting to use nested properties with Criteria so try
Code:
Criteria criteria = session.createCriteria(Alarm.class);
criteria.addAlias("alarmDetails", "ad");
criteria.addAlias("ad.status", "s");
criteria.add(Expression.eq("s.id", 1L));


I'm assuming your mapping files mirror the POJO classes but you should check them.

Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 09, 2006 8:24 am 
Newbie

Joined: Fri Sep 15, 2006 6:07 am
Posts: 5
Hi Curtis
Tnx for the fast replay. your suggestion works fine.

Guy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.