Reputation: 1738
I'm building bigger project in java on Spring and lot of people have adviced me, to use hibernate to ease access to the database. The problem is,that I have to use database from previous version of this project, which used to be written in PHP, so they didn't use hibernate for sure. I've read something about hibernate, but I'm still not sure in one thing - does it have to change the structure of the database or can I use standard MySQL database with stored values in int, varchar and other types and use hibernate just to get rid of lot of SQL in my java code?
Upvotes: 1
Views: 365
Reputation: 31
Hibernate is best and easy for connection purpose.. You can use it without affecting your current structure of database. You can also use annotation in hibernate, it's very simple and easy. Take one thing in mind, You have to add proper mapping in hibernate configuration file! It is a better idea to backup your whole database before you will go with hibernate.
Upvotes: 1
Reputation: 15240
Hibernate is a highly mature project and definitely works well with existing schemas. You can even generate your class entities from an existing schema with Hibernate tools.
Still there is an important point where you need be careful: Hibernate supports composite primary and foreign keys but you'll have a much easier life with technical generated ids.
If I had a schema with composite primary keys forming natural ids I would consider replacing them with technical auto generated ids before using Hibernate.
Upvotes: 2
Reputation: 5003
While Hibernate can be used to create / delete tables, typically you wouldn't do that in a production environment. In these scenarios, you're defining the Object-Relational Mapping between the POJOS and the underlying database schema. So, really, Hibernate doesn't need to add anything to the database schema.
If you're working with a Schema which was defined before applying hibernate, you probably need to ensure the field converters are appropriate (ie, Hibernate might have different ideas about what column type in SQL constitutes a date or a number), but that means that you would have to provide the explicit mapping/converter instead of using the default.
But, you should be able to use Hibernate without making any major changes to the existing database schema.
Upvotes: 1