【问题标题】:Hibernate get Object by non ID , unique identifierHibernate通过非ID,唯一标识符获取对象
【发布时间】:2013-04-13 17:54:03
【问题描述】:

我有以下对象:

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

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

谢谢。

【问题讨论】:

标签: hibernate get uniqueidentifier


【解决方案1】:
String hql = "select foo from Foo foo where foo.uniqueId = :uniqueId";
return (Foo) session.createQuery(hql)
                    .setString("uniqueId", theUniqueId)
                    .uniqueResult();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多