-->
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: Property-ref Child association has a null session on fetch
PostPosted: Fri Oct 19, 2007 10:58 am 
Newbie

Joined: Fri Oct 19, 2007 10:13 am
Posts: 1
Hibernate Version: 3.1.3

Database: Oracle 10g,
Dialect: Oracle9Dialect

Database Type: Legacy database with no single primary key foreign-key relationship. Also has all sorts of funky natural-business-keys, and we are trying our best to bend hibernate to retrofit for this database.

Very well given the back ground, here is what I have...

ObjectA has many ObjectB
ObjectB has many ObjectC.

ObjectA has a Composite-id combining 4 keys on the table.
ObjectB has a Composite-id combining all parents keys plus additional 2 keys.

ObjectC has a Composite-id combining subset of parents keys and additional 2 more keys.


Since the parents keys donot flow to the children as Foreign-key am forced to use a property-ref. So I ended up declaring a property-ref on ObjectB that matches the ObjectC unique key and mapped the ObjectC as a bag (one-to-many) on ObjectB.

Scenario;
I have to access ObjectA then get ObjectB from ObjectA and get ObjectC from ObjectB.
When I try fetching the association I get an error indicating the session is null with LazyInitializationException. I have a open session, its got nothing to do with hibernate transaction manager, am running my junits. The same works when the association in only one level deep for example I load ObjectB from database directly and then load ObjectC from ObjectB.
Session is open all the time.


I tried using Bag Sql Loader using Query-ref that brought in additional issues indicating "Not all parameters on the named query is set" Digging through the hibernate code I realized its treating the composite id as one named attribute
[i]
org.hibernate.impl.AbstractQueryImpl.java
protected void verifyParameters(boolean reserveFirstParameter) throws HibernateException {
if ( parameterMetadata.getNamedParameterNames().size() != namedParameters.size() + namedParameterLists.size() ) {
Set missingParams = new HashSet( parameterMetadata.getNamedParameterNames() );
missingParams.removeAll( namedParameterLists.keySet() );
missingParams.removeAll( namedParameters.keySet() );
throw new QueryException( "Not all named parameters have been set: " + missingParams, getQueryString() );
}
[/i]

getNamedParameterNames().size is returning back as 6 where as
namedParameters.size() returns back as 1.

If I try removing all the named parameters totally and tried loading the association... I started getting ...
[i]
public Query setParameter(int position, Object val, Type type) {
if ( parameterMetadata.getOrdinalParameterCount() == 0 ) {
throw new IllegalArgumentException("No positional parameters in query: " + getQueryString() );
}
[/i]


I tried multiple options one even with filter-def/ filter and realized Filter is not working for bags.

Can somebody help me understand if am doing something stupid. Or if this is a limitation and if there is any acceptable workaround.[color=blue][/color]


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.