-->
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 return-property be used to partially load a class?
PostPosted: Mon Jul 09, 2007 1:54 pm 
Beginner
Beginner

Joined: Tue Jul 25, 2006 12:34 pm
Posts: 25
Is it possible (as shown in the mapping file below) to have a SP as the source for a list() call but only populate part of the class? The SP is already in production and I'd rather not modify it. I thought the return-property would allow me to do that by specifying what was coming back from the SP. But the error message is no help (I didn't assign a column name of 'owner1_2_0_'). Do I have the name/column values transposed?

Hibernate version: 3.2.3

Mapping documents:
Code:
<?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">
<!--
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping package="us.tx.state.oag.ApplicationSecurity.db">

    <class name="InfoPublicAddress" table="info_public_address" schema="dbo" catalog="application_security">
   
        <composite-id name="id" class="us.tx.state.oag.ApplicationSecurity.db.InfoPublicAddressId">
            <key-property name="ownerTypeId" type="java.math.BigDecimal">
                <column name="owner_type_id" precision="18" scale="0" />
            </key-property>
            <key-property name="addressId" type="java.math.BigDecimal">
                <column name="address_id" precision="18" scale="0" />
            </key-property>
            <key-property name="parentId" type="java.math.BigDecimal">
                <column name="parent_id" precision="18" scale="0" />
            </key-property>
            <key-property name="addressTypeId" type="java.math.BigDecimal">
                <column name="address_type_id" precision="18" scale="0" />
            </key-property>
            <key-property name="dtEffective" type="java.sql.Timestamp">
                <column name="dt_effective" length="23" />
            </key-property>
        </composite-id>
       
        <property name="city" type="java.lang.String">
            <column name="city" length="30" not-null="true" />
        </property>
        <property name="inactive" type="java.lang.Integer">
            <column name="inactive" not-null="true" />
        </property>
        <property name="isPrimary" type="java.lang.Integer">
            <column name="is_primary" not-null="true" />
        </property>
        <property name="line1" type="java.lang.String">
            <column name="line_1" length="30" not-null="true" />
        </property>
        <property name="line2" type="java.lang.String">
            <column name="line_2" length="30" />
        </property>
        <property name="line3" type="java.lang.String">
            <column name="line_3" length="30" />
        </property>
        <property name="addressName" type="java.lang.String">
            <column name="address_name" length="60" not-null="true" />
        </property>
        <property name="stateCode" type="java.lang.String">
            <column name="state_code" length="6" not-null="true" />
        </property>
        <property name="postalCode" type="java.lang.String">
            <column name="postal_code" length="15" not-null="true" />
        </property>
        <property name="countyCode" type="java.lang.String">
            <column name="county_code" length="13" />
        </property>
        <property name="countryCode" type="java.lang.String">
            <column name="country_code" length="3" />
        </property>
        <property name="crUser" type="java.lang.String">
            <column name="cr_user" length="20" not-null="true" />
        </property>
        <property name="crDate" type="java.sql.Timestamp">
            <column name="cr_date" length="23" not-null="true" />
        </property>
        <property name="upUser" type="java.lang.String">
            <column name="up_user" length="20" not-null="true" />
        </property>
        <property name="upDate" type="java.sql.Timestamp">
            <column name="up_date" length="23" not-null="true" />
        </property>
    </class>

   <!-- NOTE: the first parameter, owner-type = 1 for users -->   
    <sql-query name="userAddresses" callable="true">
       <return alias="userAddress" class="InfoPublicAddress">
          <return-property name="addressName" column="address_name"/>
          <return-property name="line1" column="line_1"/>
          <return-property name="city" column="city"/>
          <return-property name="stateCode" column="state_code"/>
          <return-property name="postalCode" column="postal_code"/>
          <return-property name="countyCode" column="county_code"/>
          <return-property name="countryCode" column="country_code"/>
          <return-property name="isPrimary" column="is_primary"/>
          <return-property name="dtEffective" column="dt_effective"/>
          <return-property name="inactive" column="inactive"/>
          <return-property name="ownerTypeId" column="owner_type_id"/>
          <return-property name="addessId" column="address_id"/>
          <return-property name="parentId" column="parent_id"/>
          <return-property name="addressTypeId" column="address_type_id"/>
       </return>
      <![CDATA[
          { call info_public_addr_on_file_spr(1,?) }
       ]]>       
    </sql-query>

   <!-- NOTE: the first parameter, owner-type = 2 for companies -->   
    <sql-query name="companyAddresses" callable="true">
       <return alias="companyAddress" class="InfoPublicAddress"/>
      <![CDATA[
          { call info_public_addr_on_file_spr(2,?) }
       ]]>       
    </sql-query>

   <!-- NOTE: requires the entire key be supplied -->   
    <sql-query name="getPublicAddress" callable="true">
       <return alias="infoPublicAddress" class="InfoPublicAddress"/>
      <![CDATA[
          { call info_public_address_spr(?,?,?,?,?) }
       ]]>       
    </sql-query>
   
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
            lo_query = lo_sess.getNamedQuery(APPSEC_NQ_USER_ADDRESSES);
            lo_query.setBigDecimal(0, pl_userId);
            lo_numbers = (ArrayList)lo_query.list();


Full stack trace of any exception that occurs:
    12:32:38,828 INFO [BigDecimalType] could not read column value from result set: owner1_2_0_; Invalid column name owner1_2_0_.
    12:32:38,843 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 07009
    12:32:38,843 ERROR [JDBCExceptionReporter] Invalid column name owner1_2_0_.
    12:32:38,890 ERROR [STDERR] org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2223)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
    at us.tx.state.oag.ApplicationSecurity.PublicUserMgmt.getListAddressesByUserId(PublicUserMgmt.java:878)
    at us.tx.state.oag.OagPortalRegistration.RegisteredUserBean.loadUserAddresses(RegisteredUserBean.java:557)
    at us.tx.state.oag.OagPortalRegistration.RegisteredUserBean.gotoListAddresses(RegisteredUserBean.java:239)
    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.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
    at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
    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:100)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    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 us.tx.state.oag.OagPortalRegistration.AuthorizationFilter.doFilter(AuthorizationFilter.java:56)
    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(Unknown Source)
    Caused by: java.sql.SQLException: Invalid column name owner1_2_0_.
    at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:976)
    at net.sourceforge.jtds.jdbc.JtdsResultSet.getBigDecimal(JtdsResultSet.java:1225)
    at org.jboss.resource.adapter.jdbc.WrappedResultSet.getBigDecimal(WrappedResultSet.java:312)
    at org.hibernate.type.BigDecimalType.get(BigDecimalType.java:23)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
    at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
    at org.hibernate.type.ComponentType.hydrate(ComponentType.java:560)
    at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:275)
    at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
    at org.hibernate.loader.Loader.doQuery(Loader.java:701)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2220)
    ... 50 more

Name and version of the database you are using: Sybase 12.5

The generated SQL (show_sql=true): (none shown)

Extract From Stored Procedure
Code:
SELECT A.address_name,
   B.description AS address_type,
   A.line_1,
   A.city,
   A.state_code,
   A.postal_code,
   A.county_code,
   A.country_code,
   A.is_primary,
   A.dt_effective,
   A.inactive,
   A.owner_type_id,
   A.address_id,
   A.parent_id,
   A.address_type_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.