[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2904) Property-ref Child association has a null session on fetch
kumar_j2ee (JIRA)
noreply at atlassian.com
Mon Oct 22 15:30:39 EDT 2007
Property-ref Child association has a null session on fetch
----------------------------------------------------------
Key: HHH-2904
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2904
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.1.3
Environment: Hibernate Version: 3.1.3
Database: Oracle 10g,
Dialect: Oracle9Dialect
Reporter: kumar_j2ee
Priority: Blocker
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]
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list