How do I create a DAO class for Seam / JPA (hibernate)?

I am learning Seam and JPA / Hibernate, and while I could find some examples of how to create a DAO class with Hibernate, I am a little confused on how to do the same with Seam (or even if that's all it takes).

I know seam manages transactions using its conversations, so I am not worried about doing the operations manually / manually.

What I am still not getting is extending the EntityHome and EntityList objects outside of the generated seam-gen to create DAOs that would provide me with the fine-grained operations / joins that I need in my application.

Did I miss something?

+2


source to share


2 answers


I know that seam manages transactions using its own conversations so I don't (?) Have to worry about manual commit / rollback.

Yes, you don't need to worry about this, if there is an exception, the seam will automatically rollback. Ditto for commit when there is no exception. I think you can manipulate this manually too with seam annotations.

The DAO pattern is generated when you need to decouple the persistencie layer from the business layer. EntityHome and EntityList are exactly the persistence layer. You don't have to create Tao.



The best way to get started with seam is the example that comes with the seam package. see examples like dvdstore and booking. they are very useful

Hello,

+2


source


Another useful thing is EntityQuery or HibernateEntityQuery. You define your requests in XML and then you can refer to them as Seam components throughout your application. While I use this much-loved NamedQuery in JPA, I don't think it's standard practice.

<framework:entity-query name="User_findByEmailAddress" ejbql="SELECT u FROM User u">
<framework:restriction>
   <value>u.emailAddress = #{emailAddress}</value>
</framework:restriction>
</framework:entity-query>

      

Then, in your Java code, you can:



@In
private EntityQuery<User> User_findByEmailAddress;

...
Contexts.getEventContext().set("emailAddress", emailAddress);
User user = User_findByEmailAddress.getSingleResult();

      

If you want to use this in your xhtml page, you can also use it there with built-in support for pagination.

Walter

+1


source







All Articles