Sorry, I didn't get back sooner - too much work!
No one told me I couldn't do this so I just did it. Create a dummy entity to
a table/view that doesn't exist - then write a query that uses column
aliases and any arbitrary sql to populate that entity. I guess JPA/Hibernate
is just creating an instance of a class and then calling a bunch of setters.

Other times, I've dumped all the hard work on Oracle programmers, getting
them to create a set of read only views and created entities on them, but I
guess thats less weird.

I've also done a similar thing in using formal constructors via hibernate's
report queries, but thats more work and I'm lazy.

cheers Oliver

On Fri, Apr 24, 2009 at 6:11 AM, Derek Chen-Becker <dchenbec...@gmail.com>wrote:

> Oliver, I've never done anything like that in JPA or Hibernate. Is that
> actually possible? Can you "create" a class instance within a query?
>
> Derek
>
>
> On Thu, Apr 23, 2009 at 2:47 PM, Charles F. Munat <c...@munat.com> wrote:
>
>>
>> I'm not really sure how I would go about this, but I'll think about it
>> when I have time to get back to that code.
>>
>> Thanks, Oliver.
>>
>> Chas.
>>
>> Oliver Lambert wrote:
>> > Is there anything to stop you defining an class/entity {answer: String,
>> > countAnswer: Int} and to directly create it from JPA (of course, it's
>> > read only).
>> >
>> > On Wed, Apr 22, 2009 at 9:36 AM, Charles F. Munat <c...@munat.com
>> > <mailto:c...@munat.com>> wrote:
>> >
>> >
>> >     I was thinking tuples, but that didn't work. I'll try your
>> suggestion.
>> >     BTW, for anyone reading along, I forgot the group by clause in the
>> query
>> >     below.
>> >
>> >     Chas.
>> >
>> >     Derek Chen-Becker wrote:
>> >      > I think that the type would be Array[Any] and you'll get one
>> >     String and
>> >      > Int for each row.
>> >      >
>> >      > Derek
>> >      >
>> >      > On Tue, Apr 21, 2009 at 3:37 PM, Charles F. Munat <
>> c...@munat.com
>> >     <mailto:c...@munat.com>
>> >      > <mailto:c...@munat.com <mailto:c...@munat.com>>> wrote:
>> >      >
>> >      >
>> >      >     Anyone have a quick example of how to run a scalar query in
>> >     JPA? I can't
>> >      >     find anything in the JPA demo.
>> >      >
>> >      >     I have this query:
>> >      >
>> >      >     select t.answer, count(distinct answer) from Vote t where
>> >     t.poll = :poll
>> >      >     order by t.answer
>> >      >
>> >      >     but how do I call it? I normally do:
>> >      >
>> >      >     Model.createNamedQuery[...]("findVoteCountAnswersByPoll",
>> >     "poll" ->
>> >      >     poll).findAll
>> >      >
>> >      >     But what is the type? And how do I get the results back out?
>> >      >
>> >      >     I know I did this once before somewhere, but I can't remember
>> >     where and
>> >      >     I can't find it.
>> >      >
>> >      >     Thanks!
>> >      >
>> >      >     Chas.
>> >      >
>> >      >
>> >      >
>> >      >
>> >      > >
>> >
>> >
>> >
>> >
>> > >
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to