Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-16-2020 08:40 AM
Hi I am using org.springframework.boot:spring-boot-starter-data-neo4j -> 2.2.3.RELEASE library to work with Neo4j. I have multi module project where my DAO classes are in separate module. The problem is when I am trying to do some operation on Neo4j database I got following error ->
# [neo4j :: Getting java.lang.IllegalArgumentException: Class class com.my.domain.Address is not a valid entity class. Please check the entity mapping]
MY ADDRESS DAO :
@NodeEntity
@Getter
@Setter
public class Address {
@Id
@GeneratedValue(strategy = UuidStrategy.class)
private Long id;
private String country;
private String city;
private String street;
private String postalCode;
@Relationship(value = "LIVES_AT", direction = INCOMING)
private User user;
}
DAO classes are recognized in Intellij IDEA and I can also build my project with Gradle, but during runtime mentioned error is occuring. Please can you tell me how can I fix this issue ? Is there any way to tell neo4j to recognize these external DAO classes ? Thanks for help.
Solved! Go to Solution.
08-17-2020 01:23 AM
Hi after some research I find out that problem was in session OGM creates. It was not checking these external packages for DAOs so I was forced to override default session as following ->
@Bean
public SessionFactory sessionFactory() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder()
.uri(databaseUrl)
.credentials(userName, password)
.build();
return new SessionFactory(configuration,"my.external.package.with.dao");
}
@Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
I am not sure if this correct implementation because I read one stack overflow post where guy mentioned that it is not needed to override session in case spring-data-neo4j library. So is there another way to update session with new DAO package ? Thanks for help @amsilf
08-16-2020 07:25 PM
It's hard to say what's the problem without seeing the whole code but I doesn't looks like that the issue is not with neo4j, but more like with your spring configuration; could you please share your project structure and a way your configure spring?
08-17-2020 01:23 AM
Hi after some research I find out that problem was in session OGM creates. It was not checking these external packages for DAOs so I was forced to override default session as following ->
@Bean
public SessionFactory sessionFactory() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder()
.uri(databaseUrl)
.credentials(userName, password)
.build();
return new SessionFactory(configuration,"my.external.package.with.dao");
}
@Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
I am not sure if this correct implementation because I read one stack overflow post where guy mentioned that it is not needed to override session in case spring-data-neo4j library. So is there another way to update session with new DAO package ? Thanks for help @amsilf
08-23-2020 09:38 PM
Sorry for late reply, that's a bit strange behaviour, @EnableTransactionManagement and @EnableNeo4jRepositories should do the job for you; you have to initialize transaction manager manually only if it's required to have connection to multiple dbms, e.g. to neo4j and mysql or some unique rollback behaviour is required.
08-24-2020 01:33 AM
without creating custom sessionFactory and transactionManager my project did not work
All the sessions of the conference are now available online