-1

I'm looking for the "correct" way to handle object creation and update in java web apps.

Say I have an architecture with 3 levels: Web UI, Domain and Database. I also have a class WebPage (title, description, url), with a hibernate mapping.

Clearly i need to use WebPage at least in the Database level, and most likely also at Domain level.

Object creation:

But at what level should i create the object?

I see two options:

1:

__WebUI__ -> createWebsite(title, description, url) __Domain__ 
  and domain creates the objects and passes it to the **Database** level.

Option 2:

__WebUI__[_creates the website_] -> saveWebsite(website) __Domain__ 

and domain passes it to the Database level.

The first one clearly seems the most reasonable.

Object update:

And what if i need to update the Website's informations?

Option 1:

__WebUI__ -> updateTitle(title) __Domain__
__WebUI__ -> updateDescription(desc) __Domain__
__WebUI__ -> updateUrl(url) __Domain__

Option 2:

WebUI sends an updated version of the object to the domain level.


Is there a specific pattern to follow?

Enoon
  • 421
  • 4
  • 17
  • 1
    I could answer...but it would take me an hour and I'll get maybe 10% of the quality you get from this answer http://stackoverflow.com/questions/3541077/design-patterns-web-based-applications?rq=1. – elbuild Feb 04 '14 at 22:25
  • You may also try to narrow your question. Can you use EJBs? Is CDI on the field? – elbuild Feb 04 '14 at 22:26

1 Answers1

0

It sounds to me like WebPage is not a good name for a domain object in general, may be you should rethink whether you want such a tight coupling between the user entered data on the web layer and the data that is stored in the database.

Most JEE or related frontend frameworks such as Spring MVC or Wicket or JSF accept/display user data presented in a scripting language such as JSP and bind them to a bean represented by a POJO(with annotations sometimes). These POJOs may not be good candidates to serve as Hibernate mapping objects because you do not want the entites attached to the Hibernate session while the user may be in a time consuming activity. So the frontend POJOs are normally detached from the Hibernate session and your database mapping layer must have the mappings to your table using Hibernate. See the chapter from JBoss doc. here

senseiwu
  • 5,001
  • 5
  • 26
  • 47