0

I am trying to configure hibernate-ogm for Cassandra on spring boot, but there are no dataSource are transparent provided to entityManager and below error with run:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
    - Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'
    - Bean method 'dataSource' not loaded because @ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans


Action:

Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.

Blow a workflow for case:

start with disable auto configuration for related jpa on spring:

@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude = {
        DataSourceAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class
})
public class GsDataApplication {
    public static void main(String[] args) {
        SpringApplication.run(GsDataApplication.class, args);
    }
}

and project dependencies are:

dependencies {
    compile project(':shared')

    compile('joda-time:joda-time:2.9.4')
    //compile('org.hibernate:hibernate-core:5.2.2.Final')
    compile('org.hibernate.ogm:hibernate-ogm-cassandra:5.0.1.Final')
    compile('org.hibernate:hibernate-search-orm:5.5.4.Final')
    compile('javax.transaction:jta:1.1')
    compile('org.springframework.data:spring-data-jpa:1.10.4.RELEASE')
    compile('org.springframework.boot:spring-boot-starter-social-facebook')
    compile('org.springframework.boot:spring-boot-starter-social-twitter')
}

Persistence configuration:

@Configuration
@EnableJpaRepositories(basePackages = {
        "com.gs.gsData.identity"
})
@EnableTransactionManagement
class PersistenceContext {
    @Bean
    LocalContainerEntityManagerFactoryBean entityManagerFactory(Environment env) {
        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        entityManagerFactoryBean.setPackagesToScan("com.gs.gsData.domain");

        Properties jpaProperties = new Properties();
        jpaProperties.put("javax.persistence.transactionType", "resource_local");
        jpaProperties.put("hibernate.ogm.datastore.provider", "cassandra_experimental");
        jpaProperties.put("hibernate.ogm.datastore.host", "127.0.0.1");
        jpaProperties.put("hibernate.ogm.datastore.port", "9042");
        jpaProperties.put("hibernate.ogm.datastore.database", "db-name");
        jpaProperties.put("hibernate.ogm.datastore.username", "cassandra");
        jpaProperties.put("hibernate.ogm.datastore.password", "password");
        jpaProperties.put("hibernate.ogm.datastore.create_database", "true");

        entityManagerFactoryBean.setPersistenceProviderClass(HibernateOgmPersistence.class);
        entityManagerFactoryBean.setJpaProperties(jpaProperties);

        return entityManagerFactoryBean;
    }

    @Bean
    JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactory);
        return transactionManager;
    }
}

Entity sample

@Entity
@Data
@AllArgsConstructor
@Table(name = "`User`")
public class User extends AbstractTiming{
    @Id @GeneratedValue
    private Long id;
    private String firstName, lastName, description;

    public User(){}
}

ADO @Repository

public interface UserDAO extends JpaRepository<User, Long> {
    User findByFirstName(String firstName);
    List<User> findByLastName(String lastName);
}

So in the end, is there way to create DataSource to reference Hibernate OGM?

or any other actions to avoid direct dataSource provider. Any help is greatly appreciated!

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348

1 Answers1

0

Hibernate OGM stores the connection in its own class: the org.hibernate.ogm.datastore.spi.DatastoreProvider.

So at start up it does not deal with DataSources, not sure if there is a way to create a DataSource from the cassandra connection and add it in the JNDI for springboot to find it.

The reason for this is that at the moment there is no standard among NoSQL datastores defining the connection details.

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30