tags:

views:

395

answers:

2

Hi,

I'm learning Seam and JPA/Hibernate and while I could find some examples on how to build a DAO class with Hibernate I'm a bit confused on how to do the same thing with Seam (or even if that is at all necessary).

I do know that seam manages the transactions using its conversations so I don't (?) have to worry about committing / rolling back the operations manually.

What I still don't get is how to extend EntityHome and EntityList objects beyond the ones generated by seam-gen to create DAOs that would provide me with the fine grained operations / joins I need in my application.

Am I missing something ?

+2  A: 

I do know that seam manages the transactions using its conversations so I don't (?) have to worry about committing / rolling back the operations manually.

Yes, you dont need to worry about it, if there is an exception, seam will automatically do a rollback. The same thing for commit when there is no exception. I think you can control this manually too with seam annotations.

The DAO pattern is created when you need to separate the persistencie tier from business tier. EntityHome and EntityList are exactly the persistence tier. You dont need to create a dao.

The best path for whom are starting with seam is study the example that come with seam package .. see examples like dvdstore and booking. they are quite helpfull

Regards,

Cateno Viglio
Thanks for the input! Do you mean that using EntityHome and EntityList I should be able to do any persistence operation I need in my application? Or do you extend the sean-gen classes in any way?
Cleber Goncalves
yes, use entityHome for update, delete and insert and EntityList for select. But that is just a suggestion for seam projects, you can inject entity manager in any seam component if you want.
Cateno Viglio
+1  A: 

The other useful thing to is EntityQuery or HibernateEntityQuery. You specify your queries in XML and then can reference them as Seam components throughout your application. Although I use this much liked NamedQuery in JPA, I don't think this is a 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 do:

@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