-->
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.  [ 2 posts ] 
Author Message
 Post subject: Property is not injected into SQL statement
PostPosted: Fri Dec 15, 2006 2:39 pm 
Newbie

Joined: Fri Aug 05, 2005 5:37 pm
Posts: 2
My problem is hibernate recognizes the property to be set in the mapping file and then doesn't put that property in the generated sql. It insteads uses the primary key value and sets that property to its value.

In my example, the property activityDescription should be populated from the column ACTIVITY in the dto named Activity.

Is there a problem when the DTO class and one of the columns in the table are the same name? Previously this property had been named activity as well and I renamed it to activityDescription thinking this was the problem but it fixed itself for about 3 selects and then disappeared.

Hibernate version: 3.0.5

Mapping documents:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory name="filetracker_session_factory">
      <property name="connection.datasource">jdbc.wcb.filetracker</property>
      <property name="jdbc.use_get_generated_keys">true</property>       
      <property name="show_sql">false</property>
      <property name="use_sql_comments">false</property>     
      <property name="use_outer_join">false</property>
      <property name="max_fetch_depth">0</property>
      <property name="default_schema">filetrack</property>
      <property name="dialect">org.hibernate.dialect.DB2Dialect</property>
      <!-- property name="jndi.url">t3://localhost:7001</property -->
        <!--property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property -->
        <property name="query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</property>
      <property name="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
      <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
        <property name="hibernate.jndi.weblogic.jndi.replicateBindings">false</property>       
      <!-- Mapping files -->       
        <mapping resource="org/wcb/filetracker/mapping/ClaimFile.hbm"/>
        <mapping resource="org/wcb/filetracker/mapping/Activity.hbm"/>
        <mapping resource="org/wcb/filetracker/mapping/Location.hbm"/>
   </session-factory>
</hibernate-configuration>

Activity.hbm

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade="none">
   <class name="org.wcb.filetracker.dto.Activity" table="ACTIVITY_HISTORY">
      <id name="activityID" column="ACTIVITY_ID" type="integer">
         <generator class="identity"/>
      </id>
      <timestamp name="activityTimestamp" column="ACTIVITY_TIMESTAMP" unsaved-value="null"/>
      <property name="activityDescription" column="ACTIVITY" type="string"/>
      <many-to-one name="location" class="org.wcb.filetracker.dto.Location" column="LOCATION_ID" lazy="false"/>
      <many-to-one name="claimFile" class="org.wcb.filetracker.dto.ClaimFile" column="CLAIM_FILE_ID"/>
   </class>
</hibernate-mapping>



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

            ActivityDAO dao = new ActivityDAO(ftSession);

            try {
                c = dao.getClaimFileActivities(claimFile);
            } catch( HibernateException he){
                throw new EJBException(he);
            }

From ActivityDAO
   public Collection getClaimFileActivities(ClaimFile claimFile){
        Query q = getSession().createQuery("select a from Activity a join a.claimFile cf "
                    + "where cf.claimNumber = :claimNumber "
                    + "order by a.activityTimestamp desc");
        q.setParameter("claimNumber",claimFile.getClaimNumber());

        return q.list();
   }


Name and version of the database you are using:
15 Dec 2006 11:32:35,213 INFO SettingsFactory: RDBMS: DB2/6000, version: 8.2.3
15 Dec 2006 11:32:35,229 INFO SettingsFactory: JDBC driver: DB2, version: 3.40.63 (012751.007229.012452)

The generated SQL (show_sql=true):
select activity0_.ACTIVITY_ID as ACTIVITY1_, activity0_.ACTIVITY_TIMESTAMP as ACTIVITY2_1_, activity0_.LOCATION_ID as LOCATION4_1_, activity0_.CLAIM_FILE_ID as CLAIM5_1_ from filetrack.ACTIVITY_HISTORY activity0_ inner join filetrack.CLAIM_FILE claimfile1_ on activity0_.CLAIM_FILE_ID=claimfile1_.CLAIM_FILE_ID where claimfile1_.CLAIM_NUMBER=? order by activity0_.ACTIVITY_TIMESTAMP desc

