2010-11-27 7 views
0

Ich stoße auf ein Problem beim Ausführen einer Abfrage oder eines gelöschten Kriteriums auf einem eingebetteten Objekt. Ich habe versucht beides von this related question angegangen, keiner scheint zu funktionieren.Hibernate: Problem bei der Ausführung von Abfragen/gelöschten Kriterien für das eingebettete Objekt

Der Fehler Ich erhalte ist:

org.hibernate.QueryException: could not resolve property: location.Longitude of: org.project.model.Event [select c from org.project.model.Event as c WHERE c.location.Longitude between :minLongitude AND :maxLongitude] 
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67) 
at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:82) 
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54) 
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1367) 
... 

Hier ist mein Code:

@Entity 
@Table(name = "Events") 
public class Event extends Identifiable { 
    private Location location; 
    private DateTime createdTS; 

    @Embedded 
    public Location getLocation() { 
     return location; 
    } 

    public Event setLocation(Location location) { 
     this.location = location; 
     return this; 
    } 

    @Column(name = "Created") 
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime") 
    public DateTime getCreatedTS() { 
     return createdTS; 
    } 

    public Event setCreatedTS(DateTime createdTS) { 
     this.createdTS = createdTS; 
     return this; 
    } 
} 

und diese

@Embeddable 
public class Location { 
    private double longitude; 
    private double latitude; 

    public Location(double longitude, double latitude) { 
     setLongitude(longitude); 
     setLatitude(latitude); 
    } 

    public Location() {} 

    @Column(name = "Longitude") 
    public double getLongitude() { 
     return longitude; 
    } 

    public void setLongitude(double longitude) { 
     this.longitude = longitude; 
    } 

    @Column(name = "Latitude") 
    public double getLatitude() { 
     return latitude; 
    } 

    public void setLatitude(double latitude) { 
     this.latitude = latitude; 
    } 
} 

Ich habe mit einer Abfrage versucht:

Query q = session.createQuery("select c from Event as c WHERE c.location.Longitude between :minLongitude AND :maxLongitude"); 
q.setParameter("minLongitude", minLongitude); 
q.setParameter("maxLongitude", maxLongitude); 
return (List<Event>)q.list(); 

Und mit einem DetachedCriteria:

final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Event.class); 
detachedCriteria.add(Restrictions.between("Location.Longitude", minLongitude, maxLongitude)); 
detachedCriteria.add(Restrictions.between("Location.Latitude", minLatitude, maxLatitude)); 
Criteria criteria = detachedCriteria.getExecutableCriteria(session); 
return (List<Event>) criteria.list(); 

Antwort

1

Immobilien in HQL Groß- und Kleinschreibung, die Sie benötigen location.longitude statt.

+0

Ja, dies hat den Trick sowohl für Query und DetachedCriteria. Vielen Dank! – ripper234