silvestrelosada
silvestrelosada

Reputation: 55

Mixing spring data jpa + spring data neo4j. userservice

I have a simple spring boot project with JPA repositories to store USER and AUTHORITIES information for spring-security and to store LOG events. The project is working fine. Now i would like to add extra functionality that involves neo4j. I added spring-data-neo4j to the project and I created my configuration for neo4j.

@EnableTransactionManagement
@EnableScheduling
@Configuration
@EnableNeo4jRepositories(basePackages = "com.mycompany.analytics.graph.repository")
public class Neo4jConfig extends Neo4jConfiguration {

    public static final String URL = System.getenv("NEO4J_URL") != null ? System.getenv("NEO4J_URL") : "http://neo4j:movies@localhost:7474";

    @Bean
    public org.neo4j.ogm.config.Configuration getConfiguration() {
        org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
        config
                .driverConfiguration()
                .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
                .setURI(URL);
        return config;
    }

    @Override
    public SessionFactory getSessionFactory() {
        return new SessionFactory(getConfiguration(), "com.mycompany.analytics.graph.repository");
    }
}

Previously I had my user repository to store user information on relational database

/**
 * Spring Data JPA repository for the User entity.
 */
public interface UserRepository extends JpaRepository<User, Long> {
    Optional<User> findOneByActivationKey(String activationKey);
    List<User> findAllByActivatedIsFalseAndCreatedDateBefore(ZonedDateTime dateTime);

    Optional<User> findOneByResetKey(String resetKey);

    Optional<User> findOneByEmail(String email);

    Optional<User> findOneByLogin(String login);

    Optional<User> findOneById(Long userId);

    @Override
    void delete(User t);
}

On UserService Im injecting the repository

@Service
@Transactional
public class UserService {
....

    @Inject
    private UserRepository userRepository;
....

When I run the application I'm getting and error because the user repository is trying to use Neo4j database in JPA repositories.

Is there any option to integrate spring-data-neo4j without impact on existing JPA infraestructure.

Thanks

Upvotes: 1

Views: 710

Answers (1)

Jasper Blues
Jasper Blues

Reputation: 28756

The reference guide for Spring Data Commons contains instructions on how to use two spring data projects, such as both Neo4j and JPA, simultaneously. See how you go with that. Let us know if you encounter any issues.

Upvotes: 3

Related Questions