@Lob
在字段中进行搜索查询时,我遇到了奇怪的行为。
我将 HSQLDB 和 Hibernate 与 JPA2 一起使用。
查询是:(@NamedQuery(name = "URL.findByPathAndDomain", query = "select u from URL u where u.path = :path and u.domain.domain = :domain")
顺便path
说一下,是@lob 字段)。
我在DAO中实现了这样的方法:
public URL findByPathAndDomain(String path, String domain) {
URL url = null;
TypedQuery<URL> query = em().createNamedQuery("URL.findByPathAndDomain", URL.class);
query.setParameter("path", path);
query.setParameter("domain", domain);
try {
url = query.getSingleResult();
} catch (NoResultException e) {
logger.error(e.getMessage());
}
return url;
}
我得到了这个例外:
Caused by: org.hibernate.exception.GenericJDBCException: java.lang.NullPointerException java.lang.NullPointerException
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy45.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1897)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1698)
at org.hibernate.loader.Loader.doQuery(Loader.java:832)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
at org.hibernate.loader.Loader.doList(Loader.java:2382)
at org.hibernate.loader.Loader.doList(Loader.java:2368)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2198)
at org.hibernate.loader.Loader.list(Loader.java:2193)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:285)
... 10 more
如果我删除@Lob
注释,一切都会好起来的。它是 HSQLDB 错误、Hibernate 错误还是什么?
编辑:我将 PU 更改为使用 MySQL 而不是 HSQLDB,它像老板一样工作......