-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Error in bidirectional associations with join tables
PostPosted: Thu Jun 02, 2005 11:35 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
Hi there,

I have a class Addr (table ADDR) and another class ElctrncAddr which is mapped as <subclass> of Addr. For more properties a join on table ELCTRNCADDR is used. For each ElctrncAddr an NetwrkService is specified. A NetwrkService can be used by more than one ElctrnAddresses. So I have a birectional one-to-many/many-to-one relationship.
When I create a new NetwrkService nws and a new ElctrncAddr ea with the reference to nws and update the collection ElctrncAddresses in nws, I can count how many ElctrncAddr use nws as NetwrkService by nws.getElctrncAddrs().size(). My problem is that when I load the NetwrkService in a instance by using a Criteria on NetwrkService with an Id-Restriction (the same happens when using currentSession().get(NetwrkService.class, id) and then try to count nws.getElctrncAddrs().size(), an error occurs.

Why? Hibnernate tries to get the columns netwrk_id and netwrk_service_ix not from ElctrncAddr but from Addr. There no such columns exist. What am I doing wrong? I can't see it.

Thanks a lot for your help! I'm really stuck...


Mapping documents (shortened):

Addr

<hibernate-mapping>
<class name="package.Addr" table="ADDR" discriminator-value="NOS ">
<id name="addrId" type="java.lang.Long" column="ADDR_ID" length="15">
<generator class="package.gh4.GH4IdGenerator">
<param name="sequence">addr_id_seq</param>
<param name="GH4IdType">Prefix</param>
</generator>
</id>
<discriminator column="CAT_CODE" type="string" />
... some properties ...
<!-- bi-directional one-to-many association to ObjItemAddr -->
<set name="objItemAddrs" lazy="true" inverse="true" cascade="none">
<key>
<column name="ADDR_ID" />
</key>
<one-to-many class="package.ObjItemAddr" />
</set>
</class>
</hibernate-mapping>


ElctrncAddr

<hibernate-mapping>
<subclass extends="package.Addr" name="package.ElctrncAddr" discriminator-value="ELCADR">
<join table="ELCTRNC_ADDR">
<key column="ADDR_ID" />
<property name="name" type="java.lang.String" column="NAME" length="50">
<meta attribute="field-description">@hibernate.property column="NAME" length="50"</meta>
</property>
... some more properties ...
<!-- bi-directional many-to-one association to NetwrkService -->
<many-to-one name="netwrkService" class="package.NetwrkService" property-ref="NetwrkServiceCompositeKey" not-null="true" update="true" insert="true">
<column name="NETWRK_SERVICE_IX" />
<column name="NETWRK_ID" />
</many-to-one>

</join>
</subclass>
</hibernate-mapping>


NetwrkService

<hibernate-mapping>
<class table="NETWRK_SERVICE" name="package.NetwrkService">
<id name="netwrkServiceIx" type="java.lang.Long" column="NETWRK_SERVICE_IX" length="15">
<generator class="package.gh4.GH4IdGenerator">
<param name="sequence">netwrk_service_index_seq</param>
<param name="GH4IdType">Prefix</param>
</generator>
</id>

<properties name="NetwrkServiceCompositeKey" unique="true" insert="false" update="false">
<property name="netwrkServiceIx" type="java.lang.Long" column="NETWRK_SERVICE_IX" length="15" insert="false" update="false">
</property>
<many-to-one name="netwrk" class="package.Netwrk" not-null="true" update="false" insert="false">
<column name="NETWRK_ID" />
</many-to-one>
</properties>

... some "normal" properties ...

<many-to-one name="netwrk" class="package.Netwrk" not-null="true" update="true" insert="true">
<column name="NETWRK_ID" />
</many-to-one>

<!-- bi-directional one-to-many association to ElctrncAddr -->
<set name="elctrncAddrs" lazy="true" inverse="true" cascade="none" table="ELCTRNC_ADDR">
<key property-ref="NetwrkServiceCompositeKey">
<column name="NETWRK_SERVICE_IX" />
<column name="NETWRK_ID" />
</key>
<one-to-many class="package.ElctrncAddr" />
</set>

</class>
</hibernate-mapping>

Hibernate version:
3.0.5

Code between sessionFactory.openSession() and session.close():

testcreate() {
NetwrkService nws = new NetwrkService("DRCTRY", nw);
ic.currentSession().save(nws);
ObjItemTestCase.nwsId = nws.getIdentifier();

ElctrncAddr ea = new ElctrncAddr(nws);
ic.currentSession().save(ea);
nws.addElctrncAddr(ea);
ObjItemTestCase.eaId = ea.getIdentifier();

Assert.assertNotNull(nws.getElctrncAddrsAccessedVia());
Assert.assertEquals(1, nws.getElctrncAddrsAccessedVia().size());
}

testRetrieve() {
NetwrkService nws = (NetwrkService) ic.currentSession()
.createCriteria(NetwrkService.class)
.add(Restrictions.idEq(ObjItemTestCase.nwsId))
.uniqueResult();;

nws.getNetwrk();
nws.getElctrncAddrsAccessedVia();

// failure in following line! (no AssertionFailure, but SQLException)
Assert.assertEquals(1, nws.getElctrncAddrsAccessedVia().size());

}

Full stack trace of any exception that occurs:
29031 DEBUG [main] org.hibernate.util.JDBCExceptionReporter - could not initialize a collection: [com.eads.c2iedm.hibernate.objitemcluster.NetwrkService.elctrncAddrsAccessedVia#component[netwrkServiceIx,netwrk]{netwrk=com.eads.c2iedm.hibernate.objitemcluster.Netwrk#203770100001345, netwrkServiceIx=203770100000029}] [select elctrncadd0_.NETWRK_SERVICE_IX as NETWRK6_1_, elctrncadd0_.NETWRK_ID as NETWRK7_1_, elctrncadd0_.ADDR_ID as ADDR1_1_, elctrncadd0_.ADDR_ID as ADDR1_0_, elctrncadd0_.PLACE_NAME_TXT as PLACE3_96_0_, elctrncadd0_.OWNER_ID as OWNER4_96_0_, elctrncadd0_.UPDATE_SEQNR as UPDATE5_96_0_, elctrncadd0_1_.NAME as NAME97_0_, elctrncadd0_1_.OWNER_ID as OWNER3_97_0_, elctrncadd0_1_.UPDATE_SEQNR as UPDATE4_97_0_, elctrncadd0_1_.NETWRK_SERVICE_IX as NETWRK5_97_0_, elctrncadd0_1_.NETWRK_ID as NETWRK6_97_0_ from ADDR elctrncadd0_ inner join ELCTRNC_ADDR elctrncadd0_1_ on elctrncadd0_.ADDR_ID=elctrncadd0_1_.ADDR_ID where elctrncadd0_.NETWRK_SERVICE_IX=? and elctrncadd0_.NETWRK_ID=?]
java.sql.SQLException: ORA-00904: Ung?ltiger Spaltenname

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:110)
at package.ObjItemTestCase.testRetrieve(ObjItemTestCase.java:290)
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 junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
29047 WARN [main] org.hibernate.util.JDBCExceptionReporter - SQL Error: 904, SQLState: 42000
29047 ERROR [main] org.hibernate.util.JDBCExceptionReporter - ORA-00904: Ung?ltiger Spaltenname


Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
Hibernate: insert into NETWRK_SERVICE (CAT_CODE, SUBCAT_CODE, OWNER_ID, UPDATE_SEQNR, NETWRK_ID, NETWRK_SERVICE_IX) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into ADDR (PLACE_NAME_TXT, OWNER_ID, UPDATE_SEQNR, CAT_CODE, ADDR_ID) values (?, ?, ?, 'ELCADR', ?)
Hibernate: insert into ELCTRNC_ADDR (NAME, OWNER_ID, UPDATE_SEQNR, NETWRK_SERVICE_IX, NETWRK_ID, ADDR_ID) values (?, ?, ?, ?, ?, ?)
Hibernate: update ELCTRNC_ADDR set NAME=?, OWNER_ID=?, UPDATE_SEQNR=?, NETWRK_SERVICE_IX=?, NETWRK_ID=? where ADDR_ID=?

Hibernate: select netwrkserv0_.NETWRK_SERVICE_IX as NETWRK1_0_, netwrkserv0_.NETWRK_SERVICE_IX as NETWRK1_57_0_, netwrkserv0_.NETWRK_ID as NETWRK2_57_0_, netwrkserv0_.CAT_CODE as CAT3_57_0_, netwrkserv0_.SUBCAT_CODE as SUBCAT4_57_0_, netwrkserv0_.OWNER_ID as OWNER5_57_0_, netwrkserv0_.UPDATE_SEQNR as UPDATE6_57_0_ from NETWRK_SERVICE netwrkserv0_ where netwrkserv0_.NETWRK_SERVICE_IX=?
Hibernate: select this_.NETWRK_SERVICE_IX as NETWRK1_0_, this_.NETWRK_SERVICE_IX as NETWRK1_57_0_, this_.NETWRK_ID as NETWRK2_57_0_, this_.CAT_CODE as CAT3_57_0_, this_.SUBCAT_CODE as SUBCAT4_57_0_, this_.OWNER_ID as OWNER5_57_0_, this_.UPDATE_SEQNR as UPDATE6_57_0_ from NETWRK_SERVICE this_ where this_.NETWRK_SERVICE_IX = ?
Hibernate: select elctrncadd0_.NETWRK_SERVICE_IX as NETWRK6_1_, elctrncadd0_.NETWRK_ID as NETWRK7_1_, elctrncadd0_.ADDR_ID as ADDR1_1_, elctrncadd0_.ADDR_ID as ADDR1_0_, elctrncadd0_.PLACE_NAME_TXT as PLACE3_96_0_, elctrncadd0_.OWNER_ID as OWNER4_96_0_, elctrncadd0_.UPDATE_SEQNR as UPDATE5_96_0_, elctrncadd0_1_.NAME as NAME97_0_, elctrncadd0_1_.OWNER_ID as OWNER3_97_0_, elctrncadd0_1_.UPDATE_SEQNR as UPDATE4_97_0_, elctrncadd0_1_.NETWRK_SERVICE_IX as NETWRK5_97_0_, elctrncadd0_1_.NETWRK_ID as NETWRK6_97_0_ from ADDR elctrncadd0_ inner join ELCTRNC_ADDR elctrncadd0_1_ on elctrncadd0_.ADDR_ID=elctrncadd0_1_.ADDR_ID where elctrncadd0_.NETWRK_SERVICE_IX=? and elctrncadd0_.NETWRK_ID=?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.