-->
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: can't get one-to-many to auto-populate
PostPosted: Tue Oct 09, 2007 9:44 pm 
Newbie

Joined: Tue Oct 09, 2007 9:16 pm
Posts: 1
I am having a devil of a time getting the first (of several to come) one-to-many associations described and working. In this case, a report program needs to load a client's record and I want to have all the child table records loaded at the same time since I'm exporting the data to XML for processing with XSLT.

I've tried every version of the join I could gleen from the usual sources. Keep getting the "failed to ..." message (see below). This, despite the fact that I can see it read the client table and then the child barriers table right afterwards. What is it doing?

Anyone have any ideas? In this case, the client-barrier table is related to the client table via a FK of the client-id plus two other fields. Its a pretty complex mapping but a simple relationship otherwise.

Hibernate version: 3.2.0.ga

Mapping documents:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping package="com.logipath.gict.cts.db.data">

    <class name="Client" table="Info_Clients">

    <id name="ClientId" column="Client_ID" type="java.lang.Long"/>

    <property name="AltAdrsLine1" column="Alt_Adrs_1" type="java.lang.String" length="40"/>

    <!-- many more fields, as you'll see in the named query below
    I am using a named query w/native sql so I could get the
    descriptions of the code fields in one select, but the child
    tables (there are several) need to be done as one-to-manys.
    -->

    <!-- can't get this to work, as usual... -->
    <set name="allBarriers" lazy="false" mutable="false" cascade="none" inverse="true">
    <key column="Client_ID" not-null="true"/>
    <one-to-many class="ClientBarrierDescribed"/>
    <loader query-ref="ClientBarrierDescribedLoad"/>
    </set>

    </class>

    <sql-query name="ClientDemographicsDetailedById">
    <return alias="client" class="Client"/>
    <![CDATA[
    select ic.Client_ID, ic.Alt_Adrs_1, ic.Alt_Adrs_2, ic.Alt_City, ic.Alt_State, ic.Alt_ZIP,
    ic.Annual_Income, ic.Below_Poverty, ic.Caseworker_ID,
    icc.last_name + ', ' + icc.first_name as CaseWorkerName,
    ic.Citizen_Status, cc.description as CitizenStatusString,
    ic.Client_Hot_List, ic.Counselor_ID,
    icc2.last_name + ', ' + icc2.first_name as CounselorName,
    ic.Date_of_Last_Seizure, ic.Developmentally_Disabled, ic.DOB, ic.DOD,
    ic.Emer_Contact, ic.Emer_Phone, ic.Ethnicity, ce.description as EthnicityDescription,
    ic.Fax_Phone, ic.File_Locator,
    ic.First_Name, ic.Gender, cg.description as GenderDescription,
    ic.Hispanic_Descent, ic.Home_Is_TTY, ic.Home_Phone,
    ic.Household_Size, ic.Income_Set, ic.Is_Closed, ic.Last_Name, ic.Maiden_Name,
    ic.Mail_Adrs_1, ic.Mail_Adrs_2, ic.Mail_City, ic.Mail_State, ic.Mail_ZIP,
    ic.Medications, ic.Middle_Name, ic.Mobile_Phone, ic.Multiple_Disabilities,
    ic.Pager_Phone, ic.Path_Resume, ic.Physician_ID,
    iphys.last_name + ', ' + iphys.first_name as PhysicianName,
    ic.Preferred_Name, ic.Primary_Barrier, cb.description as PrimaryBarrierName,
    ic.PS_AFDC, ic.PS_FS, ic.PS_Other, ic.PS_Sctn8, ic.PS_SS, ic.PS_SSDI, ic.PS_SSI,
    ic.Secondary_Barrier, cb2.description as SecondaryBarrierName,
    ic.Severely_Disabled, ic.SSN, ic.Status_Code, cs.description as StatusDescription,
    ic.Work_Ext, ic.Work_Phone, ic.Who, ic.Last_Update, ic.comments, ic.email_address

    from info_clients ic, codes_gender cg, info_company_contacts icc,
    info_company_contacts icc2, codes_citizen cc, info_physicians iphys,
    codes_barrier cb, codes_barrier cb2, codes_status cs,
    codes_ethnicity ce

    where ic.gender = cg.gender_code
    and ic.caseworker_id = icc.contact_id
    and ic.counselor_id = icc2.contact_id
    and ic.citizen_status = cc.citizen_code
    and ic.physician_id = iphys.physician_id
    and ic.primary_barrier = cb.barrier
    and ic.secondary_barrier = cb2.barrier
    and ic.status_code = cs.status_code
    and ic.ethnicity = ce.ethnicity
    and client_id = ?
    ]]>
    </sql-query>

    </hibernate-mapping>

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping package="com.logipath.gict.cts.db.data">

    <class name="ClientBarrierDescribed">

    <composite-id class="ClientBarrierDescId">
    <key-property name="ClientId" column="Client_ID" type="java.lang.Long"/>
    <key-property name="BarrierId" column="Barrier_ID" type="java.lang.Integer"/>
    <key-property name="IsEapData" column="Eap_Data" type="java.lang.Integer"/>
    </composite-id>

    <property name="Description" column="description" type="java.lang.String" length="50"/>
    <property name="IsDisability" column="disability" type="java.lang.Integer"/>

    <property name="UpdatedBy" column="Who" type="java.lang.String" length="20"/>
    <property name="UpdatedWhen" column="Last_Update" type="java.sql.Timestamp"/>

    </class>

    <sql-query name="ClientBarrierDescribedLoad">
    <return alias="ClientBarrierDescribed" class="ClientBarrierDescribed"/>
    <![CDATA[
    select cb.client_id, cb.barrier_id, cb.eap_data, cb.who, cb.last_update,
    b.Description as description, b.Disability as disability
    from info_client_barriers cb, codes_barrier b
    where cb.barrier_id = b.barrier
    and cb.client_id = ?
    ]]>
    </sql-query>

    </hibernate-mapping>




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

