繁体   English   中英

Hibernate在列表中使用外键一对多查询

[英]Hibernate query one to many with foreign key pass in the list

这是我的休眠映射文件:

<class name="com.cms.entity.ContentPartnerMaster" table="BFContentPartnerMaster">
    <!-- <cache include="non-lazy" usage="read-only"/> -->
    <id name="partnerId" type="int" column="Id">
        <generator class="native" />
    </id>
    <property name="partnerName" column="PartnerName" type="string" />
    <property name="partnerDescription" column="PartnerDescription"
        type="string" />
    <property name="isActive" column="isActive" type="boolean" />
    <property name="partnerSalt" column="PartnerSalt" type="string" />
    <bag name="carousels" table="BFCaraousal" inverse="true" lazy="true"
        fetch="select">
        <key>
            <column name="Id" not-null="true" />
        </key>
        <one-to-many class="com.cms.entity.Carousel" />
    </bag>

</class>

<class name="com.cms.entity.Carousel" table="BFCaraousal">

    <id name="caraousalId" type="int" column="CaraousalId">
        <generator class="native" />
    </id>

    <property name="section" column="Section" type="string" />
    <property name="caraousalName" column="CaraousalName" type="string" />
    <property name="dateModified" column="DateModified" type="date" />
    <property name="dateAdded" column="DateAdded" type="date" />
    <property name="addedBy" column="AddedBy" type="int" />
    <property name="countryId" column="countryid" type="int" />
    <property name="partnerId" column="PartnerId" type="int" />

</class>

这是我的代码:

public class ContentPartnerMaster implements Serializable {
    private static final long serialVersionUID = 1L;
    private int partnerId;
    private String partnerName;
    private String partnerDescription;
    private Boolean isActive;
    private String partnerSalt;
    private ArrayList<Carousel> carousels;

    // getter setter ..


public class Carousel implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer caraousalId;
    private Integer partnerId;
    private Integer countryId;
    private String section;
    private String caraousalName;
    private Integer addedBy;
    private Date dateAdded;
    private Date dateModified;

Hibernate在列表中使用外键一对多查询

调用com.cms.entity.ContentPartnerMaster.carousels setter时,发生诸如id IllegalArgumentException的抛出错误

尝试使用Set <>而不是ArrayList。

public class ContentPartnerMaster implements Serializable { ... private Set<Carousel> carousels;

以后再使用时,可以将其强制转换为List <>。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM