]
Hontvári József commented on HHH-2459:
--------------------------------------
I think it is a bug, components within components are supported according to the hibernate
dtd (and they indeed work). The parent back-link functionality must also support a
component hierarchy, otherwise if you include a second level component in two parent
component then you were not be able to identify its actual parent.
Looking at the 3.2.2 code ComponentType.resolve recursively calls itself, but passes the
owner of the component to the included components as owner, not the component itself, so
the entity always will be the owner (parent), whatever is the level of the component:
<code>
Object result = instantiate( owner, session );
Object[] values = ( Object[] ) value;
Object[] resolvedValues = new Object[values.length]; //only really need new array during
semiresolve!
for ( int i = 0; i < values.length; i++ ) {
resolvedValues[i] = propertyTypes[i].resolve( values[i], session, owner );
}
</code>
However, simply replacing the owner parameter with the current component (referred by the
"result" variable) doesn't help, it causes an NPE, in a method named
proxyFor(), so I guess the the resolve method should have an additional parameter, the
containing component (which may be null, if the higher level object is the entity
itself).
Problem with <parent> for 2+ levels of components
-------------------------------------------------
Key: HHH-2459
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2459
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.2
Environment: Hibernate 3.2.2, Tested on PostgreSQL and HSQL
Reporter: Kevin Bragh
Attachments: test.zip
I have tested several scenarios similar to the above, and I have searched and posted to
the forum with no response.
I have attached the faulty code to the thread.
I have a main class (A) with 3 components recusively included as follows:
A -> B -> C <-> D
In the case above, D has a <parent> property to C.
While loading an instance of A, it seems that D.setC(...) is called with the value of the
main class A, and not of parent C.
I don't know if this is a bug, or if parent is not recusively supported.
Any help is appreciated.
Thks, K.
NB: I have tried many different examples (with list and composite-element, etc.) and they
all fail with 2+ levels of recursion.
Log
-----
2007-03-01 14:53:07,843 DEBUG [org.hibernate.impl.SessionImpl] - <opened session at
timestamp: 4803613441277952>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.transaction.JDBCTransaction] -
<begin>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.jdbc.ConnectionManager] - <opening JDBC
connection>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.connection.DriverManagerConnectionProvider]
- <total checked-out connections: 0>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.connection.DriverManagerConnectionProvider]
- <using pooled JDBC connection, pool size: 0>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.transaction.JDBCTransaction] - <current
autocommit status: false>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.jdbc.JDBCContext] - <after transaction
begin>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener]
- <saving transient instance>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] -
<saving [test.hibernate.recurse.A#<null>]>
2007-03-01 14:53:07,843 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] -
<executing insertions>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.engine.Versioning] - <using initial
version: 0>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] -
<Inserting entity: test.hibernate.recurse.A (native id)>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] -
<Version: 0>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to open
PreparedStatement (open PreparedStatements: 0, globally: 0)>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.SQL] - <insert into TEST_A (NO_VERSION,
VAL, VAL_B, VAL_C, VAL_D, UID) values (?, ?, ?, ?, ?, null)>
Hibernate: insert into TEST_A (NO_VERSION, VAL, VAL_B, VAL_C, VAL_D, UID) values (?, ?,
?, ?, ?, null)
2007-03-01 14:53:07,859 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <preparing
statement>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] -
<Dehydrating entity: [test.hibernate.recurse.A#<null>]>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.type.IntegerType] - <binding '0'
to parameter: 1>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.type.IntegerType] - <binding '0'
to parameter: 2>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.type.IntegerType] - <binding '0'
to parameter: 3>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.type.IntegerType] - <binding '0'
to parameter: 4>
2007-03-01 14:53:07,859 DEBUG [org.hibernate.type.IntegerType] - <binding '0'
to parameter: 5>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to close
PreparedStatement (open PreparedStatements: 1, globally: 1)>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <closing
statement>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to open
PreparedStatement (open PreparedStatements: 0, globally: 0)>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.SQL] - <call identity()>
Hibernate: call identity()
2007-03-01 14:53:07,875 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <preparing
statement>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] -
<Natively generated identity: 1>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to close
PreparedStatement (open PreparedStatements: 1, globally: 1)>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <closing
statement>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<flushing session>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<processing flush-time cascades>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<dirty checking collections>
2007-03-01 14:53:07,875 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Flushing entities and processing referenced collections>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Processing unreferenced collections>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Scheduling collection removes/(re)creates/updates>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.pretty.Printer] - <listing entities:>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.pretty.Printer] -
<test.hibernate.recurse.A{val=0, b=component[valB,c]{valB=0,
c=component[valC,d]{d=component[valD]{valD=0}, valC=0}}, id=1, version=0}>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<executing flush>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<post flush>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.transaction.JDBCTransaction] -
<commit>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.impl.SessionImpl] - <automatically
flushing session>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<flushing session>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<processing flush-time cascades>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<dirty checking collections>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Flushing entities and processing referenced collections>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Processing unreferenced collections>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Scheduling collection removes/(re)creates/updates>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.pretty.Printer] - <listing entities:>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.pretty.Printer] -
<test.hibernate.recurse.A{val=0, b=component[valB,c]{valB=0,
c=component[valC,d]{d=component[valD]{valD=0}, valC=0}}, id=1, version=0}>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<executing flush>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] -
<post flush>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.jdbc.JDBCContext] - <before transaction
completion>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.impl.SessionImpl] - <before transaction
completion>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.transaction.JDBCTransaction] - <committed
JDBC Connection>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.jdbc.JDBCContext] - <after transaction
completion>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.jdbc.ConnectionManager] - <aggressively
releasing JDBC connection>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.jdbc.ConnectionManager] - <closing JDBC
connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally:
0)]>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.connection.DriverManagerConnectionProvider]
- <returning connection to pool, pool size: 1>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.impl.SessionImpl] - <after transaction
completion>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.impl.SessionImpl] - <closing session>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.jdbc.ConnectionManager] - <connection
already null in cleanup : no action>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.impl.SessionImpl] - <opened session at
timestamp: 4803613441597440>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.transaction.JDBCTransaction] -
<begin>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.jdbc.ConnectionManager] - <opening JDBC
connection>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.connection.DriverManagerConnectionProvider]
- <total checked-out connections: 0>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.connection.DriverManagerConnectionProvider]
- <using pooled JDBC connection, pool size: 0>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.transaction.JDBCTransaction] - <current
autocommit status: false>
2007-03-01 14:53:07,890 DEBUG [org.hibernate.jdbc.JDBCContext] - <after transaction
begin>
2007-03-01 14:53:07,906 DEBUG [org.hibernate.engine.query.QueryPlanCache] - <unable to
locate HQL query plan in cache; generating (from test.hibernate.recurse.A)>
2007-03-01 14:53:07,921 DEBUG [org.hibernate.jdbc.ConnectionManager] - <running
Session.finalize()>
2007-03-01 14:53:08,000 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] - <parse() -
HQL: from test.hibernate.recurse.A>
2007-03-01 14:53:08,015 DEBUG [org.hibernate.hql.ast.AST] - <--- HQL AST ---
\-[QUERY] 'query'
\-[SELECT_FROM] 'SELECT_FROM'
\-[FROM] 'from'
\-[RANGE] 'RANGE'
\-[DOT] '.'
+-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] 'test'
| | \-[IDENT] 'hibernate'
| \-[IDENT] 'recurse'
\-[IDENT] 'A'
>
2007-03-01 14:53:08,031 DEBUG [org.hibernate.hql.ast.ErrorCounter] -
<throwQueryException() : no errors>
2007-03-01 14:53:08,078 DEBUG [org.hibernate.hql.antlr.HqlSqlBaseWalker] - <select
<< begin [level=1, statement=select]>
2007-03-01 14:53:08,093 DEBUG [org.hibernate.hql.ast.tree.FromElement] -
<FromClause{level=1} : test.hibernate.recurse.A (no alias) -> a0_>
2007-03-01 14:53:08,093 DEBUG [org.hibernate.hql.antlr.HqlSqlBaseWalker] - <select :
finishing up [level=1, statement=select]>
2007-03-01 14:53:08,093 DEBUG [org.hibernate.hql.ast.HqlSqlWalker] - <processQuery() :
( SELECT ( FromClause{level=1} TEST_A a0_ ) )>
2007-03-01 14:53:08,109 DEBUG [org.hibernate.hql.ast.HqlSqlWalker] - <Derived SELECT
clause created.>
2007-03-01 14:53:08,109 DEBUG [org.hibernate.hql.ast.util.JoinProcessor] - <Using FROM
fragment [TEST_A a0_]>
2007-03-01 14:53:08,109 DEBUG [org.hibernate.hql.antlr.HqlSqlBaseWalker] - <select
>> end [level=1, statement=select]>
2007-03-01 14:53:08,109 DEBUG [org.hibernate.hql.ast.AST] - <--- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (TEST_A)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'a0_.UID as UID0_'
{FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy
properties,classAlias=null,role=null,tableName=TEST_A,tableAlias=a0_,origin=null,colums={,className=test.hibernate.recurse.A}}}
| \-[SQL_TOKEN] SqlFragment: 'a0_.NO_VERSION as NO2_0_, a0_.VAL as VAL0_,
a0_.VAL_B as VAL4_0_, a0_.VAL_C as VAL5_0_, a0_.VAL_D as VAL6_0_'
\-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1,
fromElements=1, fromElementByClassAlias=[], fromElementByTableAlias=[a0_],
fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
\-[FROM_FRAGMENT] FromElement: 'TEST_A a0_' FromElement{explicit,not a
collection join,not a fetch join,fetch non-lazy
properties,classAlias=null,role=null,tableName=TEST_A,tableAlias=a0_,origin=null,colums={,className=test.hibernate.recurse.A}}
>
2007-03-01 14:53:08,109 DEBUG [org.hibernate.hql.ast.ErrorCounter] -
<throwQueryException() : no errors>
2007-03-01 14:53:08,125 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] - <HQL: from
test.hibernate.recurse.A>
2007-03-01 14:53:08,125 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] - <SQL:
select a0_.UID as UID0_, a0_.NO_VERSION as NO2_0_, a0_.VAL as VAL0_, a0_.VAL_B as VAL4_0_,
a0_.VAL_C as VAL5_0_, a0_.VAL_D as VAL6_0_ from TEST_A a0_>
2007-03-01 14:53:08,125 DEBUG [org.hibernate.hql.ast.ErrorCounter] -
<throwQueryException() : no errors>
2007-03-01 14:53:08,140 DEBUG [org.hibernate.engine.query.HQLQueryPlan] - <HQL param
location recognition took 0 mills (from test.hibernate.recurse.A)>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.engine.query.QueryPlanCache] - <located
HQL query plan in cache (from test.hibernate.recurse.A)>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.engine.query.HQLQueryPlan] - <find: from
test.hibernate.recurse.A>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.engine.QueryParameters] - <named
parameters: {}>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to open
PreparedStatement (open PreparedStatements: 0, globally: 0)>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.SQL] - <select a0_.UID as UID0_,
a0_.NO_VERSION as NO2_0_, a0_.VAL as VAL0_, a0_.VAL_B as VAL4_0_, a0_.VAL_C as VAL5_0_,
a0_.VAL_D as VAL6_0_ from TEST_A a0_>
Hibernate: select a0_.UID as UID0_, a0_.NO_VERSION as NO2_0_, a0_.VAL as VAL0_, a0_.VAL_B
as VAL4_0_, a0_.VAL_C as VAL5_0_, a0_.VAL_D as VAL6_0_ from TEST_A a0_
2007-03-01 14:53:08,156 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <preparing
statement>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to open
ResultSet (open ResultSets: 0, globally: 0)>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.loader.Loader] - <processing result
set>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.loader.Loader] - <result set row: 0>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.type.LongType] - <returning '1'
as column: UID0_>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.loader.Loader] - <result row:
EntityKey[test.hibernate.recurse.A#1]>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.loader.Loader] - <Initializing object
from ResultSet: [test.hibernate.recurse.A#1]>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] -
<Hydrating entity: [test.hibernate.recurse.A#1]>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.type.IntegerType] - <returning
'0' as column: NO2_0_>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.type.IntegerType] - <returning
'0' as column: VAL0_>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.type.IntegerType] - <returning
'0' as column: VAL4_0_>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.type.IntegerType] - <returning
'0' as column: VAL5_0_>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.type.IntegerType] - <returning
'0' as column: VAL6_0_>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.engine.TwoPhaseLoad] - <Version: 0>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.loader.Loader] - <done processing result
set (1 rows)>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to close
ResultSet (open ResultSets: 1, globally: 1)>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to close
PreparedStatement (open PreparedStatements: 1, globally: 1)>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <closing
statement>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.loader.Loader] - <total objects hydrated:
1>
2007-03-01 14:53:08,156 DEBUG [org.hibernate.engine.TwoPhaseLoad] - <resolving
associations for [test.hibernate.recurse.A#1]>
2007-03-01 14:53:08,156 ERROR [org.hibernate.property.BasicPropertyAccessor] -
<IllegalArgumentException in class: test.hibernate.recurse.D, setter method of
property: c>
2007-03-01 14:53:08,156 ERROR [org.hibernate.property.BasicPropertyAccessor] -
<expected type: test.hibernate.recurse.C, actual value: test.hibernate.recurse.A>
Exception stack trace
-----------------------------
Exception in thread "main" org.hibernate.PropertyAccessException:
IllegalArgumentException occurred while calling setter of test.hibernate.recurse.D.c
at
org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.PojoComponentTuplizer.setParent(PojoComponentTuplizer.java:132)
at org.hibernate.type.ComponentType.instantiate(ComponentType.java:438)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:524)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:528)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:528)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at test.hibernate.recurse.Main.main(Main.java:67)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 18 more
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: