Hibernate通过非ID,唯一标识符获取对象 [英] Hibernate get Object by non ID , unique identifier

查看:104
本文介绍了Hibernate通过非ID,唯一标识符获取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



I have the following object:

    @Id
    @GeneratedValue
    private long id;
    @Column(name = "uniqueId", unique=true)
    private String uniqueId;

是否可以从具有object.uniqueId ==some_unique_id的数据库中获取对象?

is it possible to get an object from the DB that has object.uniqueId == "some_unique_id"??

谢谢。

推荐答案

String hql = "select foo from Foo foo where foo.uniqueId = :uniqueId";
return (Foo) session.createQuery(hql)
                    .setString("uniqueId", theUniqueId)
                    .uniqueResult();

这篇关于Hibernate通过非ID,唯一标识符获取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