简体   繁体   English

Hibernate-从SQL查询中提取参数值

[英]Hibernate - Extract parameter values from SQL query

I have a class that populates a Hibernate SQL query's parameters with different values depending on some input criteria. 我有一个类,它根据某些输入条件用不同的值填充Hibernate SQL查询的参数。 I would like to write tests for the resulting query. 我想为结果查询编写测试。 As of yet, I have not found a way to get the parameter values that were set on a query. 到目前为止,我还没有找到一种方法来获取在查询中设置的参数值。 I looked at the resulting Query implementation (in this case, SQLQueryImpl) and there is a method called getParameterMetadata() that seems like it might give me something, but I haven't been able to find anything. 我查看了最终的Query实现(在本例中为SQLQueryImpl),有一个名为getParameterMetadata()的方法似乎可以给我带来一些好处,但是我却找不到任何东西。

I would like to be able to do something like: 我希望能够执行以下操作:

assertEquals("some value", query.getParameterValue(parameterName));

Is there a way to do this? 有没有办法做到这一点?

EDIT: 编辑:

I just looked a little more, and I found a 我看了一点,然后发现

query.getQueryParameters(map).getNamedParameters()

which returns a Map. 它返回一个Map。 I have to assume that the map contains the parameters and their values. 我必须假设地图包含参数及其值。 Correct me if I'm wrong. 如果我错了纠正我。

我实际上没有考虑到这样一个事实,因为我正在测试,因此我可以简单地模拟查询并期待特定的参数。

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

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