Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Hibernate for Existing Database

We have an application thats already running for a long time. Now we are migrating it to Spring and possibly using Hibernate or any other ORM.

But we caught up with a question. Is it not recommended / bad idea to use Hibernate for the already existing Database and model the object around Schema?

Most people advocate NOT using Hibernate and instead of go with some other ORMs like iBatis. But in our company, all are proponents of Hibernate.

Any experiences?

like image 987
Kevin Rave Avatar asked Jan 09 '13 01:01

Kevin Rave


2 Answers

Hibernate works well if you can model your database under your objects.
Vice versa, you are likely to get the database model as your your domain model. You need to evaluate how distant those two models are, otherwise you are going to map the database => ORM objects => your domain model. I would avoid that.

If I want to skip the ORM part, I find myself quite happy with JDBI which I prefer over Spring JDBC Template

like image 57
Luigi R. Viggiano Avatar answered Oct 17 '22 06:10

Luigi R. Viggiano


I would say that it's irresponsible to choose Hibernate, iBatis, or anything else without knowing your requirements.

If you don't have a solid object model, I'd say that Hibernate is a terrible choice.

If you use stored procedures as the interface to your database, I'd say that Hibernate is a terrible choice.

If you don't like the dynamic SQL that Hibernate generates for you, I'd say that Hibernate is a terrible choice.

Get it? Knee-jerk reactions like the ones from those Hibernate proponents aren't a good idea.

It might be that iBatis or Spring JDBC template is a better choice than Hibernate. You ought to become more informed about that decision and make it for your application rather than blindly listen to a mob.

You don't have to be all or none about it, either. It's possible to implement part of your solution with one technology and the rest in another.

I'd recommend making your persistence layer interface-based so you can swap implementations without affecting clients.

like image 34
duffymo Avatar answered Oct 17 '22 07:10

duffymo