Policy mapping? How's it work? (SDN and Neo4J).

47 views
Skip to first unread message

Dr Josef Karthauser

unread,
Mar 23, 2015, 1:04:57 PM3/23/15
to ne...@googlegroups.com
I’m still struggling with policy mapping with Spring-Neo4j-Data:

This works:

neo4jTemplate.createEntityFromStoredType(node,
neo4jTemplate.getMappingPolicy(MyClass))

Whereas this doesn’t work:

neo4jTemplate.createEntityFromStoredType(node, null)

Why would that be?

My spring wiring is:

graphDatabaseFactory(GraphDatabaseFactory)
graphDatabaseService(GraphDatabaseService, “data/graph.db") { bean ->
bean.factoryBean = "graphDatabaseFactory"
bean.factoryMethod = "newEmbeddedDatabase"
bean.destroyMethod = "shutdown"
}

bootstrapper(WrappingNeoServerBootstrapper, graphDatabaseService) { bean ->
bean.initMethod = "start"
bean.destroyMethod = "stop"
}

xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
neo4j.'repositories'( 'graphDatabaseService': "graphDatabaseService", 'base-package': "com.mycompany" )
neo4j.'config'( 'graphDatabaseService': "graphDatabaseService", 'base-package': "com.mycompany" )
ee(ExecutionEngine, graphDatabaseService)
neo4jTemplate(Neo4jTemplate, graphDatabaseService)

It’s doing my head in! I don’t want to have to read each node label by hand and then look for the right policy mapper for the associated class. :(.

I’ll buy a beer for anyone that can help me work this out!

Many thanks,
Joe

Dr Josef Karthauser

unread,
Mar 23, 2015, 1:10:55 PM3/23/15
to ne...@googlegroups.com
> On 23 Mar 2015, at 17:04, Dr Josef Karthauser <joe.kar...@wansdyketele.com> wrote:
>
> I’m still struggling with policy mapping with Spring-Neo4j-Data:
>
> This works:
>
> neo4jTemplate.createEntityFromStoredType(node,
> neo4jTemplate.getMappingPolicy(MyClass))
>
> Whereas this doesn’t work:
>
> neo4jTemplate.createEntityFromStoredType(node, null)

Interestingly, if I warm things up by running:

[MyClass, MyClass2, MyClass3].each {
neo4jTemplate.getMappingPolicy(it)
}

then

> neo4jTemplate.createEntityFromStoredType(node, null)

works for any of the nodes related to classes I prewarmed.

Bug? Or a wiring issue? Shouldn’t the spring wiring cause a pre-scan of my domain classes and do this for me?

Joe.


Dr Josef Karthauser

unread,
Mar 27, 2015, 5:14:45 PM3/27/15
to ne...@googlegroups.com
> On 23 Mar 2015, at 17:10, Dr Josef Karthauser <joe.kar...@wansdyketele.com> wrote:
>
>> On 23 Mar 2015, at 17:04, Dr Josef Karthauser <joe.kar...@wansdyketele.com> wrote:
>>
>> I’m still struggling with policy mapping with Spring-Neo4j-Data:
>>
>> This works:
>>
>> neo4jTemplate.createEntityFromStoredType(node,
>> neo4jTemplate.getMappingPolicy(MyClass))
>>
>> Whereas this doesn’t work:
>>
>> neo4jTemplate.createEntityFromStoredType(node, null)
>
> Interestingly, if I warm things up by running:
>
> [MyClass, MyClass2, MyClass3].each {
> neo4jTemplate.getMappingPolicy(it)
> }

Did this ring a bell with anyone?

Thanks,
Joe


Michael Hunger

unread,
Mar 27, 2015, 7:18:13 PM3/27/15
to ne...@googlegroups.com
You usually don't have to bother with this.

how does this ` neo4jTemplate.createEntityFromStoredType(node, null)` not work?

M
> --
> You received this message because you are subscribed to the Google Groups "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Josef Karthauser

unread,
Mar 28, 2015, 12:09:47 PM3/28/15
to ne...@googlegroups.com
No, that's the surprising thing. Supplying a null only works for classes for which I've already run 'neo4jTemplate.getMappingPolicy(ClassName)' on.

Joe  

Michael Hunger

unread,
Mar 28, 2015, 2:51:36 PM3/28/15
to ne...@googlegroups.com
What does your config look like? Do you provide your base package(s) of your entities?

It looks a bit as if SDN doesn't know your entities yet?

Michael

Dr Josef Karthauser

unread,
Mar 30, 2015, 4:37:18 PM3/30/15
to ne...@googlegroups.com
Neo4j config, or spring config? I’ve not set anything different from what comes out of the box.

I’m confused, because with the wiring:

>            neo4j.'repositories'( 'graphDatabaseService': "graphDatabaseService", 'base-package': "com.mycompany" ) 
>            neo4j.'config'( 'graphDatabaseService': "graphDatabaseService", 'base-package': "com.mycompany" ) 

the repositories are scanned and wired, and work ok. Why would they work, but the explicit getEntityFromStored type not?

Joe


You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/0suc8GmgTpM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

Michael Hunger

unread,
Apr 3, 2015, 8:08:51 PM4/3/15
to ne...@googlegroups.com
In the end getMappingPolicy just calls mappingContext.getPersistentEntity() which should fail if the entity is not known.

you actually should never call that method directly.

can you use template.project(entity, type) instead?

Michael

Dr Josef Karthauser

unread,
Apr 9, 2015, 3:43:25 PM4/9/15
to ne...@googlegroups.com
The point is that I don’t want to have to work out the class of the entity in advance, by looking at labels and so on.  The method neo4jTemplate.createEntityFromStoredType(node, null) is supposed to do that, but it doesn’t work for me unless I’ve previously tickled it by using:

        myDomainClasses.each {
            neo4jTemplate.getMappingPolicy(it)
        }

:(

I haven’t managed to work out how to get the SDN source bound to my project, so I’ve not been able to step into the code to work out what’s going wrong.

Joe
Reply all
Reply to author
Forward
0 new messages