Neo4j OGM query for relationships that don't have entity classes - neo4j-ogm

I have a particular use case, where I have a Neo4j instance with some data mapped to entity classes via OGM and some data that doesn't have an entity class. There are some relationships (without an entity class) that connect these two types of data.
I've been able to use the OGM query method to search for non entity mapped nodes and get back NodeModel instances. However when I try to include relationships I get the following errors:
21:11:28.707 [main] DEBUG org.neo4j.ogm.MetaData - looking for concrete class to resolve label: SPOKE_B
21:11:28.707 [main] DEBUG org.neo4j.ogm.MetaData - This label is not known in the mapping context. Moving on...
21:11:28.707 [main] DEBUG org.neo4j.ogm.MetaData - No resolving class found!!
21:11:28.707 [main] DEBUG org.neo4j.ogm.MetaData - looking for concrete class to resolve label: HUB
21:11:28.707 [main] DEBUG org.neo4j.ogm.MetaData - This label is not known in the mapping context. Moving on...
21:11:28.707 [main] DEBUG org.neo4j.ogm.MetaData - No resolving class found!!
21:11:28.707 [main] DEBUG org.neo4j.ogm.context.GraphEntityMapper - Relationship (0)-[SGEdge]->(2) cannot be hydrated because one or more required node types are not mapped to entity classes
I looked at some of the code and GraphEntityMapper.mapRelationships(), https://github.com/neo4j/neo4j-ogm/blob/master/core/src/main/java/org/neo4j/ogm/context/GraphEntityMapper.java, only returns relationships if both of the nodes are successfully mapped to an entity class.
So it seems I can't use the OGM query method to get relationships between nodes that aren't mapped to entity classes. Anyone know a way around this?
I realize could use a different driver, but I'd rather not maintain two different driver connections to the same database.

I faced this issue today and found out a solution.
This is an issue of Neo4j-OGM. You can check the issue here.
As #mangrish said:
To fix this simply return a,r,n and remove the path from the MATCH
statement.
In short, you have to return StartNode, EndNode besides RelationshipEntity. It seems not good but at least it works.
E.g: You have to custom your cypher this way.
MATCH (s:StartNode)-[r:SGEdge]->(e:EndNode) return s, r, e
Note: You should have a look at their test

Related

How to use custom jackson de-/serializer in kie execution server?

