Announcement Announcement Module
Collapse
No announcement yet.
Neo4j: Custom ConversionService example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Neo4j: Custom ConversionService example

    Hello,

    I'm trying to register my custom conversion for Joda DateTime field that I have inside my mapped node entity, but sicne I cannot see any example in reference docs, I have to ask here...

    Anyway, I'm planning to convert Joda dateTime to/from Long.

    My to/from converters are:

    Code:
    public class JodaDateTimeToLongConverter implements Converter<DateTime, Long> {
        public Long convert(DateTime dateTime) {
            return dateTime.getMillis();
        }
    }
    
    public class LongToJodaDateTimeConverter implements Converter<Long, DateTime> {
        public DateTime convert(Long millis) {
            return new DateTime(millis);
        }
    }
    And it doesn't work. I get in my log:
    INFO [org.springframework.data.neo4j.fieldaccess.Delegat ingFieldAccessorFactory] No FieldAccessor configured for field: class org.joda.time.DateTime timestamp rel: false idx: false

    And my spring XML looks like:

    Code:
        <context:annotation-config/>
    
        <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown">
            <constructor-arg value="C:/helloworld-neo4j"/>
        </bean>
    
        <neo4j:config graphDatabaseService="graphDatabaseService"/>
    
        <bean id="neo4jTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
            <property name="transactionManager" ref="springTransactionManager"/>
            <property name="userTransaction">
                <bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
                    <property name="transactionManager" ref="springTransactionManager"/>
                </bean>
            </property>
        </bean>
    
        <bean id="springTransactionManager" class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
            <constructor-arg ref="graphDatabaseService"/>
        </bean>
    
    
        <tx:annotation-driven transaction-manager="neo4jTransactionManager" />
    
        <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
            <property name="converters">
                <set>
                    <bean class="org.mycompany.neo4j.utils.JodaDateTimeToLongConverter"/>
                    <bean class="org.mycompany.neo4j.utils.LongToJodaDateTimeConverter"/>
                </set>
            </property>
        </bean>
    Regards,
    Vjeran

  • #2
    Something strange is happening here.
    It seems that conversion works fine when I want to convert my Joda DateTime field to String, by registering DateTime->String converters, and plainly defining field inside node entity class like:

    Code:
        private DateTime timestamp;
    But when I specify that I want it stored as Long node property, with dateTime->Long converters registered, it doesn't work then:

    Code:
        @GraphProperty(propertyType = Long.class)
        private DateTime timestamp;
    What is more strange, I understood that the library has the same conversion already given for java.util.Date fields, so one can successfuly specify field mapping such as:

    Code:
        @GraphProperty(propertyType = Long.class)
        private Date timestamp;
    Should I report this as a bug?

    Regards,
    Vjeran

    Comment


    • #3
      Do you encounter an exception there? Or does it just not do anything?

      Yes please report a bug and if possible share a sample project/test-case that does reproduce the issue.

      Thanks a lot

      Michael

      Comment

      Working...
      X