简体   繁体   English

休眠:选择列表而不是设置

[英]Hibernate: Choose List instead Set

I'm using Hibernate to convert DB to Entity and DAO Classes. 我正在使用Hibernate将DB转换为Entity和DAO类。 Hibernate chooses Set type automatically, but I need List type. Hibernate自动选择“设置类型”,但是我需要“列表类型”。 How can I change Hibernate settings? 如何更改休眠设置?

Thanks! 谢谢!

You must use createCriteria method of session and keep in list of your object, like this: 您必须使用session的createCriteria方法并将其保留在对象列表中,如下所示:

List<YourDAO> list = getSession().createCriteria(YourDAO.class).list();

or createQuery method and after use .list for get data: 或createQuery方法,并在使用.list获取数据后:

Query q = getSession().createQuery("select o from yourDAO o");
List<YourDao> list = q.list();

This will give you all the records of your entity in DB. 这将为您提供数据库中实体的所有记录。

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

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