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: asked for max(id), got full object instead
PostPosted: Mon Oct 04, 2004 9:48 am 
Newbie

Joined: Tue Jul 27, 2004 1:17 pm
Posts: 12
I executed:
Iterator resultsIt = sess.iterate("select max(id) from AlarmDTO as alarm");
and got back a full DTO rather than an Integer max value. I don't understand why.

Thank you.


Hibernate version:2.1

Mapping documents:<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.broadbus.common.dto.alarms.AlarmDTO"
table="alarm"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="increment">
</generator>
</id>

<property
name="source"
type="string"
update="true"
insert="true"
access="property"
column="source"
length="64"
not-null="true"
/>

<property
name="description"
type="string"
update="true"
insert="true"
access="property"
column="description"
length="1024"
/>

<property
name="severity"
type="int"
update="true"
insert="true"
access="property"
column="severity"
length="1"
not-null="true"
/>

<property
name="creationTime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="creationTime"
not-null="true"
/>

<property
name="acknowledged"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="acknowledged"
length="1"
not-null="true"
/>

<property
name="status"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="status"
length="1"
not-null="true"
/>

<property
name="acknowledgedBy"
type="string"
update="true"
insert="true"
access="property"
column="acknowledgedBy"
length="64"
/>

<property
name="acknowledgeTime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="acknowledgeTime"
/>

<property
name="clearedBy"
type="string"
update="true"
insert="true"
access="property"
column="clearedBy"
length="64"
/>

<property
name="clearedTime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="clearedTime"
/>

<property
name="notes"
type="string"
update="true"
insert="true"
access="property"
column="notes"
length="256"
/>

<property
name="sourceId"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="sourceId"
/>

<property
name="sourceClassId"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="sourceClassId"
/>

<property
name="parent1Id"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="parent1Id"
/>

<property
name="parent2Id"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="parent2Id"
/>

<property
name="subcomponent"
type="string"
update="true"
insert="true"
access="property"
column="subcomponent"
length="64"
/>

<property
name="serverId"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="serverId"
/>

<property
name="eventId"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="eventId"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-AlarmDTO.xml
containing the additional properties and place it in your merge dir.
-->

</class>

<query name="alarmSummaryNotAcked"><![CDATA[
select alarm.severity, count(*) from AlarmDTO as alarm where acknowledged = 0 group by alarm.severity
]]></query>
<query name="alarmSummaryNotCleared"><![CDATA[
select alarm.severity, count(*) from AlarmDTO as alarm where clearedtime is null group by alarm.severity
]]></query>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Why does this code work? I expect to get back an Integer representing the max id, and in fact I see SQL to do that. But, I also see SQL to actually get my dto and in fact the object in the Iterator is my dto.

Iterator resultsIt = sess.iterate("select max(id) from AlarmDTO as alarm");
Object row = (Object) resultsIt.next();
dto = (AlarmDTO)row;


Full stack trace of any exception that occurs:NA

Name and version of the database you are using:Oracle 10g

The generated SQL (show_sql=true):
2004-10-04 09:21:03,404 DEBUG BatcherImpl.getPreparedStatement() : select alarmdto0_.id as x0_0_ from alarm alarmdto0_
2004-10-04 09:21:03,423 DEBUG BatcherImpl.getPreparedStatement() : select alarmdto0_.id as id0_, alarmdto0_.source as source0_, alarmdto0_.description as descript3_0_, alarmdto0_.severity as severity0_, alarmdto0_.creationTime as creation5_0_, alarmdto0_.acknowledged as acknowle6_0_, alarmdto0_.status as status0_, alarmdto0_.acknowledgedBy as acknowle8_0_, alarmdto0_.acknowledgeTime as acknowle9_0_, alarmdto0_.clearedBy as clearedBy0_, alarmdto0_.clearedTime as cleared11_0_, alarmdto0_.notes as notes0_, alarmdto0_.sourceId as sourceId0_, alarmdto0_.sourceClassId as sourceC14_0_, alarmdto0_.parent1Id as parent1Id0_, alarmdto0_.parent2Id as parent2Id0_, alarmdto0_.subcomponent as subcomp17_0_, alarmdto0_.serverId as serverId0_, alarmdto0_.eventId as eventId0_ from alarm alarmdto0_ where alarmdto0_.id=?

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 10:52 am 
Beginner
Beginner

Joined: Tue Dec 09, 2003 3:27 pm
Posts: 21
I've run into this recently too, try max(alarm.id) instead.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.