-->
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.  [ 3 posts ] 
Author Message
 Post subject: hibernate wrong bind columns and fields.
PostPosted: Thu Apr 14, 2005 4:17 am 
Newbie

Joined: Thu Mar 31, 2005 4:15 am
Posts: 4
When I get objects from DB and observe somthing wrong.

My select in java code is:
Code:
select rq from RMSTRequirementHistDTO as rq  where rq.id  = ?

My mapping from logs is:
Code:
- Mapped property: tempId -> TEMPID, type: long
- Mapped property: id -> RESID, type: long

It is ok. It is the same like in my hbm mapping file.

I have diferent between my HQL and SQL genetared by hibernate:
... where rq.id = ?
... where (rmstrequir0_.TEMPID=? )
I can see it in logs:
Code:
- HQL: select rq from xxx.RMSTRequirementHistDTO as rq  where rq.id  = ?
- SQL: select rmstrequir0_.TEMPID as x0_0_ from RMST_REQUIREMENTHIST rmstrequir0_ where (rmstrequir0_.TEMPID=? )


TEMPID is id ( primary key ) of my class.
But I want to ask about objects with special id not tempid.

What is wrong?!


Hibernate version:
2.1.7
Mapping documents:
Code:
<class name="RMSTRequirementHistDTO" table="RMST_REQUIREMENTHIST" >
             
                <id column="TEMPID" length="10" name="tempId" type="long">
                   <generator class="vm"/>
                </id>
                         
                <property column="RESID" length="10" name="id" not-null="true" type="long"  />
               <property column="HISTORY" length="10"  name="history" not-null="true" type="long" />
              <property column="VERSION" length="10" name="version" not-null="true" type="long" />
              <property column="PARENT" length="10" name="parentId" not-null="true" type="long"  />
              <property column="LOCKEDDATE" length="11" name="lockedDate" not-null="false" type="java.lang.String"  /> -->
              <property column="DISCUSSION" length="10" name="discussionPostId" not-null="true" type="long"  />
                <property column="DESCRIPTION" length="1024" name="description" not-null="false" type="string" />
                <property column="BASELINE" length="10" name="baseline" not-null="false" type="long" />
                <property column="LOCKED" length="10" name="lockUser" not-null="false" type="long" />
                <property column="VERSIONUSER" length="10" name="versionUser" not-null="false" type="long" />

                <set name="parameterSet" inverse="false" cascade="none" lazy="false"  batch-size="100" >
                    <key column="PARENTREQID"/>
                    <one-to-many class="RMSTRequirementParameterHistDTO" />
                </set>
                <set name="permissionDetailSet" lazy="false"  batch-size="100" order-by="groupId">
                   <key foreign-key="RESID" column="RESID"/>
                   <one-to-many class="RMSTPermissionDTO" />
                </set>
         
                <property name="path" formula="(SELECT max(rqp.path) from rmst_requirement_path rqp WHERE rqp.leaf = resid AND rqp.flag = 1)" type="string" not-null="true" />
                <property name="numPath" formula="(SELECT max(rqp.numpath) from rmst_requirement_path rqp WHERE rqp.leaf = resid AND rqp.flag = 1)" type="string" not-null="true" />
                <property column="ISHISTORICAL"  name="isHistorical" not-null="false" type="boolean"  />     
                <property column="ISDEL"  name="isDel" not-null="false" type="boolean" />               
</class>

