I'm trying to create a composite-id as described in the "Mapping the join table to an intermediate entity" section on p. 303 but Hibernate is not finding the inner Id class. I used Listing 7.1 as a template to create the Java class (I'm using Survey->SurveyQuestion<-Question instead of Category->CategorizedItem<-Item) and am using XML (from p. 305) instead of annotations. In the composite-id class attribute I've tried using SurveyQuestion.Id as well as SurveyQuestion$Id (both with and without package names).
What am I missing?
Thanks,
Gary
P.S. Please let me know if I've not included enough info.
Hibernate version: 3.1.3
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="xxx.model.SurveyQuestion"
table="SURVEY_QUESTION">
<composite-id
name="id"
class="xxx.model.SurveyQuestion.Id">
<key-property
name="surveyId"
access="field"
column="SURVEY_ID" />
<key-property
name="questionId"
access="field"
column="QUESTION_ID" />
</composite-id>
<many-to-one
name="survey"
column="SURVEY_ID"
not-null="true"
insert="false"
update="false" />
<many-to-one
name="question"
column="QUESTION_ID"
not-null="true"
insert="false"
update="false" />
<property
name="questionNumber"
formula="QUESTION_NUM" />
</class>
</hibernate-mapping>
Java code:Code:
public class SurveyQuestion extends BaseObject {
public static class Id implements Serializable {
private static final long serialVersionUID = -5060137236621292400L;
private Long surveyId;
private Long questionId;
public Id() {}
public Id(Long surveyId, Long questionId) {
this.surveyId = surveyId;
this.questionId = questionId;
}
@Override
public boolean equals(final Object other) {
if (this == other)
return true;
if (!(other instanceof Id))
return false;
Id castOther = (Id) other;
return new EqualsBuilder().append(surveyId, castOther.surveyId)
.append(questionId, castOther.questionId).isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(surveyId).append(questionId)
.toHashCode();
}
}
private static final long serialVersionUID = 913381528098814703L;
private Id id = new Id();
private Survey survey;
private Question question;
private Integer questionNumber;
public SurveyQuestion(){}
public SurveyQuestion(Survey survey, Question question) {
this.survey = survey;
this.question = question;
this.id.surveyId = survey.getId();
this.id.questionId = question.getId();
}
.
.
.
}
Full stack trace of any exception that occurs:Code:
[sandbox] ERROR [main] ContextLoader.initWebApplicationContext(211) | Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: class mil.jfcom.model.SurveyQuestion.Id not found while looking for property: surveyId
org.hibernate.MappingException: class mil.jfcom.model.SurveyQuestion.Id not found while looking for property: surveyId
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2138)
at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1867)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:1700)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:433)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:347)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:679)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1091)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:396)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:277)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:252)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at mil.jfcom.webapp.listener.StartupListener.contextInitialized(StartupListener.java:51)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: java.lang.ClassNotFoundException: mil.jfcom.model.SurveyQuestion.Id
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1352)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76)
... 46 more
Name and version of the database you are using: Oracle 10g