简体   繁体   English

通过示例实体进行休眠搜索,ID不在属性列表中

[英]hibernate search critteria by sample entity, id not on a property list

I have a hibernate entity Car 我有一个休眠的实体车

@Entity
@Table(name = "car")
public class Car extends AbstractEntityBean implements java.io.Serializable {

    private Integer carId;
    private Integer name;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "carId", unique = true, nullable = false)
    public Integer getCarId() {
        return this.carId;
    }

    public void setCarId(Integer carId) {
        this.carId = carId;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

Then I try to search a car by example: crit.add(example); 然后,我尝试通过示例搜索汽车:crit.add(example);

In "example" I set carName adn search works great, as expected. 在“示例”中,我设置了carName和搜索效果,与预期的一样。 But when I set carId in "example", carId is being ignored in search criteria and query returns all cars. 但是,当我在“示例”中设置carId时,carId在搜索条件中将被忽略,查询将返回所有汽车。 I did some debuggin and I see in hibernate-core-3.6.10.Final-sources.jar!\\org\\hibernate\\tuple\\entity\\EntityMetamodel.java there is a property 我做了一些调试,并且在hibernate-core-3.6.10.Final-sources.jar!\\ org \\ hibernate \\ tuple \\ entity \\ EntityMetamodel.java中看到了一个属性

private final String[] propertyNames;

I can see "name" on propertyNames list, but not cardId. 我可以在propertyNames列表中看到“名称”,但看不到cardId。 When I add annotation @Id to name instead of carId, carId shows up on propertyNames list and I can search by example where carId is set. 当我在名称中添加注释@Id而不是carId时,carId会显示在propertyNames列表上,并且我可以通过示例来搜索设置了carId的示例。

Question: How can I search by example using carId when @Id annotation is set at carId? 问题:在carId设置@Id注释时,如何使用carId示例搜索?

Thanks 谢谢

As I remember from QBE with Hibernate criteria, this is the way it is designed. 正如我从具有休眠标准的QBE中所记得的那样,这就是它的设计方式。 So short question, you can't query by the id using QBE. 简短的问题是,您无法使用QBE来查询ID。 And it also doesn't make sense. 而且这也没有意义。 When querying by id, you can only get one result. 按ID查询时,只能得到一个结果。

As a side note: Hibernate 3.6 is quite old. 附带说明:Hibernate 3.6相当老。 Probably way out-of-date! 可能已经过时了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM