Thursday, 15 March 2012

spring data neo4j - Enum conversion to String not working on @Indexed unique field -



spring data neo4j - Enum conversion to String not working on @Indexed unique field -

i'm neo4j/spring-data newbie apologies if obvious looked here , there , can't quite figure out if it's bug or feature. i'm using sdn 3.1.0 , neo4j 2.0.4, running in memory (for testing).

i have super simple pojo seek save neo4j using sdn. looks so:

@nodeentity public class weekday { @graphid private long id; @indexed(unique = true) public dayofweek weekdaycode; }

everything works beautifully when create non-uniquely indexed, or not indexed @ all. works fine unique constraint when create string well. (well, sort of, i'm aware doesn't throw exception silently updates existing 1 - not perfect found jira issue related that). unfortunately moment seek save enum unique constraint exception:

org.springframework.dao.invaliddataaccessresourceusageexception: error executing statement merge (n:`weekday` {`weekdaycode`: {value}}) on create set n={props} homecoming n; nested exception org.springframework.dao.invaliddataaccessresourceusageexception: error executing statement merge (n:`weekday` {`weekdaycode`: {value}}) on create set n={props} homecoming n; nested exception java.lang.illegalargumentexception: [monday:java.time.dayofweek] not supported property value @ org.springframework.data.neo4j.support.query.cypherqueryengineimpl.query(cypherqueryengineimpl.java:61) @ org.springframework.data.neo4j.support.schema.schemaindexprovider.merge(schemaindexprovider.java:114) @ [...] caused by: org.springframework.dao.invaliddataaccessresourceusageexception: error executing statement merge (n:`weekday` {`weekdaycode`: {value}}) on create set n={props} homecoming n; nested exception java.lang.illegalargumentexception: [monday:java.time.dayofweek] not supported property value @ org.springframework.data.neo4j.support.query.cypherqueryengineimpl.parseandexecutequery(cypherqueryengineimpl.java:72) @ org.springframework.data.neo4j.support.query.cypherqueryengineimpl.query(cypherqueryengineimpl.java:58) ... 63 more caused by: java.lang.illegalargumentexception: [monday:java.time.dayofweek] not supported property value @ org.neo4j.kernel.api.properties.propertyconversion.convertproperty(propertyconversion.java:107) @ org.neo4j.kernel.api.properties.property.property(property.java:51) @ [...]

this, far can see, because unique field set map "props", , contents of map not automatically converted sends enum neo4j, doesn't like.

is expected or should raise bug sdn? if that's expected behaviour, have alternatives other making field string?

i'm not sure if real bug, had similar problem using own enum class.

so, seek this:

create converters register them in neo4j

first create converters like:

@component public class stringtodayofweekconverter implements converter<string, dayofweek> { @override public dayofweek convert(string source) { homecoming dayofweek.valueof(source); } } @component public class dayofweektostringconverter implements converter<dayofweek, string> { @override public string convert(dayofweek source) { homecoming source.name(); } }

then register converters, neo4j can utilize them:

@configuration @enableneo4jrepositories("my.repository.package") @enabletransactionmanagement public class myneo4jconfiguration extends neo4jconfiguration { @autowired private stringtodayofweekconverter stringtodayofweekconverter; @autowired private dayofweektostringconverter dayofweektostringconverter; @override protected conversionservice neo4jconversionservice() throws exception { converterregistry converterregistry = (converterregistry) super.neo4jconversionservice(); converterregistry.addconverter(stringtodayofweekconverter); converterregistry.addconverter(dayofweektostringconverter); homecoming (conversionservice) converterregistry; } }

spring-data-neo4j

No comments:

Post a Comment