【发布时间】:2014-11-07 16:19:35
【问题描述】:
我有两个表 table1 和 table2,它们在架构和复合 ID 方面完全相同。唯一的区别是它们中存在的数据。第一个表有 4 个月的数据,另一个表有 21 个月的数据。在我的应用程序中,我需要两个表的 who 数据。这里我们不能在这两个表之间建立关联,因为数据不属于任何场景。
我尝试在 HQL 查询中使用 FULL JOIN 将两个表加入两个不同的 pojo,但它要求加入路径,这意味着实体之间应该有一些关联才能在休眠中加入。
我还为这两个表尝试了一个 pojo,因为它们完全相似,除了其中的数据。为此,我使用了休眠功能实体名称。但它给了我如下错误;
**persistent class not known: MainClass**
这是我用来将表映射到实体的 HBM:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 2, 2014 7:23:43 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="pojos.MainClass"
table="table1" entity-name="table1">
<composite-id class="pojos.CompositeID"
name="compositeID">
<key-property name="*****" type="string">
<column name="*****" length="5" />
</key-property>
<key-property name="*****" type="string">
<column name="*****" length="3" />
</key-property>
<key-property name="*****" type="string">
<column name="******" length="3" />
</key-property>
<key-property name="****" type="string">
<column name="****" length="7" />
</key-property>
</composite-id>
<property name="****" type="string">
<column name="****" length="7" />
</property>
<one-to-one name="otherClass"
class="pojos.OtherClass"></one-to-one>
</class>
<class name="pojos.MainClass"
table="table2" entity-name="table2">
<composite-id class="pojos.CompositeID"
name="compositeID">
<key-property name="*****" type="string">
<column name="*****" length="5" />
</key-property>
<key-property name="*****" type="string">
<column name="*****" length="3" />
</key-property>
<key-property name="*****" type="string">
<column name="******" length="3" />
</key-property>
<key-property name="****" type="string">
<column name="****" length="7" />
</key-property>
</composite-id>
<property name="****" type="string">
<column name="****" length="7" />
</property>
<one-to-one name="otherClass"
class="pojos.OtherClass"></one-to-one>
</class>
</hibernate-mapping>
请建议我从两个相同的表中获取所有数据而不重复的最佳方法。
谢谢。 苏吉斯·G
【问题讨论】: