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]