-->
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: AliasToBeanResultTransformer and Custom PropertyAccessors
PostPosted: Thu Jun 21, 2007 4:59 pm 
Newbie

Joined: Thu Jun 21, 2007 4:06 pm
Posts: 4
Hi Everyone--

I'm using hibernate on top of a legacy schema. In order to map the denormalized schema to the domain objects, in some cases I'm using custom property accessors. For instance, let's say my schema is as follows:

CREATE TABLE stats (
ID int primary key auto_increment,
`timestamp` datetime not null,
num1 bigint not null,
num2 bigint not null,
...
);

Now in the mapping, I have something like the following:

<class name="Stats">
<id>...</id>
<propery name="timestamp" type="timestamp"/>
<property name="num1" type="long" access="StatsPropAccessor"/>
<property name="num2" type="long" access="StatsPropAccessor"/>
...
</class>

Note that the Stats class *doesn't* have num1/num2 properties... There is a "num" List with two entries in it... StatsPropAccessor deals with this disconnect between the domain model and the legacy schema.

Now I have a query that aggregates records, similar to the following:

SELECT s.timestamp, sum(s.num1) as num1, sum(s.num2) as num2 FROM Stats s GROUP BY day(s.timestamp)

I'd like to get the results back as Stats instances. What is the best way of doing this? I assumed the following would work:

Query query = session.createQuery([Query as above]);
query.setResultTransformer(new AliasToBeanResultTransformer(Stats.class));

List<Stats> stats = (List<Stats>) query.list();

The problem is, AliasToBeanResultTransformer doesn't appear to take into consideration the custom PropertyAccessors that I've specified in the mapping. Instead, it's looking for fields/setters for num1 and num2, which obviously don't exist.

Note that simple queries such as "from Stats" do work, and query.list() returns Stats instances (i.e. the custom PropertyAccessor is functioning correctly).

Any insights into this issue, or alternative approaches, would be greatly appreciated. Thanks in advance!

Derek


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 11:45 am 
Newbie

Joined: Thu Jun 21, 2007 4:06 pm
Posts: 4
Has anyone encountered this issue? I have a not-so-ideal workaround, but just wondering if anyone has any hints.

Thanks in advance!


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.