为什么使用此命名查询时出现语法错误:

@NamedQuery(name = "event_find", query = "from Event where location.address like str('%'+:address+'%') " +
        "or :address like str('%'+location.address+'%'")

以及:
Query query = session.getNamedQuery("event_find").setParameter("address", address); // or "%"+address+"%"

我怎样才能解决这个问题?
编辑:
事件:
@NamedQueries({
        @NamedQuery(name = "event_find", query = "from Event where location.address like :address " +
        "or :address like location.address")
})
@Entity
@Table(catalog = "control_station")
public final class Event implements Serializable {

    private long id;
    private Location location;
    ...

    @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public Location getLocation() {
        return location;
    }

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

    ...

}

地点:
@Entity
@Table(catalog = "control_station")
public final class Location implements Serializable {

    private long id;
    private String address;
    private double latitude;
    private double longitude;

    ...
}

例如,假设我们在表Location中有三个地址:
西班牙
西班牙马德里
西班牙马德里圣地亚哥伯纳乌体育场
现在如果我搜索西班牙马德里,结果必须包含以上所有内容。。。
即:
西班牙喜欢%马德里,西班牙%或马德里,西班牙喜欢%西班牙%
其中圣地亚哥伯纳乌体育场,马德里,西班牙喜欢%马德里,西班牙%或马德里,西班牙喜欢%圣地亚哥伯纳乌体育场,马德里,西班牙%
等等。。。

最佳答案

谢谢你们,答案是:

@NamedQuery(name = "event_find", query = "from Event where location.address like concat('%', :address, '%') or :address like concat('%', location.address, '%')")

07-24 09:19