本文介绍了Hibernate标准:是否可以使用标准访问数据库视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个标准,我试图加入数据库视图。我想知道是否有可能,如果有的话,如何做到这一点? 据我所知, createAlias 和 createCriteria 只加入到根标准的子对象。我读了 detachedCriteria ,但似乎需要在数据库实体上创建这些视图。 select * from root_criteria rc其中rc.id在中(select view.id中的view.id view.field不为null) 预先致谢解决方案您可以尝试使用XML映射来创建指向数据库视图的实体类。 文档摘录: Hibernate映射的视图和基表之间没有区别。这在数据库级别是透明的,尽管一些DBMS不能正确支持视图,特别是在更新时。 subselect(可选):将不可变且只读的实体映射到数据库子查询。这是非常有用的,如果你想有一个基准表而不是的视图。 b $ b $ b < class name =MappedClassNamemutable =假> < subselect> 从DATABASE_VW中选择view.id作为viewId视图< / subselect> ... < / class> I have a criteria, which I'm trying to join to a database view. I'm wondering if it's possible and if so how to do it?As I understand, createAlias and createCriteria only join to child objects of the root criteria. I read about detachedCriteria, but it seems that those need to be created on database entities, which the view is not.The HQL equivalent would be something like this select * from root_criteria rc where rc.id in(select view.id from DATABASE_VW view where view.field is not null)Thanks in advance 解决方案 You can try XML mapping to create an entity class pointing the database view. Each field in the entity will be mapped to the one selected from the view.Excerpts from the documentation : There is no difference between a view and a base table for a Hibernate mapping. This is transparent at the database level, although some DBMS do not support views properly, especially with updates. subselect (optional): maps an immutable and read-only entity to a database subselect. This is useful if you want to have a view instead of a base table.Below is the sample configuration, modify it accordingly. <class name="MappedClassName" mutable="false"> <subselect> select view.id as viewId from DATABASE_VW view </subselect> ... </class> 这篇关于Hibernate标准:是否可以使用标准访问数据库视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 20:23