• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Data Transfer Object + JPA in EJB 3.1 world

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic