hibernatehibernate-ogm

hibernate ogm dependency issue with embedded infinispan


I am trying to test OGM with Infinispan embedded mode, with a simple entity, repository & service class.

@Entity
@Table(name="test_person")
public class PersonEntity implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "person_id", nullable=false, updatable=false)
    private Long id;
    
    @Column(name = "person_code", nullable=false, updatable=false)
    private String person_code;
    
    @Column(name = "person_name", nullable=true, updatable=true)
    private String person_name;
    ....
}

Repository --

@Repository("personRepository")
public interface PersonRepository extends JpaRepository<PersonEntity, Long> {
    
    
    
}

Service --

@Service("personService")
public class PersonService {
    
    @Autowired
    @Qualifier("personRepository")
    private PersonRepository personRepo;
    
    public PersonEntity addPerson(PersonEntity person) {
        
        PersonEntity p = personRepo.save(person);
        
        return(p);
    }
    
}

Junit Test --

@RunWith(SpringJUnit4ClassRunner.class)
@DataJpaTest
@ContextConfiguration(locations="/application-test-context.xml")
@SpringBootTest
public class PersonServiceTest {
    
    @Autowired
    @Qualifier("personService")
    private PersonService svc;
    
    @Test
    public void test_add1() {
        PersonEntity p = makePerson("123");
        svc.addPerson(p);
    }
    
    private PersonEntity makePerson(String uid) {
        PersonEntity p = new PersonEntity();
        p.setPerson_code("ABC_XYZ" + uid);
        p.setPerson_name("Abc Xyz" + uid);
        return(p);
    }
}

While running the test, I am getting the following exception --

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hibernate.ogm.jpa.HibernateOgmPersistence]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/jpa/HibernatePersistenceProvider 
.....  
Caused by: java.lang.NoClassDefFoundError: org/hibernate/jpa/HibernatePersistenceProvider   
    at org.hibernate.ogm.jpa.HibernateOgmPersistence.<init>(HibernateOgmPersistence.java:37) ~[hibernate-ogm-core-5.4.0.Final.jar:5.4.0.Final]  
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_231]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_231]     
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_231]     
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_231]  
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]     ... 52 common frames omitted  
Caused by: java.lang.ClassNotFoundException: org.hibernate.jpa.HibernatePersistenceProvider     
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_231]   
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_231]    
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_231]    
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_231]    
... 58 common frames omitted

My pom includes the following:

<dependency>
   <groupId>org.hibernate.ogm</groupId>
   <artifactId>hibernate-ogm-infinispan-embedded</artifactId>
   <version>5.4.0.Final</version>
</dependency>

<dependency>
   <groupId>org.jboss.narayana.jta</groupId>
   <artifactId>narayana-jta</artifactId>
   <version>5.9.2.Final</version>
</dependency>

It seems, OGM 5.4.0.Final ( even tried with 5.4.1.Final ) is pulling in hibernate core 5.0.12.Final , which is quite old and doesn't package org.hibernate.jpa.HibernatePersistenceProvider. For that we need to also include hibernate-entitymanager. However, even after including entitymanager, I get the following issue:

Caused by: java.lang.NoClassDefFoundError: org/hibernate/resource/transaction/spi/TransactionCoordinatorBuilder
    at org.hibernate.ogm.boot.impl.OgmServiceRegistryInitializer.contribute(OgmServiceRegistryInitializer.java:73) ~[hibernate-ogm-core-5.4.0.Final.jar:5.4.0.Final]
    at org.hibernate.boot.registry.StandardServiceRegistryBuilder.applyServiceContributors(StandardServiceRegistryBuilder.java:305) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.boot.registry.StandardServiceRegistryBuilder.build(StandardServiceRegistryBuilder.java:273) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:176) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:160) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:135) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.ogm.jpa.HibernateOgmPersistence.createContainerEntityManagerFactory(HibernateOgmPersistence.java:89) ~[hibernate-ogm-core-5.4.0.Final.jar:5.4.0.Final]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    ... 46 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_231]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_231]
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_231]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_231]
        ... 60 common frames omitted

In hibernate core 5.0.12.Final , TransactionCoordinatorBuilder is in "org.hibernate.resource.transaction" package and not in "org.hibernate.resource.transaction.spi" package.

Can someone help me with the correct dependencies to include in pom ? I even tried to bump up the hibernate core to recent builds but I ran into another set of dependency issues there!


Solution

  • Hibernate OGM 5.4.1.Final requires Hibernate ORM 5.3.6.Final: http://hibernate.org/ogm/releases/5.4/

    Some other dependency in your project is pulling Hibernate ORM 5.0.12.Final