hibernate - uniqueResult silently fails
hibernate, spring, tomcat
Solution
Maybe you should try to see the actual hibernate query and parameters using the logger. The two loggers you should make to "debug" are:
- `org.hibernate.SQL`
- `org.hibernate.type`
Put both on `TRACE` or `ALL` and check the result on logging. For more information about the logger see the hibernate documentation.
The most common case would be log4j. AFAIK, `hibernate.show_sql` is deprecated.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="Stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<logger name="org.hibernate.SQL">
<level value="TRACE"/>
</logger>
<logger name="org.hibernate.type">
<level value="TRACE"/>
</logger>
<root>
<level value="INFO"/>
<appender-ref ref="Stdout"/>
</root>
</log4j:configuration>
Problem
I have a login controller that use the hibernate uniqueResult method. Everything works fine when i test it in eclipse's tomcat server. But when i deploy my webapps to tomcat server (on the same machine) it fails: it always returns null even i use the correct credential. Here is my hibernate code: ``` session.createCriteria(User.class) .add(Restrictions.eq(User.USERNAME_FIELD, userName)) .add(Restrictions.eq(User.PASSWORD_FIELD, password)).uniqueResult(); ``` Thank you!