Code between sessionFactory.openSession() and session.close():
Code:
Session session = RMSTHibernateUtil.currentSession();
            Transaction tx= session.beginTransaction();
            StringBuffer query = new StringBuffer();
            query.append("select rq from RMSTRequirementHistDTO as rq ");
            query.append(" where rq.id ");
            query.append(((id.length==1) ? " = ?" : " IN ("+getQMarks(id.length)+")" ) );  // tu jest/są userId, dla którego grup szukamy
            logger.debug("CreateQuery:\n"+query);
            Query q = session.createQuery(query.toString());
            int index = 0;
            for(int i = 0; i < id.length; i++) {
                if(id[i] == null || "".equals(id[i])) {
                    RMSTHibernateUtil.closeSession();
                    logger.error("Could not getRequirement. Reason: id[i] is null or has empty or null ID.");
                    throw new RMSTIllegalArgumentException("Could not getRequirement. Reason: id[i] is null or has empty or null ID.");
                }
                q.setLong(index++,id[i].longValue());
                //logger.debug("wstawiam do pytania ? <- id["+i+"].getId = "+id[i].getId());
            }
            RMSTRequirementDTO requirement = null;
            List requirements = new ArrayList();
            RMSTUserDTO logedUser = (RMSTUserDTO) getSession().getVariable("RMSTUserDTO");
            if ( logedUser == null ) {
                String msg = "Problem with session. You are not loged in. logedUser is NULL.";
                logger.error(msg);
                throw new RMSTSecurityException(msg);
            }
            for (Iterator it = q.iterate(); it.hasNext(); ) {
                requirement = RMSTRequirementFactory.requirementHistToDTO((RMSTRequirementHistDTO) it.next(), logedUser);
                try {
                    RMSTSecurityFactory.checkPermissions(requirement);
                    requirements.add(requirement);
                    logger.debug("load:"+requirement.toString());
                } catch (RMSTSecurityPrivilagesException spex){
                    logger.debug("You don't have rights to requirement:"+RMSTToString.toString(requirement)+".You have only "+requirement.getPermission());
                }
            }
            RMSTHibernateUtil.closeSession();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle9
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Code:
- open session.
- opened session
- session opened.
- begin
- current autocommit status:true
- disabling autocommit
- CreateQuery:
select rq from RMSTRequirementHistDTO as rq  where rq.id  = ?
- iterate: select rq from RMSTRequirementHistDTO as rq  where rq.id  = ?
- parameters: [1720]
- named parameters: {}
- compiling query
- flushing session
- Flushing entities and processing referenced collections
- Processing unreferenced collections
- Scheduling collection removes/(re)creates/updates
- Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
- Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
- Dont need to execute flush
- HQL: select rq from xxx.RMSTRequirementHistDTO as rq  where rq.id  = ?
- SQL: select rmstrequir0_.TEMPID as x0_0_ from RMST_REQUIREMENTHIST rmstrequir0_ where (rmstrequir0_.TEMPID=? )
- about to open: 0 open PreparedStatements, 0 open ResultSets
- select rmstrequir0_.TEMPID as x0_0_ from RMST_REQUIREMENTHIST rmstrequir0_ where (rmstrequir0_.TEMPID=? )
- preparing statement
- binding '1720' to parameter: 1
- retrieving next results
- returning '1720' as column: x0_0_
- loading [xxx.RMSTRequirementHistDTO#1720]
- attempting to resolve [xxx.RMSTRequirementHistDTO#1720]
- object not resolved in any cache [xxx.RMSTRequirementHistDTO#1720]
- Materializing entity: [xxx.RMSTRequirementHistDTO#1720]
- about to open: 1 open PreparedStatements, 1 open ResultSets
- select rmstrequir0_.TEMPID as TEMPID0_, rmstrequir0_.RESID as RESID0_, rmstrequir0_.HISTORY as HISTORY0_, rmstrequir0_.VERSION as VERSION0_, rmstrequir0_.PARENT as PARENT0_, rmstrequir0_.DISCUSSION as DISCUSSION0_, rmstrequir0_.DESCRIPTION as DESCRIPT7_0_, rmstrequir0_.BASELINE as BASELINE0_, rmstrequir0_.LOCKED as LOCKED0_, rmstrequir0_.VERSIONUSER as VERSION10_0_, rmstrequir0_.ISHISTORICAL as ISHISTO11_0_, rmstrequir0_.ISDEL as ISDEL0_, (SELECT max(rqp.path) from rmst_requirement_path rqp WHERE rqp.leaf = rmstrequir0_.resid AND rqp.flag = 1) as f4_0_, (SELECT max(rqp.numpath) from rmst_requirement_path rqp WHERE rqp.leaf = rmstrequir0_.resid AND rqp.flag = 1) as f5_0_ from RMST_REQUIREMENTHIST rmstrequir0_ where rmstrequir0_.TEMPID=?
- preparing statement
- binding '1720' to parameter: 1
- processing result set
- result row: 1720
- Initializing object from ResultSet: 1720
- Hydrating entity: xxx.RMSTRequirementHistDTO#1720
- returning '2904' as column: RESID0_
- returning '6' as column: HISTORY0_
- returning '2' as column: VERSION0_
- returning '0' as column: PARENT0_
- returning '2905' as column: DISCUSSION0_
- returning 'PARAMETER_ADD: Deadline by customer' as column: DESCRIPT7_0_
- returning '8' as column: BASELINE0_
- returning '-1' as column: LOCKED0_
- returning '2198' as column: VERSION10_0_
- returning '/2/2490/2491/2788/2805/2903/2904' as column: f4_0_
- returning 'TCC' as column: f5_0_
- returning 'false' as column: ISHISTO11_0_
- returning 'false' as column: ISDEL0_
- done processing result set (1 rows)
- done closing: 1 open PreparedStatements, 1 open ResultSets
- closing statement


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 4:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
id is a reserved keyword in hql - it will always point to the id property.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Annoyance with HQL special id property
PostPosted: Mon Dec 05, 2005 1:49 pm 
Beginner
Beginner

Joined: Wed Dec 31, 2003 1:40 pm
Posts: 25
max wrote:
id is a reserved keyword in hql - it will always point to the id property.


But that is a bad idea. As I have said elsewhere (and will keep saying until I have some satisfactory answer): The special property 'id' in HQL is a great annoyance to me, a showstopper, becasue I can't just decide not to use the name "id" for a normal property. My API/Object Model is from a standard and needs to use the standard names.

I have filed a bug report at http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1127 with a simple patch that "fixes" the problem for me. But that was simply closed without further comment, marked as "duplicate" without a link to the bug or discussion that it supposedly duplicates. This needs to be fixed in the HQL specification, my code (open source as well) can't keep depending on my private HQL patch, it makes everyone go crazy.

I think this is bad design of HQL and should somehow be repealed. It's an entirely unnecessary "feature" because all id properties have a normal name defined in the mapping file. If they wanted a "feature" they shouldn't just use up a normal looking property name, instead they should have used some special tag, such as x.@id or x.hibernateId or something less likely to conflict.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.