JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy

How To Create Session Factory in Hibernate 4

December 25, 2013 by Krishna Srinivasan Leave a Comment

There are many APIs deprecated in the hibernate core framework. One of the frustrating point at this time is, hibernate official documentation is not providing the clear instructions on how to use the new API and it stats that the documentation is in complete. Also each incremental version gets changes on some of the important API. One such thing is the new API for creating the session factory in Hibernate 4.3.0 on wards. In our earlier versions we have created the session factory as below:

[code lang=”java”]
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
[/code]

The method buildSessionFactory is deprecated from the hibernate 4 release and it is replaced with the new API. If you are using the hibernate 4.3.0 and above, your code has to be:

[code lang=”java”]
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().
applySettings(configuration.getProperties());
SessionFactory factory = configuration.buildSessionFactory(builder.build());
[/code]

Class ServiceRegistryBuilder is  replaced by StandardServiceRegistryBuilder from 4.3.0. It looks like there will be lot of changes in the 5.0 release. Still there is not much clarity on the deprecated APIs and the suitable alternatives to use. Every incremental release comes up with more deprecated API, they are in way of fine tuning the core framework for the release 5.0.

Filed Under: Hibernate Tagged With: Deprecated, Hibernate 4 Tutorials

Deprecated @Entity Annotation in Hibernate 4

December 25, 2013 by Krishna Srinivasan Leave a Comment

In the earlier versions of Hibernate, we use @Entity for marking a class as persistence entity in the database. It has list of attributes to be used as the parameters. @Entity has been deprecated from the hibernate 4 and will be removed from the hibernate 5.0 release. There is a confusion in the consistency of  information provided on their websites about the removal of these annotations. However, If you are using this annotation in the earlier versions of hibernate, you have to change before planning to migrate your project to higher versions. @Entity has the following list of attributes.

  1. dynamicInsert
  2. dynamicUpdate
  3. mutable
  4. optimisticLock
  5. persister
  6. polymorphism
  7. selectBeforeUpdate

When @Entity is removed, each and every attribute listed above will have its own annotation definition as listed below:

  1. DynamicInsert
  2. DynamicUpdate
  3. Immutable
  4. OptimisticLocking
  5. Persister
  6. Polymorphism
  7. SelectBeforeUpdate

However, the annotation Entity is deprecated in favor of the JPA annotation @javax.persistence.Entity. If you would like to use it, you have to use the JPA one instead of the hibernate annotation. It is obvious that there will be lot of changes with the hibernate API in the future versions, I would suggest to use the latest version if you are starting a new project.

Filed Under: Java Tagged With: Deprecated, Hibernate 4 Tutorials

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved