为什么以下代码部分产生“java.lang.ClassCastException:org.dom4j.tree.DefaultElement无法强制转换为cc.co.sqeezer.model.Registration”
List list = this.getHibernateTemplate().find(query, parameters);
if (list.size() > 0) {
registration = (Registration) list.get(0); // here is ClassCastException
}
映射是:
<class name="Registration" table="registration" dynamic-insert="true" dynamic-update="true" optimistic-lock="version">
<meta attribute="implement-equals">true</meta>
<meta attribute="implement-tostring">true</meta>
<id name="registrationId" type="integer" column="registration_id" unsaved-value="none">
<meta attribute="scope-set">public</meta>
<meta attribute="use-in-tostring">true</meta>
<!-- generator class="native"></generator -->
<generator class="sequence">
<param name="sequence">registration_registration_id_seq</param>
</generator>
</id>
<property name="emailAddress" column="email" type="string" not-null="true">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="password" column="password" type="string" length="50">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
的applicationContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource" /></property>
<property name="mappingResources">
<list>
<value>cc/co/sqeezer/model/Mappings.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
DefaultElement来自哪里?
答案 0 :(得分:2)
好吧,我自己找到了解决方案。 添加了以下HibernateProperty
<prop key="hibernate.default_entity_mode">pojo</prop>
似乎dom4j是我案例中的默认实体模式。 查看属性here。