开发者

Weblogic WebService with EJB

开发者 https://www.devze.com 2023-03-21 20:39 出处:网络
I am going to develop a webservice which will expose two operations. These operation will query/update data from database.

I am going to develop a webservice which will expose two operations. These operation will query/update data from database.

Please suggest do i use EJB for database operation and what advantage i will get?

or

in my webservice i 开发者_开发知识库use JPA directly like following, and create my entities and persist them

@PersistenceUnit private EntityManagerFactory emf;
@Resource
private UserTransaction utx;

Please answer with advantages/disadvantages.

Regards, imran


Both approaches are valid and supported by Java EE, so this is only a design recommendation based on my experience:

Do never directly expose EJB operations as Web Services, it only increases runtime complexity. If you publish an EJB as a Web Service the container must still wrap it by using an internal Web Services servlet which (implicitly) tightly couples your WAR containing the internal Web Service mapping to your ejb-jar (depends on app server product). Furthermore, it's hard to debug in day-to-day operations.

My recommendation using only standard Java EE features without any additional libraries:

  • POJO defines the Web Service interface, aka its operations (@WebService annotation). It delegates to a functional implementation. Let's call this POJO WS-POJO.

Two options to implement the functionality:

  1. WS-POJO calls stateless Session Beans which provide the required functionality. Pro: All EJB features available (dependency injection, declarative transaction mgmt, etc.). Con: "Heavyweight"
  2. WS-POJO calls custom POJOs following e.g. the Command Pattern. Pro: "Lightweight". Con: Dependency injection not possible; Entity Manager etc. to be passed.

Today, I'd go with option #1... my 2 cent

0

精彩评论

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