私は比較的新しく、1 対多のマッピングを使用して子エンティティを読み込もうとしています。しかし、初期化プロセス中に、ロードされているエンティティが 1 つしか表示されません。関連付けられた子テーブルには、ロードされていない行がさらに 3 行ありますが、クエリで 4 行が返されますが、これは正しいです。休止状態が初期化されていません。
ログ トレースに太字が表示されている場合、最初の行が初期化されていることがわかりますが、その後、残りの行はどれも初期化されていません。何が問題なのかわからない。役立つポインタをいくつか提供してください。どうもありがとう。
-ロン
以下はコード スニペットです。
EMP table;
EMP_ACCT table;
EMP_ID ACCT_TYPE ACCT_VAL
------ --------- --------
1001 checking test val
1001 savings test val1
1001 high yield savings test val2
1001 simple checking test val3
<!-- EMP table -->
<hibernate-mapping>
<class name="com.Employee" table="EMP" dynamic-update="true">
<id name="empId" type="java.lang.Integer">
<column name="EMP_ID" precision="5" scale="0" />
<generator class="assigned"></generator>
</id>
<property name="empName" type="java.lang.String">
<column name="EMP_NAME" length="100"/>
</property>
<set name="empAcctDetails" inverse="false" lazy="false" table="EMP_ACCT"
cascade="all" fetch="subselect">
<key>
<column name="EMP_ID" />
</key>
<one-to-many class="com.EmployeeAcctDetails" />
</set>
</class>
</hibernate-mapping>
<!-- EMP_ACCT table -->
<hibernate-mapping>
<class name="com.EmployeeAcctDetails" table="EMP_ACCT" dynamic-update="true">
<id name="empId" type="java.lang.Integer">
<column name="EMP_ID" precision="5" scale="0" />
<generator class="assigned"></generator>
</id>
<property name="acctName" type="java.lang.String">
<column name="ACCT_NAME" length="20"/>
</property>
<property name="acctValue" type="java.lang.String">
<column name="ACCT_VALUE" length="30" />
</property>
<many-to-one name="emp" class="com.domain.Employee" update="false" insert="false">
<column name="EMP_ID" />
</many-to-one>
</class>
</hibernate-mapping>
Log trace:
---------
2013-03-10 12:13:29,558 DEBUG [org.hibernate.SQL]-
/* load one-to-many com.domain.Employee.empAcctDetails */ select
empacctdet0_.EMP_ID as EMP1_1_,
empacctdet0_.EMP_ID as EMP1_81_0_,
empacctdet0_.ACCT_NAME as ACCT2_81_0_,
empacctdet0_.ACCT_VALUE as ACCT3_81_0_
from
EMP_ACCT empacctdet0_
where
empacctdet0_.EMP_ID=?
Hibernate:
/* load one-to-many com.domain.Employee.empAcctDetails */ select
empacctdet0_.EMP_ID as EMP1_1_,
empacctdet0_.EMP_ID as EMP1_81_0_,
empacctdet0_.ACCT_NAME as ACCT2_81_0_,
empacctdet0_.ACCT_VALUE as ACCT3_81_0_
from
EMP_ACCT empacctdet0_
where
empacctdet0_.EMP_ID=?
2013-03-10 12:13:29,558 TRACE [org.hibernate.jdbc.AbstractBatcher]- preparing statement
2013-03-10 12:13:29,604 TRACE [org.hibernate.type.IntegerType]- binding '1001' to parameter: 1
2013-03-10 12:13:29,683 DEBUG [org.hibernate.jdbc.AbstractBatcher]- about to open ResultSet (open ResultSets: 0, globally: 0)
2013-03-10 12:13:29,683 DEBUG [org.hibernate.loader.Loader]- result set contains (possibly empty) collection: [com.domain.Employee.empAcctDetails#1001]
2013-03-10 12:13:29,683 TRACE [org.hibernate.engine.loading.LoadContexts]- constructing collection load context for result set [oracle.jdbc.driver.OracleResultSetImpl@23102310]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- starting attempt to find loading collection [[com.domain.Employee.empAcctDetails#1001]]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- collection not yet initialized; initializing
2013-03-10 12:13:29,698 TRACE [org.hibernate.loader.Loader]- processing result set
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result set row: 0
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_81_0_
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result row: EntityKey[com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.loader.Loader]- Initializing object from ResultSet: [com.domain.EmployeeAcctDetails#1001]
**2013-03-10 12:13:29,698 TRACE [org.hibernate.persister.entity.AbstractEntityPersister]- Hydrating entity: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.StringType]- returning 'checking' as column: ACCT2_81_0_
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.StringType]- returning 'test val' as column: ACCT3_81_0_
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_81_0_
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_**
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- found row of collection: [com.domain.Employee.empAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- starting attempt to find loading collection [[com.domain.Employee.empAcctDetails#1001]]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- attempting to locate loading collection entry [CollectionKey[com.domain.Employee.empAcctDetails#1001]] in any result-set context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- collection [CollectionKey[com.domain.Employee.empAcctDetails#1001]] located in load context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- found loading collection bound to current result set processing; reading row
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- loading entity: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- attempting to resolve: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- resolved object in session cache: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result set row: 1
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_81_0_
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result row: EntityKey[com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- found row of collection: [com.domain.Employee.empAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- starting attempt to find loading collection [[com.domain.Employee.empAcctDetails#1001]]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- attempting to locate loading collection entry [CollectionKey[com.domain.Employee.empAcctDetails#1001]] in any result-set context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- collection [CollectionKey[com.domain.Employee.empAcctDetails#1001]] located in load context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- found loading collection bound to current result set processing; reading row
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- loading entity: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- attempting to resolve: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- resolved object in session cache: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result set row: 2
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_81_0_
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result row: EntityKey[com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- found row of collection: [com.domain.Employee.empAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- starting attempt to find loading collection [[com.domain.Employee.empAcctDetails#1001]]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- attempting to locate loading collection entry [CollectionKey[com.domain.Employee.empAcctDetails#1001]] in any result-set context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- collection [CollectionKey[com.domain.Employee.empAcctDetails#1001]] located in load context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- found loading collection bound to current result set processing; reading row
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- loading entity: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- attempting to resolve: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- resolved object in session cache: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result set row: 3
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_81_0_
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- result row: EntityKey[com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_
2013-03-10 12:13:29,698 DEBUG [org.hibernate.loader.Loader]- found row of collection: [com.domain.Employee.empAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- starting attempt to find loading collection [[com.domain.Employee.empAcctDetails#1001]]
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- attempting to locate loading collection entry [CollectionKey[com.domain.Employee.empAcctDetails#1001]] in any result-set context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.LoadContexts]- collection [CollectionKey[com.domain.Employee.empAcctDetails#1001]] located in load context
2013-03-10 12:13:29,698 TRACE [org.hibernate.engine.loading.CollectionLoadContext]- found loading collection bound to current result set processing; reading row
2013-03-10 12:13:29,698 TRACE [org.hibernate.type.IntegerType]- returning '1001' as column: EMP1_1_
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- loading entity: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- attempting to resolve: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.event.def.DefaultLoadEventListener]- resolved object in session cache: [com.domain.EmployeeAcctDetails#1001]
2013-03-10 12:13:29,698 TRACE [org.hibernate.loader.Loader]- done processing result set (4 rows)