wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Using subselect tag or creating a view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Using subselect tag or creating a view" Watch "Using subselect tag or creating a view" New topic

Using subselect tag or creating a view

Fletcher Munson
Ranch Hand

Joined: May 16, 2007
Posts: 31
I have a query (below) that needs to pull the most recent activity by transactionId (FK in a transactions table).

The query works exactly how I want it, but when I try to use it in Hibernate I have trouble converting it over. I currently use the SQLQuery interface to run this, but I would like to use a criteria query though I can't seem to find any way to do it. The closest I've come was the <subselect> tag in the mapping file to attempt to create a view. I'm not seeing much documentation on this tag, and it's not totally clear how to use it or what I'm doing wrong. In fact, I'm not ever sure how to access/utilize the view via java after it's mapped properly (DetachedCritiera maybe?).

Can someone help understand how to use this subselect - and will it even do what I want it to?

Thank you in advance.

Javid Jamae
Ranch Hand

Joined: May 14, 2008
Posts: 198
This may not be the answer you're looking for, but I always use a view in a situation like this.

Author: JBoss in Action, javidjamae.com, @javidjamae on Twitter
Fletcher Munson
Ranch Hand

Joined: May 16, 2007
Posts: 31
That's what I'm trying to do. Only I don't have access to the DB to create one. Hibernate was supposed to have a way to create one using the subselect tag in the mapping file. Only problem is there isn't much documentation, and I can't seem to figure it out.
It is sorta covered in the JavaRanch Style Guide.
subject: Using subselect tag or creating a view
Similar Threads
mapping question (hashmap and subclasses)
Hibernate : many to many mapping and inner join query results.
joins in Hibernate Annotation
Validating Hibernate mapping file with -set- and -join- elements
Hibernate one-to-many weirdness...