1

Most of the time I get this advice not to use hibernate model objects as my Value Objects or UI Objects. Will there be any issues if I use Hibernate model objects as VO objects or Form Objects in UI? If it is ok to use I can avoid copying values to and from the VO and model Objects.

Sherin Syriac
  • 447
  • 6
  • 13

1 Answers1

2

I think you're right, there are no issues with that. It is a matter of context.

Hibernate model objects are simple POJOs with some metadata (annotations) attached to it. At the persistence layer this metadata means something, but in the view layer it means nothing.

This way in the view layer it acts as a VO, but in the persistence layer it acts as a model object, so it indeed eliminates the need for separate VOs.

This is the beauty of metadata.

If you're concerned with the security of an object travelling from UI to database, this would be another subject.

There are various ways to ensure security, but basically it would be achieved by using proper authentication and authorization mechanisms, queries with parameters and/or Criteria API.

For more info on that, please take a look at this and this.

I hope it helps.

Community
  • 1
  • 1
rbento
  • 9,919
  • 3
  • 61
  • 61