Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1 beta 1
Mapping documents:
<class name="com.tds.refdata.admin.Preference" table="T_PREFERENCE">
<id name="prefId" type="integer" column="id_pref_key" />
<version name="prefVersion" type="integer" column="id_pref_ver" />
<property name="active" type="boolean" column="is_actv" />
<property name="dsRegion" type="integer" column="id_ds_rgn" />
<property name="lastModifiedBy" type="string" column="id_lst_upd" />
<property name="strLastModifiedDate" type="string" column="dt_lst_upd_gmt" />
<property name="prefType" type="string" column="id_pref_typ" />
<property name="prefTypeId" type="integer" column="id_pref_typ_key" />
<property name="pathId" type="integer" column="id_path_key" />
<property name="prefName" type="string" column="nm_pref_key" />
<property name="prefValue" type="string" column="nm_pref_val" />
<property name="prefOrder" type="integer" column="nm_pref_ord" />
<property name="prefDescription" type="string" column="nm_pref_desc" />
<!--loader query-ref="LoadPref" /-->
<sql-insert callable="true">{call INS_UPD_pref_hbm (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}</sql-insert>
<sql-update callable="true">{? = call INS_UPD_pref_hbm (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}</sql-update>
<!--sql-delete callable="true">{? = call DEL_pref_hbm (?)}</sql-delete-->
</class>
<sql-query name="LoadUserPref" callable="true">
<return alias="usrPref" class="com.tds.refdata.admin.Preference">
<return-property name="prefId" column="id_pref_key" />
<return-property name="prefType" column="id_pref_typ" />
<return-property name="pathId" column="id_path_key" />
<return-property name="prefName" column="nm_pref_key" />
<return-property name="prefValue" column="nm_pref_val" />
<return-property name="prefVersion" column="id_pref_ver" />
</return>
{ call SEL_user_pref_hbm(?, ?) }
</sql-query>
Code between sessionFactory.openSession() and session.close():
try
{
Session session = HibernateUtils.openSession();
Transaction tx = session.beginTransaction();
Query q = session.getNamedQuery("LoadUserPref");
q.setInteger(0, userId);
q.setBoolean(1, true);
userPrefList = q.list();
tx.commit();
HibernateUtils.closeSession();
}
catch (Exception e)
{
log.error(e,e);
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
SQL Server 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Not sure if this is a bug or if I am using hibernate incorrectly.
Basically, I have a class and its asscoaited table as shown in the mapping section above.
I want to use an SP to return only certain columns and populate the same class. However, I get errors saying it cannot find the fields that have been defined in the class-table mapping.
I thought that was the idea of the <return-property name="..." column="...."> attribute in the <sql-query>, ie it will call the setters of the class based on the returned column and not based on the table-class definition.
Also - if I wanted to populate an object for which there is no underlying table, I presume I have to execute the query and iterate through the result myself and call the appropriate setters?
Thanks in advance.
Naz