<p>When using Business Objects' CrystalReportViewer control, how can you detect and manually print the report the user has currently drilled into? You can print this automatically using the Print() method of the CrystalReportViewer, but I want to be able to do a manual printing of this report.</p>

<p>It is possible to print the main ReportSource of the CrystalReportViewer, but I need to know what report the user has drilled into and then do a manual printing of that particular drill down. Any ideas?</p>

You are after a native SQL query.
If you are using JPA the syntax is:
```
```
Query q = em.createNativeQuery("select foo.* from Foo foo " +
                               "where f.x = max(f.x) over " +
                               "(partition by f.y)", Foo.class);
```
```
If you need to return multiple types, take a look at the
SQLResultSetMapping
annotation.
If you're using the the Hibernate API directly:
```
```
Query q = session.createSQLQuery("select {foo.*} from Foo foo " +
                                 "where f.x = max(f.x) over "+
                                 "(partition by f.y)");
q.addEntity("foo", Foo.class);
```
```
See
10.4.4. Queries in native SQL
in the Hibernate documentation for more details.
In both APIs you can pass in parameters as normal using setParameter.