Debug level Hibernate log excerpt:
Code:
15 Dec 2006 11:32:34,854 INFO  HbmBinder      : Mapping class: org.wcb.filetracker.dto.Activity -> ACTIVITY_HISTORY
15 Dec 2006 11:32:34,854 DEBUG HbmBinder      : Mapped property: activityID -> ACTIVITY_ID
15 Dec 2006 11:32:34,854 DEBUG HbmBinder      : Mapped property: activityTimestamp -> ACTIVITY_TIMESTAMP
15 Dec 2006 11:32:34,854 DEBUG HbmBinder      : Mapped property: activityDescription -> ACTIVITY
15 Dec 2006 11:32:34,947 DEBUG HbmBinder      : Mapped property: location -> LOCATION_ID
15 Dec 2006 11:32:34,947 DEBUG HbmBinder      : Mapped property: claimFile -> CLAIM_FILE_ID

15 Dec 2006 11:32:37,697 DEBUG SessionFactoryObjectFactory: JNDI lookup: hibernate:filetracker_session_factory
15 Dec 2006 11:32:37,697 DEBUG SessionFactoryObjectFactory: lookup: uid=2c918a8d0f872c28010f872c2d4d0000
15 Dec 2006 11:32:37,697 DEBUG SessionImpl    : opened session at timestamp: 4776771410726912
15 Dec 2006 11:32:37,697 DEBUG SessionImpl    : find: select a from Activity a join a.claimFile cf where cf.claimNumber = :claimNumber order by a.activityTimestamp desc
15 Dec 2006 11:32:37,697 DEBUG QueryParameters: named parameters: {claimNumber=10281783}
15 Dec 2006 11:32:37,697 DEBUG QueryTranslatorImpl: parse() - HQL: select a from org.wcb.filetracker.dto.Activity a join a.claimFile cf where cf.claimNumber = :claimNumber order by a.activityTimestamp desc
15 Dec 2006 11:32:37,713 DEBUG AST            : --- HQL AST ---
\-[QUERY] 'query'
    +-[SELECT_FROM] 'SELECT_FROM'
    |  +-[FROM] 'from'
    |  |  +-[RANGE] 'RANGE'
    |  |  |  +-[DOT] '.'
    |  |  |  |  +-[DOT] '.'
    |  |  |  |  |  +-[DOT] '.'
    |  |  |  |  |  |  +-[DOT] '.'
    |  |  |  |  |  |  |  +-[IDENT] 'org'
    |  |  |  |  |  |  |  \-[IDENT] 'wcb'
    |  |  |  |  |  |  \-[IDENT] 'filetracker'
    |  |  |  |  |  \-[IDENT] 'dto'
    |  |  |  |  \-[IDENT] 'Activity'
    |  |  |  \-[ALIAS] 'a'
    |  |  \-[JOIN] 'join'
    |  |     +-[DOT] '.'
    |  |     |  +-[IDENT] 'a'
    |  |     |  \-[IDENT] 'claimFile'
    |  |     \-[ALIAS] 'cf'
    |  \-[SELECT] 'select'
    |     \-[IDENT] 'a'
    +-[WHERE] 'where'
    |  \-[EQ] '='
    |     +-[DOT] '.'
    |     |  +-[IDENT] 'cf'
    |     |  \-[IDENT] 'claimNumber'
    |     \-[COLON] ':'
    |        \-[IDENT] 'claimNumber'
    \-[ORDER] 'order'
       +-[DOT] '.'
       |  +-[IDENT] 'a'
       |  \-[IDENT] 'activityTimestamp'
       \-[DESCENDING] 'desc'

