0

I have a spring web app that uses Hibernate and Velocity. It's an MVC app. I pass my ModelMaps down to the service level. And I also use my Hibernate persistence objects in the service level. I have these "domain" objects, which are basically the same thing as the persistence objects, except I include them in the ModelMap and make use of then in velocity. My questions is: can I do away with the "domain" object and use the persistence objects in the ModelMap, or that cause some kind of problems (maybe performance problems)?

Thanks for the help, Joe

Joe
  • 1,091
  • 1
  • 13
  • 18

2 Answers2

0

As long as you are writing the templates, and not some designer (and assuming that won't change later), it is probably fine.

Your biggest gotcha will be catching errors. If something doesn't load, you may already have sent a portion of the rendered template in the response. So, you will probably want to buffer the output, the VelocityLayoutServlet essentially does this by default (not for the layout template, but for the main content). The VelocityViewServlet will require you to flip a setting. I don't recall which one, offhand. Look at the VelocityView class for more on that.

Nathan Bubna
  • 6,540
  • 2
  • 33
  • 36
0

The other gotcha is that if you use Lazy Loading, you'll most likely run into a scenario where Hibernate will want to load data that you're only using in the view, yet you've already closed the Session. The OpenSessionInView pattern gets you around that but that's not always seen as a clean solution (see also here: Why is Hibernate Open Session in View considered a bad practice?)

Community
  • 1
  • 1
beny23
  • 32,077
  • 3
  • 78
  • 83