Thanks for the prompt reply David.
The column being summed is defined as an Integer in MySQL, defined like this in the Hibernate config:
Code:
<version name="version" column="version" type="int"/>
The table is generated by Hibernate as:
Code:
CREATE TABLE `stingray`.`record` (
`id` BIGINT NOT NULL,
`class` VARCHAR(255) DEFAULT '' NOT NULL,
`version` INT DEFAULT '' NOT NULL,
`number` VARCHAR(255),
`status` VARCHAR(255),
`customerName` VARCHAR(255),
`tradingName` VARCHAR(255),
`business` TEXT,
`created` DATETIME,
`submit` DATETIME,
`required` DATE,
`due` DATE,
`start` DATE,
`end` DATE,
`effectiveFrom` DATE,
`effectiveTo` DATE,
`duration` INT,
`pol_ref` BIGINT,
`locked` null,
`flags` VARCHAR(255),
`owner_id` BIGINT,
`underwriter_id` BIGINT,
`policy_id` BIGINT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
I get the same error if I perform a sum() on the policy_ref field, which is a BIGINT in the database and defined like this in the hibernate config file:
Code:
<property name="policyId" column="pol_ref" not-null="false" type="long"/>
So the hibernate table definition appears sensible, and summing these columns seems like a resonable thing to do and works as expected if I execute the query through MySQL directly.
I've tried wrapping the SELECT wiith functions with another select with no functions.
Code:
SELECT owner,
total
FROM ( SELECT owner_id AS owner,
sum(version) AS total
FROM record
WHERE start >= :fromDate AND start <= :toDate
GROUP BY owner_id ) AS results
But that hasnt worked because Hibernate is still unable to determine the underlying type of the total aliased column.
Is there any workaround to help Hibernate determine the datatype of a derived column, or will I need to resort to directly using JDBC?
Cheers,
Nick