I am using Kie Execution Server 6.5 (docker image). I deploy a kie container (kjar) which contains some rules and some custom java classes. Everything was working so far.
Now, I added some 3rd party classes to my java classes (geojson-jackson
), which use a custom jackson serializer and deserializer declared with #JsonDeserialize(using = LngLatAltDeserializer.class), see LngLatAlt.
First I had class loading issues, apparently because of different jackson versions, which I solved by using geojson-jackson 1.3 and excluding the jackson dependency in my pom.xml.
The container is now started successfully, but objects cannot be deserialized, because the custom deserializer is not used. I get a MarshallingException caused by
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of
org.geojson.LngLatAlt out of START_ARRAY token
at [Source: java.io.StringReader#33714932; line: 1, column: 385] (through reference chain:
org.drools.core.command.runtime.BatchExecutionCommandImpl["commands"]->
org.drools.core.command.runtime.rule.InsertObjectCommand["object"]->
MYPACKAGE.MYCLASS["polygon"]->org.geojson.Polygon["coordinates"])
at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
This is exactly the part the custom deserializer should take care of.
Update: Karel Suta's answer helped me to investigate further.
The issue 5776 to the PR indicates that annotating a DTO should be possible to extend the JSON marshaller. The new JSONMarshallerExtension should only be needed if the object model is not to be annotated.
https://issues.jboss.org/browse/JBPM-5776
https://github.com/kiegroup/droolsjbpm-integration/pull/851
Enabling debug log level for org.kie.server, I got:
DEBUG [org.kie.server.services.drools.DroolsKieServerExtension] (default task-1) Adding org.geojson.Polygon type into extra jaxb classes set
DEBUG [org.kie.server.services.drools.DroolsKieServerExtension] (default task-1) Added org.geojson.Polygon type into extra jaxb classes set
DEBUG [org.kie.server.services.drools.DroolsKieServerExtension] (default task-1) Adding org.geojson.LngLatAlt type into extra jaxb classes set
DEBUG [org.kie.server.services.drools.DroolsKieServerExtension] (default task-1) Added org.geojson.LngLatAlt type into extra jaxb classes set
...
and
DEBUG [org.kie.server.api.marshalling.BaseMarshallerBuilder] (default task-2) About to build default instance of JSON marshaller with classes [
..., class org.geojson.Polygon, org.geojson.LngLatAlt, ...
Together with over hundred other classes (all dependencies it seems). So the classes are recognized and maybe supplying a JSONMarshallerExtension for them would work (I have not figured out, how to do that), but it should be possible with annotations as well.
Any other suggestions to get the annotations working?
In latest snapshot it could be possible to define custom marshaller for classes using JSONMarshallerExtension, see this PR.

CDI environment configuration, handling properties with annotations

Found DeltaSpike that sort of does what I want....
Working with EJB 3.1 and really want to be able to annotate class properties so that "environment" properties are injected either at class load time or lazy on access plus the ability to allow for updates. For example:
#Environment(name="greeting.for.aliens", fetch="lazy", updates="true")
private String welcomeSign;
The name attribute is a match on a property name pulled from different sources like Java System, environment variables (from the shell), JNDI, property files and so forth. The fetch either says load on initiation or lazy (underpinned by Instance wrapper). Then if the "environment" properties are updated the interested "class" properties listen for that event.
More amazed that nobody has put together something (beyond DeltaSpikes) like this for EJB/CDI? Or I haven't found a good combination of Google keys words to get me to the right implementation for me.

What is Castle proxy factory in NHibernate?

What is Castle proxy factory in NHibernate? What is its task? What does proxy mean in this case?
Castle can be used (amongst others, you have the choice, you can also use LinFu, Spring.NET, ...) to create dynamic proxies of your entities.
By default, NHibernate uses dynamic proxies to represent your entities; by doing so, it is able to return an object to you when you retrieve some entity from the DB, without all properties being populated. By using a dynamic proxy, it will only populate the entity once you really refer to a property.
(So it is some kind of lazy loading; not to be confused with lazy loading of collections / associations though).
This behaviour is the reason why NHibernate wants you to create every property as virtual by default: NHibernate will create a new class using this Castle (or LinFu, ...) proxy provider which inherits from your entity, and it will override all the properties so that it can 'inject' the code that is necessary to retrieve the necessary data from the DB.
You can disable this behaviour by specifying 'lazy=false' in your entity mapping. (Although, I do think that even if you disable this feature, NHibernate will still require that you use one of the proxy factories).
When you are selecting an entity from ISession you are getting not real entity instance - you are getting proxy object.
This proxy object inherits your entity and used by NHibernate to track changes made to the fields.
see it: http://en.wikipedia.org/wiki/Proxy_pattern

wcf and ADO entity framework

We are using Linq to Entities in WCF service. We created a edmx file which contains auto generated entities. While creating proxy the entities are not appearing in the proxy class even the data contract and datamember attributes are there. We found that the problem is because of the auto generated entities are inheriting from something called System.Data.Objects.DataClasses.EntityObject But if we create a class without any inheritance that class is appearing in the proxy. Is there any way to resolve this?
Regards
Sekar
The way we do this is:
Auto generate entity framework entities
Create separate classes to be used in the data contracts
Write mapping code to convert from one contract classes to entity classes, and back
This may be a bit cumbersom but it works (it also isolates your services from changes in your database). This should become much easier in the next version of entity framework.

NHibernate.MappingException: Unknown entity class

I am trying to get test running that uses FluentNHibernate to map my
entities.
I get unknown entity class error.
I have a Domain project that has my entities and the mappings in a seperate
folder in that project.
My test project has the Nhibrenate configuration in the App.Config.
Any ideas please???
Malcolm
EDIT: I have this method that creats the ISessionFactory but I dont think this code is working and this is why it does not recoginze me mappings exist at all. The SessionFacoryCreator is the assembly with my AppConfig and Recipe is my assembly where the Domain objects are. Please HELLLLLLP!!!!
public static ISessionFactory Create()
{
Configuration cfg = new Configuration()
.AddAssembly(typeof(SessionFactoryCreator).Assembly)
.AddAssembly(typeof(Recipe).Assembly);
return cfg.BuildSessionFactory();
}
Have you read the wiki? Your example shows nothing of hooking Fluent NHibernate into the session factory building, that'd be why it isn't working. Start with the Getting Started guide.
How do you add your Entities to the Hibernate framework? Are you using AnnotationConfiguration or just Configuration? If you are using annotations you must add your annotated entity to the framwork. Otherwise, if you are using xml hibernate mapping, the syntax could be worng (iirc)
NHibernate and I keep on getting the following error: MappingException: Unkown Entity Class
If you get MappingException error, there are two things you should check out:
Make sure the name of the *.hbm.xml is spelled correctly — not *.hmb.xml nor *.mbh.xml
Make sure the Build Action property is set to “Embeded Resource.”