-->
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: Should I use formulas?
PostPosted: Wed May 09, 2007 11:11 am 
Newbie

Joined: Mon Apr 23, 2007 3:55 pm
Posts: 10
Hibernate version: 1.2.0 GA
Database: Microsoft SQL Server 2000

I have this query/stored procedure
Code:
SELECT   Files.pkFileGuid,
         COUNT(Views.ViewDate) AS Total,
         (SELECT COUNT(*) FROM Views WHERE ViewDate < CONVERT(varchar, GETDATE(), 112)) AS Today
FROM     Files
INNER JOIN Views ON Files.pkFileGuid = Views.fkFileGuid
GROUP BY Files.pkFileGuid
HAVING   pkFileGuid = @Guid


I want to map this accordingly, like:
Code:
// Hibernate mapping for the File class...
<component name="Views" class="View" insert="false" update="false">
    <property name="Total" type="Int32" />
    <property name="Today" type="Int32" />
</component>


I've tried to use formulas but I can't seem to send in the ID contained in the class. Anyone have a good suggestion on how to solve this?

My apologies if my English is bad... Do comment. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 1:29 pm 
Newbie

Joined: Mon Apr 02, 2007 12:31 pm
Posts: 19
Maybe you could create a view on SQL Server that has all the columns from your query, like this:

Code:
SELECT   Views.fkFileGuid,
         COUNT(Views.ViewDate) AS Total,
         (SELECT COUNT(*) FROM Views WHERE ViewDate < CONVERT(varchar, GETDATE(), 112)) AS Today
FROM     Views
GROUP BY Views.fkFileGuid


Then make a one-to-one relation between File and the View in your mapping.


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.