Neo4j Error | List<MyObject> | error- org.neo4j.ogm.exception.core.InvalidPropertyFieldException - neo4j

I have a neo4j database, and one of the nodes in the database has the following:
public class Location
{
.
.
.
#Property(name = "zone_quantities")
private List<ZoneQuantity> zoneQuantityList;
}
When I try to use ogm to map the node into the object, I get the following error:
Caused by: org.neo4j.ogm.exception.core.InvalidPropertyFieldException: 'com.livspace.atp.domain.InvSku#zoneQuantityList' is not persistable as property but has not been marked as transient.
Neo4j version - 3.1.6
#Getter
#Setter
#NoArgsConstructor
#AllArgsConstructor
public class ZoneQuantity {
private String zone;
private Integer quantity;
}

Neo4j-OGM does not know what to do with the custom type property ZoneQuantity.
It is either a relationship and has to get described as such e.g.
#Relationship("HAS_ZONE")
private List<ZoneQuantity> zoneQuantityList;
or you need to provide an AttributeConverter for your custom type (collection) that converts it into a database compatible type. For example something like this converter https://github.com/neo4j/neo4j-ogm/blob/master/core/src/main/java/org/neo4j/ogm/typeconversion/NumberCollectionStringConverter.java#L37

Related

MappingException(Attempt to add id) after upgrading to spring boot 2.2.X

After upgrading the spring boot to 2.2.4 (from 2.1.x), org.springframework.cloud:spring-cloud-dependencies to Hoxton.RELEASE and org.springframework.cloud:spring-cloud-stream-dependencies to Horsham.RELEASE.
Getting the following exception when trying to create index document.
Caused by: org.springframework.data.mapping.MappingException: Attempt to add id property private java.util.Map .CatalogIndex.document but already have property private java.lang.String .CatalogIndex.id registered as id. Check your mapping configuration!
Please find the entity class hierarchy. I have removed all the getter and setter for simplicity.
package mypackage.entity;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Parent;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class CatalogIndex {
private static final long serialVersionUID = 1L;
#Id
private String id;
#Parent(type = "Initiative")
private String initiativeId;
private List<Map<String, Object>> typeHierarchy;
private Map<String, Object> document;
private List<Map<String, Object>> filters;
}
package mypackage.entity;
import org.springframework.data.elasticsearch.annotations.Document;
#Document(indexName = "cataloginitiative")
public class CatalogInitiativeIndex extends CatalogIndex { }
Spring Data Elasticsearch, when inspecting the Entity class, tries to figure out which property of the class is to be used as the Id property. A property qualifies for this if one of the following is true:
the property is annotated with #Id
the property is named id
the property is named document
So in your case you have the property id which has a matching name and the annotation, and the property document with a matching name.
You have to rename your property document to somthing different.

SpringData Cassandra Java Adapter - Using UDTs in Map Columns

I am using the 1.5.1 version of the Cassandra adapter for Java, and I am attempting to insert a record to a table having a Map column that uses a UDT as the column value (key is just a varchar). I created the table using cqlsh and am able to insert to it in CQL just fine. When i try to use a CassandraTemplate...insert(), though, all I get is:
UserTypeResolver must not be null
My UDT class is defined as:
#UserDefinedType("iss_type")
public class IssueType {
#CassandraType(type = DataType.Name.VARCHAR)
private String issue_code;
#CassandraType(type = DataType.Name.VARCHAR)
private String issue_name;
#CassandraType(type = DataType.Name.TIMESTAMP)
private Date issue_start;
#CassandraType(type = DataType.Name.TIMESTAMP)
private Date issue_end;
And my table is defined as
#Table
public class IssueMap {
#PrimaryKeyColumn(
type = PrimaryKeyType.PARTITIONED)
private UUID map_id;
#Column
private Map<String, IssueType> issue_map;
In my config, i have:
#Bean
public CassandraMappingContext cassandraMapping()
throws ClassNotFoundException {
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(cluster().getObject(),"campaign_management"));
return mappingContext;
}
Is there something I am missing here? Or is it just not possible to define columns this way? I realize I could just use a query builder to create the CQL and do the insert, but I was hoping to be able to make full use of the Cassandra template features.

