Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MappingException in 3.0.1.RELEASE #161

Closed
monitorjbl opened this issue Mar 14, 2014 · 20 comments
Closed

MappingException in 3.0.1.RELEASE #161

monitorjbl opened this issue Mar 14, 2014 · 20 comments

Comments

@monitorjbl
Copy link

I tried updating to 3.0.1.RELEASE today from 3.0.0.RELEASE. I'm unable to use the new version at all due this exception below. I ended up switching back to 3.0.0.RELEASE.

Caused by: org.springframework.data.mapping.model.MappingException: Unknown persistent entity my.class.name
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:169)
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141)
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67)
    at org.springframework.data.neo4j.repository.query.CypherQueryBuilder.<init>(CypherQueryBuilder.java:37)
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:72)
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:35)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
    at org.springframework.data.neo4j.repository.query.DerivedCypherRepositoryQuery.<init>(DerivedCypherRepositoryQuery.java:59)
    at org.springframework.data.neo4j.repository.query.GraphQueryMethod.createQuery(GraphQueryMethod.java:146)
    at org.springframework.data.neo4j.repository.GraphRepositoryFactory$1.resolveQuery(GraphRepositoryFactory.java:113)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)
    at org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean.afterPropertiesSet(GraphRepositoryFactoryBean.java:69)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
    ... 43 more

This class has the @NodeEntity annotation, so I'm not sure what's going on here. Did something change in the latest version? Do I need to include a different kind of annotation on my model POJOs now?

@jjlharrison
Copy link

Is there an upgrade guide for 3.0.1.RELEASE? I am seeing similar issues.

@jexp
Copy link
Contributor

jexp commented Mar 14, 2014

Did you both specificy base-package for your entities in the configuration? It is now mandatory, and what you see is the enabled strict-checking in the MappingContext.

see the blog post: http://blog.neo4j.org/2014/03/spring-data-neo4j-progress-update-sdn-3.html

@monitorjbl
Copy link
Author

Yep, that was the problem for me. Put that in my <neo4j:config/> and everything worked. Thanks Michael!

@monitorjbl
Copy link
Author

Not sure if this would be possible, but it would be nice if the exception message was more helpful. The docs for Spring are often hard to deal with; tracking down info for your specific version and combination of components is pretty tough at times.

@jexp
Copy link
Contributor

jexp commented Mar 14, 2014

Unfortunately that exception is generated by SD-Commons. We could only capture that, check he message and re-throw with a better message which also sucks. Actually the base-package attribute is mandatory in the 3.0 xsd but the xsd alias still points to 2.x

@monitorjbl
Copy link
Author

Ah, I see. Well, hopefully uncle Google will find this issue if anyone else runs into it :)

tuxBurner pushed a commit to tuxBurner/play-neo4jplugin that referenced this issue Mar 20, 2014
@sdcuthbertson
Copy link

I am trying to upgrade and I cannot get past this error at all! below is my current XML set up, I am getting the same error with Java Config

<neo4j:config graphDatabaseService="graphDatabaseService" base-package="com.company.dataservice.entities" />
<neo4j:repositories base-package="com.company.dataservice.repositories" />

<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase"
        destroy-method="shutdown">
    <constructor-arg index="0" value="http://localhost:7474/db/data" />
</bean>

<bean id="neo4jTemplate" class="org.springframework.data.neo4j.support.Neo4jTemplate">
    <constructor-arg index="0" ref="graphDatabaseService" />
</bean>

<bean id="neo4jMappingContext" class="org.springframework.data.neo4j.support.mapping.Neo4jMappingContext" />
<bean id="transactionManager" class="org.springframework.data.neo4j.config.JtaTransactionManagerFactoryBean">
    <constructor-arg index="0" ref="graphDatabaseService" />
</bean>
<bean id="hibernateExceptionTranslator" class="org.springframework.orm.hibernate4.HibernateExceptionTranslator" />

@jexp
Copy link
Contributor

jexp commented Mar 25, 2014

@scuthbertson Which error are you exactly getting?

Btw. there are not real transactions over REST.

Youu usually don't have to configure the template, mappingcontext or tx-Manager.

@sdcuthbertson
Copy link

Hi @jexp, it was the exact error that @monitorjbl was having, the Unknown persistent entity error.

Ah, OK, thanks for the pointer.

I am upgrading from 2.3.2.RELEASE to 3.0.1.RELEASE and moving from Neo4J 1.9.5 to 2.0.1

I have rolled back to the 3.0.0.RELEASE of Spring Data Neo4J and appear to be having better success.

Cheers for the help.

@jexp
Copy link
Contributor

jexp commented Mar 25, 2014

Don't roll back, it is a feature not a bug. Strict checking would have been enabled in 3.0.0 already if there hadn't been an issue in SD-Commons.

What is the exact error message? Which bean is not found? Is it part of the base-package that you provide to neo4j:config?

@sdcuthbertson
Copy link

Hi @jexp

OK, since my last communication, I have reverted back to 3.0.0, and have it in a semi-working state using the Java Config, I just need to update all of our custom Cypher to be Neo4J compliant.

I changed my gradle settings to use SDN 3.0.1.RELEASE and the following error happens:

