As a beginner to Java-database projects, how does one decide when one should use Hibernate in Java code instead of simple jdbc?
Hibernate– Hibernation is a good option when you know you won't use your laptop for an extended period of time and you are unsure of when you'll have the chance to charge it again. This is also a good option for desktop users concerned about power consumption as it doesn't use as much as sleep mode.
Hibernate is mostly considered for complex apps. JDBC is a much better option, if: If an app is using a simple database that does not require to migrate, or. If the application needs data to be stored in database tables that won't require object-mapping to 2 or 2+ table versions.
The short answer on the fundamental difference between JDBC and Hibernate is that Hibernate performs an object-relational mapping framework, while JDBC is simply a database connectivity API. The long answer requires a history lesson on database access with Java.
No, there is no way that Hibernate is deprecated. There is the JPA which is a persistence specification and Hibernate implements it. Also Hibernate has its own advanced features that JPA does not have and that's why Hibernate is the main source of new features that are added to the JPA standard.
Use hibernate if 1 to 4 are satisfied
Else
I would recommend ibatis. This is still an ORM framework but leaves flexibility in handling schema and domain objects separatley. It offers more flexibility in handling queries etc.
Spring jdbc also has good features offering flexibility. But i feel it still not near to an ORM. But spring does offer templates to handle orms like hibernate and ibatis.
Basically, if your application needs to store some data, you will probably want to use an ORM (e.g. you built some business app for your company and you need to track users and accounts). If your application is your data, then you will probably want to use JDBC (e.g. you built a data warehouse for your company).
as an additional note, it's perfectly reasonable for an application to use both ORM and JDBC. if, for instance, you were building a webapp which was allowing users to access your data warehouse, you might manage the user/account info using ORM but use JDBC to interact with the data warehouse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With