gpt4 book ai didi

java - 基本的 Hibernate 设置问题 : why is this resulting in one million null objects?

转载 作者:行者123 更新时间:2023-12-01 19:21:46 25 4
gpt4 key购买 nike

我有两个表:foo(主键:foo_id)和foo_entry(主键:foo_entry_id;外键:foo_id)。

下面是我的 Hibernate 配置。
我的问题是,当我在 FooModel 类上调用 getAttributes() 时,我最终得到了一个略多于一百万个空对象的列表。 (foo 表有约 200 行,foo_entry 有约 10,000 行)。

我是 Hibernate 新手,怀疑我只是忽略了或者只是不理解一些非常非常基本的东西。任何帮助表示赞赏!

<hibernate-mapping package="com.blah.www">
<class name="FooModel" table="foo">
<id name="fooId" column="foo_id"></id>

<list name="attributes" table="foo_entry">
<key column="foo_id" />
<index column="entry_id" />
<one-to-many class="FooEntryModel" />
</list>
</class>
</hibernate-mapping>

<hibernate-mapping package="com.blah.www">
<class name="FooEntryModel" table="foo_entry">
<id name="fooEntryId" column="foo_entry_id">
<generator class="native" />
</id>

<property name="fooId" type="int" column="foo_id" />
<property name="attrName" type="string" column="attr_name" />
<property name="attrValue" type="string" column="attr_value" />
<property name="startDate" type="timestamp" column="start_date" />
<property name="endDate" type="timestamp" column="end_date" />
</class>
</hibernate-mapping>

最佳答案

这些数字意味着您正在获得笛卡尔连接。您在数据库中设置了 FK 吗?

旁白 - 我使用 Hibernate 一年了,从未编写过属性注入(inject)模型或像您的节目那样的文件之一。我们总是对数据库进行逆向工程。

关于java - 基本的 Hibernate 设置问题 : why is this resulting in one million null objects?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3911463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com