I'm trying to setup a system to pull data from a Neo4J database and push it into a Postgres database. The connection to the Neo4J database is longstanding, and the Postgres connection is new. I'm able to retrieve data from the Postgres databsae just fine, however when calling save
or saveAll
, I see no updates actually pushed. My (very simple) service class is below:
public class RCAWorkflowService {
private final RCAWorkflowRepository rcaWorkflowRepository;
private final Neo4jClient neo4jClient;
public Iterable<RCAWorkflow> findAll() {
return rcaWorkflowRepository.findAll();
}
public void pushWorkflows() {
var rcaWorkflows = neo4jClient.query("""{{CYPHER CODE TO PULL ENTITIES}}""")
.fetchAs(RCAWorkflow.class)
.mappedBy(RCAWorkflow::map)
.all();
rcaWorkflowRepository.saveAll(rcaWorkflows);
}
public void createWorkflow(String workflowId, String appId) {
var wf = new RCAWorkflow(
UUID.randomUUID(),
workflowId,
"localhost",
"1.0",
appId,
"json!",
new Date()
);
rcaWorkflowRepository.save(wf);
}
}
The config for the Postgres connection is as follows:
@Configuration
@EnableJpaRepositories(basePackages = "package")
public class RCAPostgresConfig {
@Bean
public DataSource rcaDataSource() {
var dataSource = new DriverManagerDataSource();
dataSource.setUrl("url");
dataSource.setUsername("username");
dataSource.setPassword("password");
return dataSource;
}
@Primary
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean rcaEntityManager() {
var em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(rcaDataSource());
em.setPackagesToScan("package");
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
var properties = Map.of(
"hibernate.hbm2ddl.auto", "none",
"hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect",
"hibernate.show-sql", "true"
);
em.setJpaPropertyMap(properties);
return em;
}
@Bean
public PlatformTransactionManager rcaTransactionManager() {
var transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(rcaEntityManager().getObject());
return transactionManager;
}
}
The repository class is nothing special -- just an interface extending off of JpaRepository
and nothing else.
Any ideas on why this is able to retrieve data through findAll
, but neither of my methods to push data into the database are working? No exceptions are thrown, I've even tried just throwing a try/catch
block in on the off chance it caught something, but still nothing. It just silently doesn't actually save any entities.
Did you try to make your Service methods transactional in order to let the ORM manage the commit ?
@Transactional
public void createWorkflow(String workflowId, String appId) {
var wf = new RCAWorkflow(
UUID.randomUUID(), workflowId, "localhost", "1.0", appId, "json!",
new Date());
rcaWorkflowRepository.save(wf);
}