15 Dec 2006 11:32:37,713 DEBUG ErrorCounter   : throwQueryException() : no errors
15 Dec 2006 11:32:37,713 DEBUG HqlSqlBaseWalker: query() << begin, level = 1
15 Dec 2006 11:32:37,713 DEBUG FromElement    : FromClause{level=1} :  org.wcb.filetracker.dto.Activity (a) -> activity0_
15 Dec 2006 11:32:37,713 DEBUG FromReferenceNode: Resolved :  a -> activity0_.ACTIVITY_ID
15 Dec 2006 11:32:37,729 DEBUG DotNode        : getDataType() : claimFile -> org.hibernate.type.ManyToOneType(org.wcb.filetracker.dto.ClaimFile)
15 Dec 2006 11:32:37,744 DEBUG DotNode        : dereferenceEntityJoin() : generating join for claimFile in org.wcb.filetracker.dto.Activity (cf) parent = [ {null} ]
15 Dec 2006 11:32:37,744 DEBUG FromElement    : FromClause{level=1} :  org.wcb.filetracker.dto.ClaimFile (cf) -> claimfile1_
15 Dec 2006 11:32:37,744 DEBUG FromClause     : addJoinByPathMap() : a.claimFile -> filetrack.CLAIM_FILE claimfile1_
15 Dec 2006 11:32:37,760 DEBUG FromReferenceNode: Resolved :  a.claimFile -> activity0_.CLAIM_FILE_ID
15 Dec 2006 11:32:37,760 DEBUG HqlSqlWalker   : createFromJoinElement() : -- join tree --
\-[JOIN_FRAGMENT] FromElement: 'filetrack.CLAIM_FILE claimfile1_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=cf,role=null,tableName=filetrack.CLAIM_FILE,tableAlias=claimfile1_,colums={activity0_.CLAIM_FILE_ID ,className=org.wcb.filetracker.dto.ClaimFile}}

