| Author |
Data Transfer Object + JPA in EJB 3.1 world
|
Piotr Nowicki
Ranch Hand
Joined: Jul 13, 2010
Posts: 610
|
|
Howdy Ranchers!
Recently I've bumped into a topic about the purpose of DTO (http://www.coderanch.com/t/472362/patterns/opinion-Data-Transfer-Objects-pattern) and few questions raised in my head.
So, let's assume that right now (in EJB 3.1 world) we don't need a DTO but we can use JPA entities. In the pointed topic there is a following statement:
If you're not using remote interfaces, no need to use Transfer Object, end of story.
1. Isn't the DTO supposed to promote loosely coupled design? If I understand the above topic correctly, it implies that I can create a JPA Entity (i.e. in the controller code of the client UI) and pass it to the EJB business method.
Ok, but I think that in this case my view layer (controller and view) will be aware of changes made directly to the database (change in JPA entity), am I right? This isn't very nice...
2. Another case. Assume I have a JBoss AS with my business logic and -- right beside -- a Tomcat server with client UI. Both servers runs on the same machine.
Does it mean that they run on the same JVM or on separate? Is it treated as a remote or local invocation?
If it's treated as a local access and we use JPA entities directly from the client than doesn't the Tomcat client UI application need to have a dependency on the JPA code to be able to run entities it should present / create? Once again it seems strange that client UI-only layer needs a dependency on the persistency layer...
So talking about the design - how would you cope with the above problems?
Thanks in advance for your help!
Cheers!
|
OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
|
 |
K Hein
Greenhorn
Joined: Jul 02, 2008
Posts: 10
|
|
Pedro Kowalski wrote:Howdy Ranchers!
1. Isn't the DTO supposed to promote loosely coupled design? If I understand the above topic correctly, it implies that I can create a JPA Entity (i.e. in the controller code of the client UI) and pass it to the EJB business method.
Ok, but I think that in this case my view layer (controller and view) will be aware of changes made directly to the database (change in JPA entity), am I right? This isn't very nice...
I am not sure if I understand your point correctly. But you can detach the entity object from Entity Manager and use it as a POJO in the view layer.
Regards,
K.H
|
 |
Romeo Son
Ranch Hand
Joined: Mar 12, 2007
Posts: 92
|
|
|
Exactly. In EJB2 entity beans were not POJOs, so the anti-pattern DTO was a must. Not needed anymore with EJB3.
|
SCJP 1.4, SCJD, OCE EJBD 6
|
 |
 |
|
|
subject: Data Transfer Object + JPA in EJB 3.1 world
|
|
|