Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Transfer Object + JPA in EJB 3.1 world

 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
K Hein
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
Android Eclipse IDE Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. In EJB2 entity beans were not POJOs, so the anti-pattern DTO was a must. Not needed anymore with EJB3.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic