Ruby9191
Ruby9191

Reputation: 113

Hibernate 5.0.1 and Java 8; Provider org.hibernate.type.Java8DateTimeTypeContributor not found

I am learning hibernate. I downloaded the hibernate-release 5.0.1 Final and copied all the jars in the required and java8 folders into my project. I am using java8 jdk in my system.

I am trying to execute a very basic program:

  public class HibernateTest {      
    public static void main(String[] args){

        UserDetails user = new UserDetails();
        user.setUserId(1);
        user.setUserName("First User");


        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();

        session.beginTransaction();
        session.save(user);
        session.getTransaction().commit();
        session.close();

    }
}

The hibernate configuration file is also very basic:

<hibernate-configuration>                
      <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/Training</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">password</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>

        <mapping class="org.vicky.dto.UserDetails"/>
      </session-factory>
</hibernate-configuration>

The result is:

Exception in thread "main" java.util.ServiceConfigurationError: org.hibernate.boot.model.TypeContributor: Provider org.hibernate.type.Java8DateTimeTypeContributor not found
    at java.util.ServiceLoader.fail(ServiceLoader.java:231)
    at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:365)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:324)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:356)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    at org.vicky.hibernate.HibernateTest.main(HibernateTest.java:19)

Please help me out. I searched in that package for this missing class file. But it is not there. Thank you for your answers.

Upvotes: 4

Views: 3680

Answers (3)

Thushara
Thushara

Reputation: 559

Remove java8 jar file from build path libraries.

Upvotes: 1

Ruby9191
Ruby9191

Reputation: 113

I got it fixed just now. I have installed multiple eclipse IDEs in my system. Found out that the one I am using with this project is using JDK 1.7. I have changed it to JDK 1.8 and everything got smooth now (Windows->preferences->java->installed JREs->Add and point to JDK 1.8 directory).

But can someone explain how eclipse works here? I have installed Java 8 RE in my system. May be that's why this particular eclipse is expecting Java 8 related classes but without detecting them even though they are added to the project, because it's "installed JREs" setting is pointing to JDK 1.7 . No clue what exactly is happening here with eclipse.

Thank you for your answers subodh and danizmax. Nice evening!

Upvotes: 0

danizmax
danizmax

Reputation: 2456

You are missing the hibernate-java8 jar in your class path. You can find it here.

Upvotes: 0

Related Questions