Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
I am expecting back only purchased products where the product matches. Instead I get back all purchased product objects, regardless of product, from the database. For queries where I set properties such as a String , int etc this works fine. It fails when I pass in a refernce object. What am I doing wrong? Any help would be greatly appreciated and hopefully I submitted this ok :)
Scott
Hibernate version:2.1
Mapping documents:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.gen.ipdsserver.persistence.PurchasedProduct" table="PURCHASED_PRODUCT">
<meta attribute="class-description">
Represents a purchased product.
</meta>
<id name="id" type="long" column="PURCHASED_PRODUCT_ID">
<meta attribute="scope-set">protected</meta>
<meta attribute="field-description">Unique identity - automatically generated</meta>
<generator class="native" />
</id>
<many-to-one name="contact" column="CONTACT_ID"
class="com.gen.ipdsserver.persistence.Contact"
cascade="save-update"
not-null="true"
outer-join="true"/>
<many-to-one name="lineItem" column="LINE_ITEM_ID"
class="com.gen.ipdsserver.persistence.LineItem"
cascade="none"
not-null="false"
outer-join="true"/>
<many-to-one name="product" column="PRODUCT_OFFERING_ID"
class="com.gen.ipdsserver.persistence.ProductOffering"
cascade="none"
not-null="true"
outer-join="true"/>
<property name="productIdNumber" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The serial number of the purchased product</meta>
<column name="PRODUCT_ID_NUMBER" length="30" />
</property>
<property name="loginName" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The login name for the purchased product</meta>
<column name="LOGIN_NAME" length="25" />
</property>
<property name="password" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The password for the purchased product</meta>
<column name="PASSWORD" length="30" />
</property>
<property name="active" type="boolean">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">Is the purchased product active</meta>
<column name="ACTIVE" not-null="true" />
</property>
<property name="expirationDate" type="timestamp">
<meta attribute="field-description">The purchased product expiration date</meta>
<column name="EXPIRATION_DATE" not-null="true" />
</property>
<property name="lastSaved" type="timestamp">
<meta attribute="field-description">The purchased product save date</meta>
<column name="LAST_SAVED" not-null="true" />
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():session = openSession();
HibernateService hibernateService = HibernateService.getInstance(configurator.getHibernateConfigurationProperty());
ProductOffering product=detail.getProduct();
product=(ProductOffering)hibernateService.getUniqueResult(product);
if(product==null)
throw new ServiceException("product offering not found in database");
PurchasedProduct pp= new PurchasedProduct();
pp.setActive(true);
pp.setProduct(product);
// this gets a list of purchased products
List purchasedProducts=hibernateService.getResults(pp);
// this is my getResults method that i call
Example example = Example.create(exampleCriteria);
example.excludeZeroes();
example.ignoreCase();
if (!exactMatch) {
example.enableLike();
}
Criteria criteria = session.createCriteria(exampleCriteria.getClass());
criteria.add(example);
if (order != null) {
criteria.addOrder(order);
}
results = criteria.list();
}
catch (HibernateException he) {
he.printStackTrace();
throw new PersistenceException(he);
}
finally {
endSession(session);
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:PostgreSQL
The generated SQL (show_sql=true):14:32:48,955 INFO [STDOUT] Hibernate: select productoff0_.PRODUCT_OFFERING_ID a
s PRODUCT_1_3_, productoff0_.UPGRADE_ID as UPGRADE_ID3_, productoff0_.PRODUCT_OF
FERING_TYPE_ID as PRODUCT_3_3_, productoff0_.NAME as NAME3_, productoff0_.DESCRI
PTION as DESCRIPT5_3_, productoff0_.RECURRING as RECURRING3_, productoff0_.PAYME
NT_PERIOD as PAYMENT_7_3_, productoff0_.INSTALLMENTS as INSTALLM8_3_, productoff
0_.PRICE as PRICE3_, productoff0_.DATE_CREATED as DATE_CR10_3_, productoff0_.LAS
T_SAVED as LAST_SAVED3_, productoff1_.PRODUCT_OFFERING_ID as PRODUCT_1_0_, produ
ctoff1_.UPGRADE_ID as UPGRADE_ID0_, productoff1_.PRODUCT_OFFERING_TYPE_ID as PRO
DUCT_3_0_, productoff1_.NAME as NAME0_, productoff1_.DESCRIPTION as DESCRIPT5_0_
, productoff1_.RECURRING as RECURRING0_, productoff1_.PAYMENT_PERIOD as PAYMENT_
7_0_, productoff1_.INSTALLMENTS as INSTALLM8_0_, productoff1_.PRICE as PRICE0_,
productoff1_.DATE_CREATED as DATE_CR10_0_, productoff1_.LAST_SAVED as LAST_SAVED
0_, productoff2_.PRODUCT_OFFERING_TYPE_ID as PRODUCT_1_1_, productoff2_.PRODUCT_
OFFERING_TYPE as PRODUCT_2_1_, productoff2_.LAST_SAVED as LAST_SAVED1_, producto
ff3_.PRODUCT_OFFERING_TYPE_ID as PRODUCT_1_2_, productoff3_.PRODUCT_OFFERING_TYP
E as PRODUCT_2_2_, productoff3_.LAST_SAVED as LAST_SAVED2_ from PRODUCT_OFFERING
productoff0_ left outer join PRODUCT_OFFERING productoff1_ on productoff0_.UPGR
ADE_ID=productoff1_.PRODUCT_OFFERING_ID left outer join PRODUCT_OFFERING_TYPE pr
oductoff2_ on productoff1_.PRODUCT_OFFERING_TYPE_ID=productoff2_.PRODUCT_OFFERIN
G_TYPE_ID left outer join PRODUCT_OFFERING_TYPE productoff3_ on productoff0_.PRO
DUCT_OFFERING_TYPE_ID=productoff3_.PRODUCT_OFFERING_TYPE_ID where productoff0_.P
RODUCT_OFFERING_ID=?
Debug level Hibernate log excerpt: