请问hql会给你编译时错误吗?

时间:2021-02-03 15:29:37

Will hql give you compile time errors like criteria query?

hql会给你编译时错误,比如条件查询吗?

I remember hearing that one of the methods doesn't (besides raw SQL).

我记得听过其中一个方法没有(除了原始SQL)。

4 个解决方案

#1


The short answer is no. Since HQL is essentially a string, you need an IDE to parse it and figure out if you're doing something wrong.

最简洁的答案是不。由于HQL本质上是一个字符串,因此您需要一个IDE来解析它并弄清楚您是否做错了。

#2


No query build in Hibernate, neither HQLs nor Critieras, will produce compile time errors. Nevertheless you can use the NamedQuery annotation to declare your static HQL queries in a static way. This will provide caching and validity checks when starting your application because hibernate's session factory will read all NamedQueries on first startup.

Hibernate中没有查询构建,HQL和Critieras都不会产生编译时错误。不过,您可以使用NamedQuery批注以静态方式声明静态HQL查询。这将在启动应用程序时提供缓存和有效性检查,因为hibernate的会话工厂将在首次启动时读取所有NamedQueries。

#3


HQL wil not give you compile time errors, as it is only treated as a string at compile time. What do you mean with 'like criteria query'?

HQL不会给你编译时错误,因为它在编译时只被视为一个字符串。 “喜欢标准查询”是什么意思?

#4


Criteria queries may not give you compile time errors, something like this will error

Criteria查询可能不会给你编译时错误,这样的错误

ICriteria crit = sess.CreateCriteria(typeof(Cat));
crit.SetMaxResults("50"); /* wrong parameter type */
List cats = crit.List();

Something like this will not

这样的事情不会

IList cats = sess.CreateCriteria(typeof(Cat))
.Add( Expression.Like("Naem", "Fritz%") ) /* misspelled property */
.Add( Expression.Between("Weight", minWeight, maxWeight) )
.List();

#1


The short answer is no. Since HQL is essentially a string, you need an IDE to parse it and figure out if you're doing something wrong.

最简洁的答案是不。由于HQL本质上是一个字符串,因此您需要一个IDE来解析它并弄清楚您是否做错了。

#2


No query build in Hibernate, neither HQLs nor Critieras, will produce compile time errors. Nevertheless you can use the NamedQuery annotation to declare your static HQL queries in a static way. This will provide caching and validity checks when starting your application because hibernate's session factory will read all NamedQueries on first startup.

Hibernate中没有查询构建,HQL和Critieras都不会产生编译时错误。不过,您可以使用NamedQuery批注以静态方式声明静态HQL查询。这将在启动应用程序时提供缓存和有效性检查,因为hibernate的会话工厂将在首次启动时读取所有NamedQueries。

#3


HQL wil not give you compile time errors, as it is only treated as a string at compile time. What do you mean with 'like criteria query'?

HQL不会给你编译时错误,因为它在编译时只被视为一个字符串。 “喜欢标准查询”是什么意思?

#4


Criteria queries may not give you compile time errors, something like this will error

Criteria查询可能不会给你编译时错误,这样的错误

ICriteria crit = sess.CreateCriteria(typeof(Cat));
crit.SetMaxResults("50"); /* wrong parameter type */
List cats = crit.List();

Something like this will not

这样的事情不会

IList cats = sess.CreateCriteria(typeof(Cat))
.Add( Expression.Like("Naem", "Fritz%") ) /* misspelled property */
.Add( Expression.Between("Weight", minWeight, maxWeight) )
.List();