Hi, i've got a really wierd case .. Just cant figure out what's wrong .. Please help .. T__T
The code is as simple as this :
Code:
Am01 mstUser = (Am01) session.get(Am01.class, "ADEK");
System.out.println(mstUser);
And the resulted object of mstUser is null .. The table actually has the record with "ADEK" primary key ..
I've taken a look at the debug, the generated query runs fine in my query tool, the row exists..
I've tested hql on the same case :
Code:
Am01 mstUser = (Am01) session.createQuery("from Am01 A where A.userid='ADEK'").uniqueResult();
System.out.println(mstUser);
and it's result is not null and correct !
I really wonder what's wrong with the first code using session.get(Class,Serializabe) which results null
I've supplied my very simple confs and some debugs, please take a look :
Hibernate version: 3.1.beta2
Mapping documents:excerp from hibernate.cfg.xml
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
<property name="connection.url">jdbc:oracle:thin:@database:1521:TEST</property>
<property name="show_sql">true</property>
<mapping resource="test/model/Am01.hbm.xml" />
</session-factory>
full Am01.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="test.model.Am01"
table="AM01"
>
<id
name="userid"
type="java.lang.String"
column="USERID"
>
<generator class="assigned" />
</id>
<property
name="usernm"
type="java.lang.String"
column="USERNM"
length="30"
/>
<property
name="passwd"
type="java.lang.String"
column="PASSWD"
length="20"
/>
<property
name="dflmnu"
type="java.lang.String"
column="DFLMNU"
length="10"
/>
<property
name="usracl"
type="java.lang.Integer"
column="USRACL"
length="1"
/>
<property
name="tglkey"
type="java.sql.Date"
column="TGLKEY"
length="7"
/>
<property
name="usrkey"
type="java.lang.String"
column="USRKEY"
length="10"
/>
<!-- associations -->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Am01 mstUser = (Am01) session.get(Am01.class, "ADEK");
System.out.println(mstUser);
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Hibernate: select am01x0_.USERID as USERID1_0_, am01x0_.USERNM as USERNM1_0_, am01x0_.PASSWD as PASSWD1_0_, am01x0_.DFLMNU as DFLMNU1_0_, am01x0_.USRACL as USRACL1_0_, am01x0_.TGLKEY as TGLKEY1_0_, am01x0_.USRKEY as USRKEY1_0_ from AM01 am01x0_ where am01x0_.USERID=?
Debug level Hibernate log excerpt:
13:36:00,875 DEBUG DefaultLoadEventListener:153 - loading entity: [test.model.Am01#ADEK]
13:36:00,876 DEBUG DefaultLoadEventListener:304 - attempting to resolve: [test.model.Am01#ADEK]
13:36:00,876 DEBUG DefaultLoadEventListener:340 - object not resolved in any cache: [test.model.Am01#ADEK]
13:36:00,876 DEBUG AbstractEntityPersister:2698 - Fetching entity: [test.model.Am01#ADEK]
13:36:00,877 DEBUG Loader:1774 - loading entity: [test.model.Am01#ADEK]
13:36:00,905 DEBUG AbstractBatcher:309 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
13:36:00,906 DEBUG SQL:344 - select am01x0_.USERID as USERID1_0_, am01x0_.USERNM as USERNM1_0_, am01x0_.PASSWD as PASSWD1_0_, am01x0_.DFLMNU as DFLMNU1_0_, am01x0_.USRACL as USRACL1_0_, am01x0_.TGLKEY as TGLKEY1_0_, am01x0_.USRKEY as USRKEY1_0_ from AM01 am01x0_ where am01x0_.USERID=?
Hibernate: select am01x0_.USERID as USERID1_0_, am01x0_.USERNM as USERNM1_0_, am01x0_.PASSWD as PASSWD1_0_, am01x0_.DFLMNU as DFLMNU1_0_, am01x0_.USRACL as USRACL1_0_, am01x0_.TGLKEY as TGLKEY1_0_, am01x0_.USRKEY as USRKEY1_0_ from AM01 am01x0_ where am01x0_.USERID=?
13:36:00,907 DEBUG AbstractBatcher:413 - preparing statement
13:36:00,985 DEBUG StringType:60 - binding 'ADEK' to parameter: 1
13:36:00,990 DEBUG AbstractBatcher:325 - about to open ResultSet (open ResultSets: 0, globally: 0)
13:36:00,991 DEBUG Loader:682 - processing result set
13:36:00,992 DEBUG Loader:709 - done processing result set (0 rows)
13:36:00,992 DEBUG AbstractBatcher:332 - about to close ResultSet (open ResultSets: 1, globally: 1)
13:36:00,992 DEBUG AbstractBatcher:317 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
13:36:00,993 DEBUG AbstractBatcher:459 - closing statement
13:36:00,995 DEBUG Loader:839 - total objects hydrated: 0
13:36:00,996 DEBUG StatefulPersistenceContext:780 - initializing non-lazy collections
13:36:00,996 DEBUG Loader:1805 - done entity load
null (the output of System.out.println)