日期:2014-05-16  浏览次数:20551 次

怎么实现一个POJO对应多个不同的数据库表

首先先建好一个pojo类,

public class IcWsprice implements Serializable
{

??? /**
???? *
???? */
??? private static final long serialVersionUID = 1L;

??????? // primary key
??? private java.util.Calendar icEffdate;

??? private java.lang.String icCode;

??? private java.lang.String icArea;

??? // fields
??? private java.lang.Integer icOWp;

??? private java.lang.Integer icWp

???? ..............

}

在hibernate 中mapping

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
?"-//Hibernate/Hibernate Mapping DTD//EN"
?"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.fortuneduck.ic.vo">
?<class name="IcWsprice" table="IC_HB_WSPRICE" entity-name="IcHBWsprice">
??<composite-id>
???<key-property
????column="IC_EFFDATE"
????name="icEffDate"
????type="java.util.Calendar"
??? />
???<key-property
????column="IC_CODE"
????name="icCode"
????type="string"
??? />
???<key-property
????column="IC_AREA"
????name="icArea"
????type="string"
??? />
??</composite-id>
??<property
???column="IC_O_WP"
???length="5"
???name="icOWp"
???not-null="false"
???type="integer"
?? />
??<property
???column="IC_WP"
???length="5"
???name="icWp"
???not-null="false"
???type="integer"
?? />
?</class>
?<class name="IcWsprice" table="IC_LG_WSPRICE" entity-name="IcLGWsprice">
??<composite-id>
???<key-property
????column="IC_EFFDATE"
????name="icEffDate"
????type="java.util.Calendar"
??? />
???<key-property
????column="IC_CODE"
????name="icCode"
????type="string"
??? />
???<key-property
????column="IC_AREA"
????name="icArea"
????type="string"
??? />
??</composite-id>
??<property
???column="IC_O_WP"
???length="5"
???name="icOWp"
???not-null="false"
???type="integer"
?? />
??<property
???column="IC_WP"
???length="5"
???name="icWp"
???not-null="false"
???type="integer"
?? />
?</class>
?
?<class name="IcWsprice" table="IC_WA_WSPRICE" entity-name="IcWAWsprice">
??<composite-id>
???<key-property
????column="IC_EFFDATE"
????name="icEffDate"
????type="java.util.Calendar"
??? />
???<key-property
????column="IC_CODE"
????name="icCode"
????type="string"
??? />
???<key-property
????column="IC_AREA"
????name="icArea"
????type="string"
??? />
??</composite-id>
??<property
???column="IC_O_WP"
???length="5"
???name="icOWp"
???not-null="false"
???type="integer"
?? />
??<property
???column="IC_WP"
???length="5"
???name="icWp"
???not-null="false"
???type="integer"
?? />
?</class>
?
?<class name="IcWsprice" table="IC_WT_WSPRICE" entity-name="IcWTWsprice">
??<composite-id>
???<key-property
????column="IC_EFFDATE"
????name="icEffDate"
????type="java.util.Calendar"
??? />
???<key-property
????column="IC_CODE"
????name="icCode"
????type="string"
??? />
???<key-property
????column="IC_AREA"
????name="icArea"
????type="string"
??? />
??</composite-id>
??<property
???column="IC_O_WP"
???length="5"
???name="icOWp"
???not-null="false"
???type="integ