15 Dec 2006 11:32:37,760 DEBUG FromReferenceNode: Resolved :  a -> activity0_.ACTIVITY_ID
15 Dec 2006 11:32:37,760 DEBUG FromReferenceNode: Resolved :  cf -> claimfile1_.CLAIM_FILE_ID
15 Dec 2006 11:32:37,760 DEBUG DotNode        : getDataType() : claimNumber -> org.hibernate.type.StringType@ee4a22
15 Dec 2006 11:32:37,760 DEBUG FromReferenceNode: Resolved :  cf.claimNumber -> claimfile1_.CLAIM_NUMBER
15 Dec 2006 11:32:37,776 DEBUG FromReferenceNode: Resolved :  a -> activity0_.ACTIVITY_ID
15 Dec 2006 11:32:37,776 DEBUG DotNode        : getDataType() : activityTimestamp -> org.hibernate.type.TimestampType@ee4a25
15 Dec 2006 11:32:37,776 DEBUG FromReferenceNode: Resolved :  a.activityTimestamp -> activity0_.ACTIVITY_TIMESTAMP
15 Dec 2006 11:32:37,776 DEBUG HqlSqlBaseWalker: query() : finishing up , level = 1
15 Dec 2006 11:32:37,776 DEBUG HqlSqlWalker   : processQuery() :  ( SELECT ( {select clause} activity0_.ACTIVITY_ID ) ( FromClause{level=1} ( filetrack.ACTIVITY_HISTORY activity0_ filetrack.CLAIM_FILE claimfile1_ ) ) ( where ( = ( claimfile1_.CLAIM_NUMBER claimfile1_.CLAIM_FILE_ID claimNumber ) ? ) ) ( order ( activity0_.ACTIVITY_TIMESTAMP activity0_.ACTIVITY_ID activityTimestamp ) desc ) )
15 Dec 2006 11:32:37,776 DEBUG JoinProcessor  : Using FROM fragment [inner join filetrack.CLAIM_FILE claimfile1_ on activity0_.CLAIM_FILE_ID=claimfile1_.CLAIM_FILE_ID]
15 Dec 2006 11:32:37,776 DEBUG JoinProcessor  : Using FROM fragment [filetrack.ACTIVITY_HISTORY activity0_]
15 Dec 2006 11:32:37,776 DEBUG HqlSqlBaseWalker: query() >> end, level = 1
15 Dec 2006 11:32:37,791 DEBUG AST            : --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT'  querySpaces (filetrack.CLAIM_FILE,filetrack.ACTIVITY_HISTORY)
    +-[SELECT_CLAUSE] SelectClause: '{select clause}'
    |  +-[ALIAS_REF] IdentNode: 'activity0_.ACTIVITY_ID as ACTIVITY1_' {alias=a, className=org.wcb.filetracker.dto.Activity, tableAlias=activity0_}
    |  \-[SQL_TOKEN] SqlFragment: 'activity0_.ACTIVITY_TIMESTAMP as ACTIVITY2_1_, activity0_.LOCATION_ID as LOCATION4_1_, activity0_.CLAIM_FILE_ID as CLAIM5_1_'
    +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=2, fromElements=2, fromElementByClassAlias=[a, cf], fromElementByTableAlias=[claimfile1_, activity0_], fromElementsByPath=[a.claimFile], collectionJoinFromElementsByPath=[], impliedElements=[]}
    |  \-[FROM_FRAGMENT] FromElement: 'filetrack.ACTIVITY_HISTORY activity0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=a,role=null,tableName=filetrack.ACTIVITY_HISTORY,tableAlias=activity0_,colums={,className=org.wcb.filetracker.dto.Activity}}
    |     \-[JOIN_FRAGMENT] FromElement: 'inner join filetrack.CLAIM_FILE claimfile1_ on activity0_.CLAIM_FILE_ID=claimfile1_.CLAIM_FILE_ID' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=cf,role=null,tableName=filetrack.CLAIM_FILE,tableAlias=claimfile1_,colums={activity0_.CLAIM_FILE_ID ,className=org.wcb.filetracker.dto.ClaimFile}}
    +-[WHERE] SqlNode: 'where'
    |  \-[EQ] SqlNode: '='
    |     +-[DOT] DotNode: 'claimfile1_.CLAIM_NUMBER' {propertyName=claimNumber,dereferenceType=4,propertyPath=claimNumber,path=cf.claimNumber,tableAlias=claimfile1_,className=org.wcb.filetracker.dto.ClaimFile,classAlias=cf}
    |     |  +-[ALIAS_REF] IdentNode: 'claimfile1_.CLAIM_FILE_ID' {alias=cf, className=org.wcb.filetracker.dto.ClaimFile, tableAlias=claimfile1_}
    |     |  \-[IDENT] IdentNode: 'claimNumber' {originalText=claimNumber}
    |     \-[NAMED_PARAM] SqlNode: '?'
    \-[ORDER] OrderByClause: 'order'
       +-[DOT] DotNode: 'activity0_.ACTIVITY_TIMESTAMP' {propertyName=activityTimestamp,dereferenceType=4,propertyPath=activityTimestamp,path=a.activityTimestamp,tableAlias=activity0_,className=org.wcb.filetracker.dto.Activity,classAlias=a}
       |  +-[ALIAS_REF] IdentNode: 'activity0_.ACTIVITY_ID' {alias=a, className=org.wcb.filetracker.dto.Activity, tableAlias=activity0_}
       |  \-[IDENT] IdentNode: 'activityTimestamp' {originalText=activityTimestamp}
       \-[DESCENDING] SqlNode: 'desc'

