java - Hibernate 映射 - 多表查询
问题描述
我正在开发一个使用 hibernate 和 drools 文件对数据库表进行 CRUD 操作的应用程序,此时我需要提供给定特定 ID 的菜单,现在可以对其进行硬编码。
我有必要的查询使其可用,我想使用它或在休眠中模拟它,以便调用 .hbm 并输出此查询的结果。考虑到我无法访问 .java 文件,因此我只能创建需要输出的 .hbm 和 .xml 文件。
我可以列出我的应用程序上执行此查询所需的所有表。出现的问题是:如何使用所有这些模型(使这些表中的每一个可用的休眠映射文件)来创建一个调用它们的单个 .hbm 文件,我在哪里可以模拟我需要的查询?
查询如下:
select distinct d.* from Group MB, Access AI, Item I, Module M, MenuItem D
where
mb.IdGroup = AI.IdGroup and ai.CodItem = i.CodItem and i.Module = m.Module and
mb.CodSis = ai.CodSis and ai.CodSis = i.CodSis and i.CodSis = m.CodSis and
m.CodSis = 103 and mb.IdUtil= 29
and
d.Coditem = i.CodItem
and
d.parentMenuID = 0
列出每个表的 hbm 模型如下所示:(列出菜单表的示例)
菜单.hbm.xml
<hibernate-mapping>
<class name="authorization.model.Menu" table="MenuItem" where="ParentMenuID = 0 ">
<composite-id>
<key-property column="Id" name="id" type="int"/>
</composite-id>
<property column="label" name="__label" type="string"/>
<property column="actionURL" name="__actionURL" type="string"/>
<property column="ParentMenuID" name="__ParentMenuID" type="string"/>
<property column="MenuID" name="__MenuID" type="int"/>
<property column="Coditem" name="__Coditem" type="int"/>
</class>
</hibernate-mapping>
菜单.xml
<?xml version="1.0" encoding="utf-8" ?>
<concept name="menu">
<action name="readlist" jsonMetainfo="{
'columns':[
{'key':'__ParentMenuID', 'order':1, 'allowSort':false, 'type':'text', 'exportable':true},
{'key':'__Coditem', 'order':2, 'allowSort':false, 'type':'text', 'exportable':true},
{'key':'__label', 'order':3, 'allowSort':false, 'type':'text', 'exportable':true},
],
'defaultSort':{'column':2, 'type':'asc'},
'actions':[]
}" />
</concept>
有了这个,我可以列出没有任何过滤器的菜单表,只是表。我需要模拟上面的查询,我尝试使用<many-to-one name="Item" class="authorization.model.Item" insert="false" update="false" not-found="ignore"/><many-to-one>
所有模型(列出表),我只需要列出它们并确保我在一个 .hbm 文件中拥有我需要的所有表(列出它们来制作当然..)但它不工作.. 鉴于我的情况,有没有办法执行该查询?
经过大量搜索,我仍然找不到解决问题的方法,希望有人能帮助我。
解决方案
推荐阅读
- javascript - 在 ReactJS 中集成 sharethis
- regex - bash find 使用正则表达式不区分大小写
- vb.net - 如何使用 VB.NET 从 LDAP 获取域列表?
- html - 与在浏览器上打开 HTML 文件相比,通过 URL 打开网站时的设计不同
- javascript - Javascript splice in loop vs splice multi line
- node.js - 带有 Express Js 的 Mikronode:TypeError:_sentence$.get(...).do is not a function
- llvm - LLVM 中 CallInst、InvokeInst 和 CallSite 的区别和用法是什么?
- apache-spark - 使用 Java-Spark 格式将列写入日期
- python - Python有序列表搜索与对象列表搜索集
- vespa - 如何在 Vespa 中执行全文搜索?