I'm using JBoss as the container, but here is the code where the error shows up:

Code:
      client = (Client)records.get(0);
      // force Hibernate to flesh out the child tables
      Set barriers = client.getAllBarriers();
      session.close();
              clientXml.serializeToXml(CS_CLIENT_DATA, null);


The serializeToXml method accesses the Set and attempts to ge an iterator on it but finds NULL. Argh!

I've tried lots of different ways to "force" Hibernate to pre-populate the set, to no avail.

Full stack trace of any exception that occurs:
20:13:10,299 INFO [STDOUT] Hibernate: select ic.Client_ID, ic.Alt_Adrs_1, ic.Alt_Adrs_2, ic.Alt_City, ic.Alt_State, ic.Alt_ZIP,
ic.Annual_Income, ic.Below_Poverty, ic.Caseworker_ID,
icc.last_name + ', ' + icc.first_name as CaseWorkerName,
ic.Citizen_Status, cc.description as CitizenStatusString,
ic.Client_Hot_List, ic.Counselor_ID,
icc2.last_name + ', ' + icc2.first_name as CounselorName,
ic.Date_of_Last_Seizure, ic.Developmentally_Disabled, ic.DOB, ic.DOD,
ic.Emer_Contact, ic.Emer_Phone, ic.Ethnicity, ce.description as EthnicityDescription,
ic.Fax_Phone, ic.File_Locator,
ic.First_Name, ic.Gender, cg.description as GenderDescription,
ic.Hispanic_Descent, ic.Home_Is_TTY, ic.Home_Phone,
ic.Household_Size, ic.Income_Set, ic.Is_Closed, ic.Last_Name, ic.Maiden_Name,
ic.Mail_Adrs_1, ic.Mail_Adrs_2, ic.Mail_City, ic.Mail_State, ic.Mail_ZIP,
ic.Medications, ic.Middle_Name, ic.Mobile_Phone, ic.Multiple_Disabilities,
ic.Pager_Phone, ic.Path_Resume, ic.Physician_ID,
iphys.last_name + ', ' + iphys.first_name as PhysicianName,
ic.Preferred_Name, ic.Primary_Barrier, cb.description as PrimaryBarrierName,
ic.PS_AFDC, ic.PS_FS, ic.PS_Other, ic.PS_Sctn8, ic.PS_SS, ic.PS_SSDI, ic.PS_SSI,
ic.Secondary_Barrier, cb2.description as SecondaryBarrierName,
ic.Severely_Disabled, ic.SSN, ic.Status_Code, cs.description as StatusDescription,
ic.Work_Ext, ic.Work_Phone, ic.Who, ic.Last_Update, ic.comments, ic.email_address

from info_clients ic, codes_gender cg, info_company_contacts icc,
info_company_contacts icc2, codes_citizen cc, info_physicians iphys,
codes_barrier cb, codes_barrier cb2, codes_status cs,
codes_ethnicity ce

where ic.gender = cg.gender_code
and ic.caseworker_id = icc.contact_id
and ic.counselor_id = icc2.contact_id
and ic.citizen_status = cc.citizen_code
and ic.physician_id = iphys.physician_id
and ic.primary_barrier = cb.barrier
and ic.secondary_barrier = cb2.barrier
and ic.status_code = cs.status_code
and ic.ethnicity = ce.ethnicity
and client_id = ?
20:13:10,350 WARN [JDBCExceptionReporter] SQL Warning: 0, SQLState:
20:13:10,350 WARN [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to gwcts_centex
20:13:10,350 WARN [JDBCExceptionReporter] SQL Warning: 0, SQLState:
20:13:10,350 WARN [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database context to 'gwcts_centex'.
20:13:10,350 WARN [JDBCExceptionReporter] SQL Warning: 0, SQLState:
20:13:10,350 WARN [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english
20:13:10,350 WARN [JDBCExceptionReporter] SQL Warning: 0, SQLState:
20:13:10,350 WARN [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language setting to us_english.
20:13:10,380 INFO [STDOUT] Hibernate: select cb.client_id, cb.barrier_id, cb.eap_data, cb.who, cb.last_update,
b.Description as description, b.Disability as disability
from info_client_barriers cb, codes_barrier b
where cb.barrier_id = b.barrier
and cb.client_id = ?
20:13:12,726 INFO [STDOUT] Hibernate: select cb.client_id, cb.barrier_id, cb.eap_data, cb.who, cb.last_update,
b.Description as description, b.Disability as disability
from info_client_barriers cb, codes_barrier b
where cb.barrier_id = b.barrier
and cb.client_id = ?
20:13:14,756 ERROR [[faces]] Servlet.service() for servlet faces threw exception
javax.faces.FacesException: Error calling action method of component with id reportForm:cmdRunReport
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:109)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.logipath.gict.cts.reporting.AuthorizationFilter.doFilter(AuthorizationFilter.java:57)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:613)
Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{reportClient.runReport}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:156)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
... 32 more
Caused by: java.lang.NullPointerException
at org.hibernate.collection.PersistentSet.isEmpty(PersistentSet.java:146)
at com.logipath.gict.cts.reporting.client.ReportClient.runReport(ReportClient.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
... 33 more

Name and version of the database you are using: MSSQL 2000

The generated SQL (show_sql=true): (see above)


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.