15 Dec 2006 11:32:37,791 DEBUG ErrorCounter   : throwQueryException() : no errors
15 Dec 2006 11:32:37,791 DEBUG QueryTranslatorImpl: HQL: select a from org.wcb.filetracker.dto.Activity a join a.claimFile cf where cf.claimNumber = :claimNumber order by a.activityTimestamp desc
15 Dec 2006 11:32:37,791 DEBUG QueryTranslatorImpl: SQL: select activity0_.ACTIVITY_ID as ACTIVITY1_, activity0_.ACTIVITY_TIMESTAMP as ACTIVITY2_1_, activity0_.LOCATION_ID as LOCATION4_1_, activity0_.CLAIM_FILE_ID as CLAIM5_1_ from filetrack.ACTIVITY_HISTORY activity0_ inner join filetrack.CLAIM_FILE claimfile1_ on activity0_.CLAIM_FILE_ID=claimfile1_.CLAIM_FILE_ID where claimfile1_.CLAIM_NUMBER=? order by activity0_.ACTIVITY_TIMESTAMP desc
15 Dec 2006 11:32:37,791 DEBUG ErrorCounter   : throwQueryException() : no errors
15 Dec 2006 11:32:37,791 DEBUG AbstractBatcher: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15 Dec 2006 11:32:37,791 DEBUG ConnectionManager: opening JDBC connection
15 Dec 2006 11:32:37,807 DEBUG JDBCContext    : successfully registered Synchronization
15 Dec 2006 11:32:37,807 DEBUG SQL            : select activity0_.ACTIVITY_ID as ACTIVITY1_, activity0_.ACTIVITY_TIMESTAMP as ACTIVITY2_1_, activity0_.LOCATION_ID as LOCATION4_1_, activity0_.CLAIM_FILE_ID as CLAIM5_1_ from filetrack.ACTIVITY_HISTORY activity0_ inner join filetrack.CLAIM_FILE claimfile1_ on activity0_.CLAIM_FILE_ID=claimfile1_.CLAIM_FILE_ID where claimfile1_.CLAIM_NUMBER=? order by activity0_.ACTIVITY_TIMESTAMP desc
15 Dec 2006 11:32:37,807 DEBUG AbstractBatcher: preparing statement
15 Dec 2006 11:32:37,822 DEBUG QueryLoader    : bindNamedParameters() 10281783 -> claimNumber [1]
15 Dec 2006 11:32:37,822 DEBUG StringType     : binding '10281783' to parameter: 1
15 Dec 2006 11:32:37,822 DEBUG AbstractBatcher: about to open ResultSet (open ResultSets: 0, globally: 0)
15 Dec 2006 11:32:37,822 DEBUG Loader         : processing result set
15 Dec 2006 11:32:37,822 DEBUG Loader         : result set row: 0
15 Dec 2006 11:32:37,822 DEBUG IntegerType    : returning '498' as column: ACTIVITY1_
15 Dec 2006 11:32:37,822 DEBUG Loader         : result row: EntityKey[org.wcb.filetracker.dto.Activity#498]
15 Dec 2006 11:32:37,822 DEBUG Loader         : Initializing object from ResultSet: [org.wcb.filetracker.dto.Activity#498]
15 Dec 2006 11:32:37,822 DEBUG BasicEntityPersister: Hydrating entity: [org.wcb.filetracker.dto.Activity#498]
15 Dec 2006 11:32:37,822 DEBUG TimestampType  : returning '2006-12-13 16:12:48' as column: ACTIVITY2_1_
15 Dec 2006 11:32:37,822 DEBUG StringType     : returning '498' as column: ACTIVITY1_
15 Dec 2006 11:32:37,822 DEBUG IntegerType    : returning '71' as column: LOCATION4_1_
15 Dec 2006 11:32:37,822 DEBUG IntegerType    : returning '101' as column: CLAIM5_1_
15 Dec 2006 11:32:37,822 DEBUG TwoPhaseLoad   : Version: 2006-12-13 16:12:48.933
15 Dec 2006 11:32:37,822 DEBUG Loader         : result set row: 1


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 8:36 pm 
Regular
Regular

Joined: Thu Jul 29, 2004 11:55 pm
Posts: 75
Not sure if this was an issue with 3.0.5, but there was a bug in the 3.0.x tree where if the name was the same to a certain number of characters, it would think it was the same field and set the value twice. Try changing the activitydescription column to description and see if the issue goes away.


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

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.