Caused by: org.springframework.data.mapping.model.MappingException: Unknown persistent entity com.company.dataservice.entities.Member
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:169)
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141)
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67)
    at org.springframework.data.neo4j.repository.query.CypherQueryBuilder.<init>(CypherQueryBuilder.java:37)
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:72)
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:35)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
    at org.springframework.data.neo4j.repository.query.DerivedCypherRepositoryQuery.<init>(DerivedCypherRepositoryQuery.java:59)
    at org.springframework.data.neo4j.repository.query.GraphQueryMethod.createQuery(GraphQueryMethod.java:146)
    at org.springframework.data.neo4j.repository.GraphRepositoryFactory$1.resolveQuery(GraphRepositoryFactory.java:113)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)
    at org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean.afterPropertiesSet(GraphRepositoryFactoryBean.java:69)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)

My Java Config is (It's identical to my previous XML):

@Configuration
@EnableNeo4jRepositories(basePackageClasses = { Neo4jRepositoryConfig.class },
        excludeFilters = { @Filter(Configuration.class) })
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@PropertySource({ "classpath:company.application.properties" })
public class Neo4jRepositoryConfig extends Neo4jConfiguration {

    @Resource
    private PropertyResolver propResolver;

    public Neo4jRepositoryConfig() throws ClassNotFoundException {
        setBasePackage("com.company.dataservice.entities", "org.springframework.social.connect.neo4j");
    }

    @Bean(destroyMethod = "shutdown")
    public GraphDatabaseService graphDatabaseService() throws IOException {

        return new SpringRestGraphDatabase(propResolver.getRequiredProperty("neo4j.server.url") + "/db/data");
    }

    @Bean
    public Neo4jTemplate neo4jTemplate() throws IOException {
        return new Neo4jTemplate((GraphDatabase) graphDatabaseService());
    }

    @Bean
    public Neo4jMappingContext neo4jMappingContext() {
        return new Neo4jMappingContext();
    }

    @Bean
    public JtaTransactionManagerFactoryBean transactionManager() throws Exception {
        return new JtaTransactionManagerFactoryBean(graphDatabaseService());
    }

    @Bean
    public HibernateExceptionTranslator hibernateExceptionTranslator() {
        return new HibernateExceptionTranslator();
    }
}

The Member entity is inside my entities package. This config works with SDN 3.0.0.RELEASE as I have said but just that my Cypher does not comply at the moment.

@jexp
Copy link
Contributor

jexp commented Mar 25, 2014

Weird

Can you try it with only one parameter passed to setBasePackage() ? I assume in spring-social there are no @NodeEntity annotated Pojos?

I also saw that there is no base-package on @EnableNeo4jRepositories ?

And as I said there are no transactions over the wire. Just so that you are not surprised by the behavior. Currently I rather recommend going with embedded Neo4j than server if you want to have fun. :)

@sdcuthbertson
Copy link

I have

basePackageClasses = { Neo4jRepositoryConfig.class }

in the @EnableNeo4jRepositories, is this not the same behaviour as
base-package?

There is one POJO with @NodeEntity in there but it is a Jar that I have
control off and is just included into the project.

Trying with just one in there, has the same result. :-(

On 25 March 2014 17:22, Michael Hunger notifications@github.com wrote:

Weird

Can you try it with only one parameter passed to setBasePackage() ? I
assume in spring-social there are no @NodeEntity annotated Pojos?

I also saw that there is no base-package on @EnableNeo4jRepositories ?

And as I said there are no transactions over the wire. Just so that you
are not surprised by the behavior. Currently I rather recommend going with
embedded Neo4j than server if you want to have fun. :)

Reply to this email directly or view it on GitHubhttps://github.com//issues/161#issuecomment-38594237
.

@jexp
Copy link
Contributor

jexp commented Mar 25, 2014

Would you be able to create a test project that exhibits this behavior?

I can't reproduce it locally.

Thanks!

@sdcuthbertson
Copy link

Hi Michael,

I will have a look at this tomorrow for you.

Cheers,

Steven

On 25 March 2014 18:02, Michael Hunger notifications@github.com wrote:

Would you be able to create a test project that exhibits this behavior?

I can't reproduce it locally.

Thanks!

Reply to this email directly or view it on GitHubhttps://github.com//issues/161#issuecomment-38599211
.

@ccit-spence
Copy link

@jexp I was able to produce this error by following the spring.io example

https://github.com/spring-guides/gs-accessing-neo4j-data-rest

Same error as above

Tried the following versions.
spring-data-neo4j:3.0.1.RELEASE -- FAILED
spring-data-neo4j:3.1.0.BUILD-SNAPSHOT --FAILED

spring-data-neo4j:3.0.1.RELEASE --WORKED

@jexp
Copy link
Contributor

jexp commented Mar 29, 2014

@ccit-spence Sent a pull request to that project, you have to add a constructor to the Application that sets the base package:

public Application() {
     setBasePackage("hello");
}

@ccit-spence
Copy link

Works perfectly now... spring-data-neo4j:3.1.0.BUILD-SNAPSHOT

@sdcuthbertson
Copy link

Hi @jexp, I have been trying to create a project for you that is replicating this issue but I cannot seem to get a project set up that replicates this.

It appears to be something in the setup then of our full project that is throwing this all off. Sorry for the bother.

@mangrish
Copy link
Contributor

mangrish commented Aug 2, 2016

Closed. Issue out of date.

@mangrish mangrish closed this as completed Aug 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants