hibernate创建条件功能在控制台上打印问号

时间:2012-02-22 13:34:33

标签: hibernate struts2

我在我的项目中编写了hibernate createcriteria函数,就像这样

Hibernatesession.createCriteria(Salesman.class).add(Restrictions.ilike("email", email)).list();

这里的电子邮件是一个变量,我在我的dao页面中正确地得到了这个。 但是控制台中的查询是

select this_.id as id28_0_, this_.city_id as city2_28_0_, this_.state_id as state3_28_0_, this_.firstname as firstname28_0_, this_.lastname as lastname28_0_, this_.address as address28_0_, this_.zip as zip28_0_, this_.phone as phone28_0_, this_.suit as suit28_0_, this_.username as username28_0_, this_.password as password28_0_, this_.email as email28_0_, this_.status as status28_0_, this_.created_at as created14_28_0_ from test_mydrdirect.salesman this_ where lower(this_.email) like ?

它的instaed应该像这样在控制台中打印

select this_.id as id28_0_, this_.city_id as city2_28_0_, this_.state_id as state3_28_0_, this_.firstname as firstname28_0_, this_.lastname as lastname28_0_, this_.address as address28_0_, this_.zip as zip28_0_, this_.phone as phone28_0_, this_.suit as suit28_0_, this_.username as username28_0_, this_.password as password28_0_, this_.email as email28_0_, this_.status as status28_0_, this_.created_at as created14_28_0_ from test_mydrdirect.salesman this_ where lower(this_.email) like 'test@gmail.com'

而不是test@gmail.com hibernate打印只是'?'在控制台中。任何人都知道为什么这样的印刷品会这样。

1 个答案:

答案 0 :(得分:1)

这些查询被视为预处理语句,参数绑定到查询执行时的值。但是,您仍然可以按如下方式记录它们。

如果要详细记录hibernate查询,则需要使用以下日志记录机制,如文章here中所述。

log4.properties 文件

中添加以下内容
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\mkyongapp.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO

# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL

这是另一个example