GSP Accessing domain class static field

I have a domain class which contains a Class[] array. I want the contents of that array displayed
using g:select. Although I cannot find how to access those fields. I tried <%#page import="package.path.to.PropertyDefinition" %> and then
<g:select from="${PropertyDefinition.types}" name="cust_prop_type"/>
Although I am getting a very big exception of type org.codehaus.groovy.control.MultipleCompilationErrorsException
Is it possible to access that static Array without making use of a Controller class?
I am using version 2.3.7
class PropertyDefinition {
#Transient
public static final Class[] validTypes = [Integer.getClass(), String.getClass(), RefdataValue.getClass(), BigDecimal.getClass()]
.
.
.
Exception:
Caused by: java.lang.NullPointerException at
org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodGetParameterAnnotations(ReflectiveInterceptor.java:944)
at
org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:357)
at org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:258)
at org.codehaus.groovy.ast.ClassNode.getInterfaces(ClassNode.java:353)
at
org.codehaus.groovy.ast.ClassNode.declaresInterface(ClassNode.java:945)
at
org.codehaus.groovy.ast.ClassNode.implementsInterface(ClassNode.java:925)
at
org.codehaus.groovy.ast.ClassNode.isDerivedFromGroovyObject(ClassNode.java:915)
at
org.codehaus.groovy.classgen.AsmClassGenerator.isGroovyObject(AsmClassGenerator.java:937)
at
You've declared
public static final Class[] validTypes
in PropertyDefinition but you're accessing PropertyDefinition.types in the GSP...

How to get a node using index

I have an entity Place:
#NodeEntity
#TypeAlias(value="Place")
public class Place implements Serializable{
private static final long serialVersionUID = 1L;
#GraphId
private Long nodeId;
#JsonProperty("id")
#Indexed(unique=true)
private String id;
//...
}
And I try to get a node based on its id attribute this way:
String pfc = "1234";
(Node)template.getIndex(Place.class, "id").get("id", pfc).getSingle()
But I'm having this exception :
java.lang.IllegalStateException: Index name for class java.lang.String id rel: false idx: true must differ from the default name: Place
Must I necessairly add a name to the index?
If yes, how should I do for the existent data?
Which version are you using? In SDN 3.x for Neo4j 2.x the indexes and constraints are used automatically.
I would use a PlaceRepository with a findById() method.
Or in general cypher queries that access place like this:
MATCH (p:Place {id:{id}})-->(x)
RETURN x
You can access them manually with template.merge() or template.findByLabelAndProperty() which I would only recommend when you know what you're doing.

toString() in Grails Java Domain Class Causes

By default, grails seems to return <class name>:<id> for toString() of an Java domain object. That's not at all what I want of course, so I tried to #Override
the toString() to return what I want. When I tried grails generate-all Tagtype, I got the following error:
java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a differen
t type with name "org/w3c/dom/NamedNodeMap"
My code is below. Any help would be greatly appreciated.
#Entity
#Table(name = "tagtype", catalog = "tigger")
#SuppressWarnings("serial")
public class Tagtype implements Serializable {
/**
* Attribute id.
*/
private Integer id;
/**
* Attribute tagtype.
*/
private String tagtype;
/**
* Attribute regexpression
*/
private Regexpression regexpression;
. . .
#Override public String toString() {
StringBuilder result = new StringBuilder();
result.append(this.tagtype);
return result.toString();
}
}
I've overriden toString() in Grails domain classes without any problems, so that can't be the reason. This blog suggests it could be a result of name collisions, either temporary (have you tried running "grails clean"?) or perhaps your class name Tagtype collides with some grails internals.
Another thing you could try is using different versions of Grails, especially the latest 1.1.1 if you aren't already using that. This ML post describes an identical error message that was apparently version dependant.

Resources