Hibernate get Object by non ID , unique identifier

余生颓废 提交于 2019-12-10 22:33:18

问题


I have the following object:

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

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

thanks.


回答1:


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


来源:https://stackoverflow.com/questions/16119850/hibernate-get-object-by-non-id-unique-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!