我在Mysql中有一个hibernate的配置,有两个表,Pojo的配置文件如下:
<hibernate-mapping>
<class name="empresa.Departamentos" table="departamentos" catalog="empresa2" optimistic-lock="version">
<id name="deptno" type="int">
<column name="deptno" />
<generator class="assigned" />
</id>
<property name="dnombre" type="string">
<column name="dnombre" length="15" />
</property>
<property name="loc" type="string">
<column name="loc" length="15" />
</property>
<set name="empleadoses" table="empleados" inverse="true" lazy="true" fetch="select">
<key>
<column name="deptno" not-null="true" />
</key>
<one-to-many class="empresa.Empleados" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="empresa.Empleados" table="empleados" catalog="empresa2" optimistic-lock="version">
<id name="empno" type="short">
<column name="empno" />
<generator class="assigned" />
</id>
<many-to-one name="departamentos" class="empresa.Departamentos" fetch="select">
<column name="deptno" not-null="true" />
</many-to-one>
<property name="apellido" type="string">
<column name="apellido" length="10" />
</property>
<property name="oficio" type="string">
<column name="oficio" length="10" />
</property>
<property name="dir" type="java.lang.Short">
<column name="dir" />
</property>
<property name="fechaalt" type="date">
<column name="fechaalt" length="10" />
</property>
<property name="salario" type="java.lang.Float">
<column name="salario" precision="6" />
</property>
<property name="comision" type="java.lang.Float">
<column name="comision" precision="6" />
</property>
</class>
</hibernate-mapping>
接下来,当我在hql中执行以下句子时:从Empiredos e中选择e,其中e.departamentos.deptno在(从departamentos d中选择d.deptno,其中d.loc='Lundon'(它给了我以下错误:org.hubinate.MappingException:关联引用未映射的类:empresa。Empiredos网址:org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2557(网址:org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2808(位于org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70(位于org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1695(位于org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424(位于org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844(位于org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928(当做哈维尔
解决方案是:
select e.apellido
from Empleados e
where e.departamentos.deptno in
(select d.deptno
from Departamentos d
where d.loc='Sevilla')