On Fri, May 23, 2008 at 8:27 PM, Alexander Coles <[EMAIL PROTECTED]> wrote:
> Chris,
>
> Your tutorial was really excellent. I have two issues, that I was wondering
> if someone on the list would be able to help with:
>
> 1. I notice you're using DetachedCriteria in your Hibernate implementation.
> Does anyone know what the best method to would approach this would be with
> JPA? Is there any equivalent using the JPA API?
>
> 2. One other issue (that I'd be happy to help work on, since it benefits
> me), is with modular Appfuse-based applications - which I tend to use pretty
> much exclusively.
>
> I'm not too strict of a purist when it comes to keeping the DAO/Service/Web
> layers decoupled from each other (or at least as long as the layers only
> know about each other in one direction), but this solution does start to
> couple things together. This is particularly noticeable if you use the
> modular archetype. as you would end up having to have the DisplayTag as a
> dependency in your *-core module.
>
> Parts of this problem would have a simple resolution, such as recreating a
> SortOrderEnum or passing a string for sort order to your DAO. However,
> pushing the classes in the helper package you created class down to the
> *-core module certainly would make DisplayTag a dependency.
>
> Thanks,
>
> Alex
>
I think I hit send a little too fast on the previous email...
To partially answer my own question, or at least part 1 -- having
recently switched over to JPA from Hibernate, I should have realized
there is no Criteria API in JPA.
So the solutions is one of the following: a) handle criteria myself,
or b) since I am still using Hibernate as the implementation (even if
I am using the JPA API), to use Hibernate's native API where I need to
handle criteria.
So a PagingLookupDaoJpa.java implementation might look something like this:
public List<NewsItem> getAllRecordsPage(int first, int max,
SortOrder direction, String criterion) {
Query q = entityManager.createQuery("select n from NewsItem n");
// handle the criteria
q.setFirstResult(first);
q.setMaxResults(max);
List<NewsItem> items = q.getResultList();
return items;
}
//NOTE THE JPA SPEC RETURNS LONGs for COUNT aggregate queries
public Long getAllRecordsCount() {
Query q = entityManager.createQuery("select count(n) from NewsItem n");
return (Long) q.getSingleResult();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]