开发者

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

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 transactio开发者_运维技巧ns 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 ?


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,


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