java - Hibernate - OneToMany 仅检索一行

标签 java postgresql hibernate one-to-many

我有以下具有 @OneToMany 关系的类,但它只返回两行之一:

@Entity
@javax.persistence.Table(name = "as_itm_ext")
public class ItemExtensionEntity implements java.io.Serializable {

    @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
    @JoinColumns({ @JoinColumn(name = "id_itm", referencedColumnName = "id_itm", insertable = false, updatable = false) })
    public Set<ItemAttributeEntity> getItemAttributeEntities() {
        return this.itemAttributeEntities;
    }

    public void setItemAttributeEntities(Set<ItemAttributeEntity> itemAttributeEntities) {
        this.itemAttributeEntities = itemAttributeEntities;
    }
}

以及要检索的类:

@Entity
@javax.persistence.Table(name = "as_itm_att")
public class ItemAttributeEntity implements java.io.Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * AttributeKey,The key of the attribute.
     */
    private ItemAttributeEntityId id;

    /**
     * AttributeValue,The value of the attribute.
     */
    private String attributeValue;

    public ItemAttributeEntity() {
    }

    public ItemAttributeEntity(ItemAttributeEntityId id, String attributeValue) {
        this.id = id;
        this.attributeValue = attributeValue;
    }

    /**
     * AttributeKey,The key of the attribute.
     */
    @EmbeddedId
    @AttributeOverrides({
            @AttributeOverride(name = "itemId", column = @Column(name = "id_itm", nullable = false, length = 32)),
            @AttributeOverride(name = "attributeKey", column = @Column(name = "att_key", nullable = false, length = 32)) })
    public ItemAttributeEntityId getId() {
        return this.id;
    }

    public void setId(ItemAttributeEntityId id) {
        this.id = id;
    }

    /**
     * AttributeValue,The value of the attribute.
     */
    @Column(name = "att_value", nullable = false, length = 32)
    public String getAttributeValue() {
        return this.attributeValue;
    }

    public void setAttributeValue(String attributeValue) {
        this.attributeValue = attributeValue;
    }

}

我已经尝试将 Set 更改为 List 但没有成功(在阅读了一些关于它们之间的差异后,更改它是没有意义的)。

我不知道发生了什么,也不确定它是否总是这样。

谢谢!

更新:尝试实现等于,但什么也没发生。

最佳答案

尝试在 itemAttributeEntities 上使用 fetch = FetchType.LAZY

关于java - Hibernate - OneToMany 仅检索一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48100578/

相关文章:

sql - 计算 postgresql 中的再入院率

Spring 启动 : Executing the Newer version of SQL file each time we rebuild the application

mysql - 使用 @SqlDelete 的 JPA 软删除会导致 SQL 错误 : Parameter index out of range (2 > number of parameters,,即 1)

java - Hibernate二级缓存

hibernate - 在没有 Hibernate 或 GORM 的情况下使用 Grails 域类

java - Mysql:输入文本,使用哪种类型?

java - 如何重构 map 转换操作

java - WebSphere 应用程序 > 安全角色到用户/组映射 - 缺失

java - 将样式设置为 GWT ListBox 元素

sql - Postgres 循环更新记录