Hello,
I am running into a problem that I can't seem to find an answer for.
I build this query...
List list = session.createQuery("from CustomerHibernate cust where cust.customerId in (select cust.customerId from cust.customerAddresses addr where addr.state = :selState)")
.setEntity("selState","CA")
.list();
When this query is run I get the net.sf.hibernate.MappingException: No persister for: java.lang.String exception.
I can run the exact same query using...
List list = session.getNamedQuery("ByCustomerState")
.setString("selState","CA")
.list();
And this query runs fine. Both queries create the exact same Hibernate query, so I am at a loss as to what I am missing.
Any help will be greatly appreciated
Thanks,
Blair
Hibernate version:
2.1.4
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>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.tomax.pojo.customer.hibernate.CustomerHibernate"
table="CUSTOMER"
>
<id
name="customerId"
type="java.lang.String"
column="CUSTOMER_ID"
>
<generator class="assigned" />
</id>
<property
name="drvKeywordLookup"
type="java.lang.String"
column="DRV_KEYWORD_LOOKUP"
length="15"
/>
<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="30"
/>
<property
name="firstName"
type="java.lang.String"
column="FIRST_NAME"
length="25"
/>
<property
name="middleName"
type="java.lang.String"
column="MIDDLE_NAME"
length="25"
/>
<property
name="salutationCd"
type="java.lang.String"
column="SALUTATION_CD"
length="20"
/>
<property
name="adr1"
type="java.lang.String"
column="ADR1"
length="30"
/>
<property
name="adr2"
type="java.lang.String"
column="ADR2"
length="30"
/>
<property
name="city"
type="java.lang.String"
column="CITY"
length="23"
/>
<property
name="state"
type="java.lang.String"
column="STATE"
length="8"
/>
<property
name="zip"
type="java.lang.String"
column="ZIP"
length="10"
/>
<property
name="phone"
type="java.lang.String"
column="PHONE"
length="20"
/>
<property
name="contact"
type="java.lang.String"
column="CONTACT"
length="15"
/>
<property
name="lookUp"
type="java.lang.String"
column="LOOK_UP"
length="15"
/>
<property
name="linkedCustId"
type="java.lang.String"
column="LINKED_CUST_ID"
length="15"
/>
<property
name="nationalCustId"
type="java.lang.String"
column="NATIONAL_CUST_ID"
length="15"
/>
<property
name="nationalCustFl"
type="java.lang.String"
column="NATIONAL_CUST_FL"
length="1"
/>
<property
name="priceMatrixUpdateCd"
type="java.lang.Character"
column="PRICE_MATRIX_UPDATE_CD"
length="1"
/>
<property
name="relatedCustId"
type="java.lang.String"
column="RELATED_CUST_ID"
length="15"
/>
<property
name="salesRepId"
type="java.lang.String"
column="SALES_REP_ID"
length="15"
/>
<property
name="externalCustId"
type="java.lang.String"
column="EXTERNAL_CUST_ID"
length="240"
/>
<property
name="commentTxt"
type="java.lang.String"
column="COMMENT_TXT"
length="600"
/>
<property
name="source"
type="java.lang.String"
column="SOURCE"
length="1"
/>
<property
name="promoRecordNo"
type="java.lang.Integer"
column="PROMO_RECORD_NO"
length="4"
/>
<property
name="primarySiteNo"
type="java.lang.Integer"
column="PRIMARY_SITE_NO"
length="4"
/>
<property
name="birthdayDt"
type="java.sql.Date"
column="BIRTHDAY_DT"
length="7"
/>
<property
name="activationDt"
type="java.sql.Date"
column="ACTIVATION_DT"
length="7"
/>
<property
name="statusCd"
type="java.lang.String"
column="STATUS_CD"
length="5"
/>
<property
name="genderCd"
type="java.lang.String"
column="GENDER_CD"
length="5"
/>
<property
name="maritalStatusCd"
type="java.lang.String"
column="MARITAL_STATUS_CD"
length="5"
/>
<property
name="omContactReqdFl"
type="java.lang.Character"
column="OM_CONTACT_REQD_FL"
length="1"
/>
<property
name="invoicePrintFl"
type="java.lang.String"
column="INVOICE_PRINT_FL"
length="1"
/>
<!-- Associations -->
<!-- bi-directional one-to-many association to CustomerPhone -->
<set
name="customerPhones"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
access="com.tomax.persist.hibernate.DirectSetAccessor">
<key>
<column name="CUSTOMER_ID" not-null="true"/>
</key>
<one-to-many class="com.tomax.pojo.customer.hibernate.CustomerPhoneHibernate"/>
</set>
<!-- bi-directional one-to-many association to CustomerAddress -->
<set
name="customerAddresses"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
access="com.tomax.persist.hibernate.DirectSetAccessor">
<key>
<column name="CUSTOMER_ID" not-null="true"/>
</key>
<one-to-many class="com.tomax.pojo.customer.hibernate.CustomerAddressHibernate"/>
</set>
</class>
<query name="ByCustomerLastName">
<![CDATA[
from com.tomax.pojo.customer.hibernate.CustomerHibernate as customer
where customer.name like :CustomerLastName
]]>
</query>
<query name="ByCustomerFirstName">
<![CDATA[
from com.tomax.pojo.customer.hibernate.CustomerHibernate as customer
where customer.firstName like :CustomerFirstName
]]>
</query>
<query name="ByCustomerID">
<![CDATA[
from com.tomax.pojo.customer.hibernate.CustomerHibernate as customer
where customer.customerId = :CustomerID
]]>
</query>
<query name="ByCustomerFirstAndLastName">
<![CDATA[
from com.tomax.pojo.customer.hibernate.CustomerHibernate as customer
where customer.firstName = :CustomerFirstName and customer.name = :CustomerLastName
]]>
</query>
<query name="ByPrimarySiteNo">
<![CDATA[
from com.tomax.pojo.customer.hibernate.CustomerHibernate as customer
where customer.primarySiteNo = :priSiteNo
]]>
</query>
<query name="ByCustomerState">
<![CDATA[
from CustomerHibernate as cust
where cust.customerId in
(select cust.customerId from cust.customerAddresses addr where addr.state = :selState)
]]>
</query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
net.sf.hibernate.MappingException: No persister for: java.lang.String
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:441)
at net.sf.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:170)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:47)
at net.sf.hibernate.hql.QueryTranslator.bindNamedParameters(QueryTranslator.java:832)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:714)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.tomax.persist.test.ExpressionTesting.testHibernate(ExpressionTesting.java:132)
at com.tomax.persist.test.ExpressionTesting.main(ExpressionTesting.java:158)
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
Hibernate: select customerhi0_.CUSTOMER_ID as CUSTOMER1_, customerhi0_.DRV_KEYWORD_LOOKUP as DRV_KEYW2_, customerhi0_.NAME as NAME, customerhi0_.FIRST_NAME as FIRST_NAME, customerhi0_.MIDDLE_NAME as MIDDLE_N5_, customerhi0_.SALUTATION_CD as SALUTATI6_, customerhi0_.ADR1 as ADR1, customerhi0_.ADR2 as ADR2, customerhi0_.CITY as CITY, customerhi0_.STATE as STATE, customerhi0_.ZIP as ZIP, customerhi0_.PHONE as PHONE, customerhi0_.CONTACT as CONTACT, customerhi0_.LOOK_UP as LOOK_UP, customerhi0_.LINKED_CUST_ID as LINKED_15_, customerhi0_.NATIONAL_CUST_ID as NATIONA16_, customerhi0_.NATIONAL_CUST_FL as NATIONA17_, customerhi0_.PRICE_MATRIX_UPDATE_CD as PRICE_M18_, customerhi0_.RELATED_CUST_ID as RELATED19_, customerhi0_.SALES_REP_ID as SALES_R20_, customerhi0_.EXTERNAL_CUST_ID as EXTERNA21_, customerhi0_.COMMENT_TXT as COMMENT22_, customerhi0_.SOURCE as SOURCE, customerhi0_.PROMO_RECORD_NO as PROMO_R24_, customerhi0_.PRIMARY_SITE_NO as PRIMARY25_, customerhi0_.BIRTHDAY_DT as BIRTHDA26_, customerhi0_.ACTIVATION_DT as ACTIVAT27_, customerhi0_.STATUS_CD as STATUS_CD, customerhi0_.GENDER_CD as GENDER_CD, customerhi0_.MARITAL_STATUS_CD as MARITAL30_, customerhi0_.OM_CONTACT_REQD_FL as OM_CONT31_, customerhi0_.INVOICE_PRINT_FL as INVOICE32_ from CUSTOMER customerhi0_ where (customerhi0_.CUSTOMER_ID in(select customerhi0_.CUSTOMER_ID from CUSTOMER_ADDRESS customerad1_ where customerhi0_.CUSTOMER_ID=customerad1_.CUSTOMER_ID and ((customerad1_.STATE=? ))))
Debug level Hibernate log excerpt: