使用3个表检索数据

时间:2018-01-23 08:37:50

标签: java spring hibernate

我正试图到达桌子中的一个字段而我不知道该怎么做。我有一个表,我有所有数据(TespEolReference),另一个中间表我有EolMedia表,它提到表TespTaxon和字段taxonRecordId,这是我有兴趣更新的字段。我正在开发它以创建一个新的记录。如果您离开我,请更新数据库中的那些,但输入新的不会在表单中显示。我留下我的代码给你看。

谢谢!

TespEolReferenceData.java

 * TespEolReference generated by hbm2java
 */
public class TespEolReferenceData  implements java.io.Serializable {


     private String idreference;
     private TespTPublicationtype tespTPublicationtype;
     private String fullReference;
     private Set<TespEolmedia> tespEolmedias = new HashSet(0);
     private BigDecimal idtaxon;
     private String scientificname;
}

TespEolReference.java

public class TespEolReference extends AbstractGenericEntity implements java.io.Serializable {

    private Long idreference;
    private TespTPublicationtype tespTPublicationtype;
    private String fullReference;
    private Set tespEolmedias = new HashSet(0);
}

TespEolMedia.java

public class TespEolmedia extends AbstractGenericEntity implements java.io.Serializable {

private BigDecimal idmedia;
private TespTAudience tespTAudience;
private TespTType tespTType;
private Set tespTaxons = new HashSet(0);
private Set tespEolReferences = new HashSet(0);
}

TespTaxon.java

public class TespTaxon extends AbstractGenericEntity implements java.io.Serializable {

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

    private BigDecimal taxonid;
    private TespTAmbitos tespTAmbitos;
    private BigDecimal taxonrecordid;
    private BigDecimal idtaxonomicstatus;
    private String source;
    private String tmpDatasetid;

    private Set<TespEolmedia> tespEolmedias = new HashSet<TespEolmedia>(0);
    private Set<TespEolReference> testEolReference = new HashSet<TespEolReference>(0);
}

ApplicationServiceUtils.java

public static TespEolReference getTespEolReference(
            TespEolReferenceData tespEolReferenceData) {

        try {

            TespEolReference tespEolReference = new TespEolReference();

            if(tespEolReferenceData.getIdreference() != null && !tespEolReferenceData.getIdreference().equals("")) {
                tespEolReference.setIdreference(new Long(tespEolReferenceData.getIdreference()));
            }

            tespEolReference.setFullReference(tespEolReferenceData.getFullReference());


            **if(tespEolReferenceData.getIdtaxon() != null && !tespEolReferenceData.getIdtaxon().equals("")) {
            //  TespEolmedia tespEolmedia = new TespEolmedia();

                TespTaxon tespTaxon = new TespTaxon();
                tespTaxon.setTaxonrecordid(new BigDecimal(tespEolReferenceData.getIdtaxon()));

                HashSet tespTaxons = new HashSet();
                tespTaxons.add(tespTaxon);
                tespEolReference.setTespEolmedias(tespTaxons);
            }**

            return tespEolReference;
        } catch (Exception e) {
            LOGGER.error("Ha ocurrido un error en getTespEolReference: " 
                    + e.getMessage());
            return null;
        }
    }

    public static TespEolReferenceData getTespEolReferenceData(
            TespEolReference tespEolReference) {

        try {

            TespEolReferenceData tespEolReferenceData = new TespEolReferenceData();

            tespEolReferenceData.setIdreference(tespEolReference.getIdreference().toString());

            tespEolReferenceData.setFullReference(tespEolReference.getFullReference());



            return  tespEolReferenceData ;
        } catch (Exception e) {
            LOGGER.error("Ha ocurrido un error en getTespEolReferenceData: " 
                    + e.getMessage());
            return null;
        }
    }

TespEolReference.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 
<hibernate-mapping>
    <class name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolReference" table="TESP_EOL_REFERENCE" schema="DBA_IEPNB">
        <id name="idreference" type="long">
            <column name="IDREFERENCE" precision="22" scale="0" />
            <generator class="sequence-identity" >
                <param name="sequence">SEQ_TESP_EOL_REFERENCE</param>
            </generator>
        </id>
        <many-to-one name="tespTPublicationtype" class="es.magrama.iepnb.especies.bom.hibernate.tables.TespTPublicationtype" fetch="select">
            <column name="IDPUBLICATIONTYPE" precision="22" scale="0" />
        </many-to-one>
        <property name="fullReference" type="string">
            <column name="FULL_REFERENCE" />
        </property>
        <property name="primarytitle" type="string">
            <column name="PRIMARYTITLE" />
        </property>
        <property name="title" type="string">
            <column name="TITLE" />
        </property>
    </class>
</hibernate-mapping>

TespEolMedia.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolmedia" table="TESP_EOLMEDIA" schema="DBA_IEPNB">
        <id name="idmedia" type="big_decimal">
            <column name="IDMEDIA" precision="22" scale="0" />
            <generator class="assigned" />
        </id>
        <set name="tespTaxons" table="TESP_TAXON_EOL_MEDIA" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="IDMEDIA" precision="22" scale="0" not-null="true" />
            </key>
            <many-to-many entity-name="es.magrama.iepnb.especies.bom.hibernate.tables.TespTaxon">
                <column name="TAXONID" precision="22" scale="0" not-null="true" />
            </many-to-many>
        </set>
        <set name="tespEolReferences" table="TESP_EOLMEDIAEOLREFERENCE" inverse="false" lazy="false" fetch="select">
            <key>
                <column name="IDMEDIA" precision="22" scale="0" not-null="true" />
            </key>
            <many-to-many entity-name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolReference">
                <column name="IDREFERENCE" precision="22" scale="0" not-null="true" />
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>

TespTaxon.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 26-ago-2016 9:41:02 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="es.magrama.iepnb.especies.bom.hibernate.tables.TespTaxon" table="TESP_TAXON" schema="DBA_IEPNB" lazy="true" >
        <id name="taxonid" type="big_decimal">
            <column name="TAXONID" precision="22" scale="0" />
            <generator class="assigned" />
        </id>
        <many-to-one name="tespPliniancoreExtension" class="es.magrama.iepnb.especies.bom.hibernate.tables.TespPliniancoreExtension" lazy="false" fetch="select">
            <column name="TAXONRECORDID" precision="22" scale="0" />
        </many-to-one>

        <set name="tespEolmedias" table="TESP_TAXON_EOL_MEDIA" inverse="false" lazy="false" fetch="select">
            <key>
                <column name="TAXONID" precision="22" scale="0" not-null="true" />
            </key>
            <many-to-many entity-name="es.magrama.iepnb.especies.bom.hibernate.tables.TespEolmedia">
                <column name="IDMEDIA" precision="22" scale="0" not-null="true" />
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>

0 个答案:

没有答案
相关问题