I am attempting to use a query to return all of a type of component of another class. When I run it, I get a a class not found exception. I have seen similar posts on this board go unanswered. I hope I can provide enough information to help someone help me determine if this is possible.
I am mapping to a legacy database, so please do not criticize the table structure.
Here is the basic structure (I simplified and anonomized the real code to show the real issue):
Code:
------- classes ----------
class Person {
String identifier;
Phone phone1;
Phone phone2;
}
class Phone {
String number;
String extension;
}
-------- mapping ------
<hibernate-mapping>
<class name="example.Person" mutable="false">
<id column="person_identifier" name="identifier">
<component name="phone1" class="example.Phone">
<property name="number" column="phone_number1"/>
<property name="extension" column="phone_ext1"/>
</component>
<component name="phone2" class="example.Phone">
<property name="number" column="phone_number2"/>
<property name="extension" column="phone_ext2"/>
</component>
<loader query-ref="loadPerson"/>
</class>
<sql-query name="loadPerson" callable="true">
<return alias="person" class="example.Person">
<return-property name="identifier" column="person_identifier" />
<return-property name="phone1">
<return-column name="phone_number1"/>
<return-column name="phone_ext1"/>
</return-property>
<return-property name="phone2">
<return-column name="phone_number2"/>
<return-column name="phone_ext2"/>
</return-property>
</return>
{call getPerson(?)}
</sql-query>
<sql-query name="getAllPhones" callable="true" read-only="true">
<return alias="phone" name="example.Phone">
<return-property name="number" column="phNum"/>
<return-property name="extension" column="phExt"/>
</return>
SELECT phone_number1 as phNum, phone_ext1 as phExt from SOMETABLE group by phone_number1, phone_ext1
UNION
SELECT phone_number2 as phNum, phone_ext2 as phExt from SOMETABLE group by phone_number2, phone_ext2
</sql-query>
</hibernate-mapping>
My java code is not important right now because this mapping blows up before I even get to run it. But, for completeness sake, it is
Code:
return (List<Phone>)getHibernateTemplate().getSessionFactory().getCurrentSession().getNamedQuery("getAllPhones").list();
I am using Hibernate 3.3.1. I am using it with Spring 2.5.6. My spring config is
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingLocations">
<list>
<value>classpath:/example/Person.hbm.xml</value>
<!--other stuff snipped-->
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.cache_provider">${hibernate.cache_provider}</prop>
</props>
</property>
</bean>
This should be possible. It makes sense that the component is not on the list of mapped classes, but shouldn't it be? I have debugged the code, and haven't seen it. I am not sure how to map it as a class without an ID.
If you have any suggestions, I would appreciate it.
Thanks!