Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Data Transfer Object + JPA in EJB 3.1 world

 
Ranch Hand
Posts: 623
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 (https://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!
 
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
 
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.
 
Create symphonies in seed and soil. For this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic