PageRenderTime 59ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/asciidoc/migration.adoc

http://github.com/SpringSource/spring-data-neo4j
AsciiDoc | 227 lines | 169 code | 58 blank | 0 comment | 0 complexity | 767b310c8f72fac0642516e3dd27fc3f MD5 | raw file
Possible License(s): Apache-2.0
  1. [[migration]]
  2. [appendix]
  3. = Migration Guide
  4. [[migration.5-0]]
  5. == Migrating from 4.2 -> 5.0/5.1
  6. * Base class for repositories `GraphRepository` has been renamed `Neo4jRepository` and parameter types change from `<T>` to `<T, ID>`.
  7. * All Repository methods can return `Streams`.
  8. * The repository method naming scheme has changed for SD commons 2.0 as part of https://jira.spring.io/browse/DATACMNS-944[DATACMNS-944].
  9. ** for example, `findOne` repository methods are renamed `findById` and now return `Optional<T>`.
  10. ** please check the JavaDoc of `org.springframework.data.repository.CrudRepository`
  11. * Paged custom queries no longer accept queries without `countQuery` attribute.
  12. * The keywords `Between` and `IsBetween` in query methods now include the given limits in the query.
  13. Use a combination of `GreaterThan`/`isGreaterThan` and `LessThan`/`isLessThan` (e.g. `isGreaterThanLowerLimitAndIsLessThanUpperLimit`) to keep the exclusive behavior.
  14. * Id handling : `Long` native ids are not mandatory anymore. See <<reference:annotating-entities:graph-id, GraphId field>>.
  15. * Primary indexes are now deprecated and replaced by `@Id` See <<reference:annotating-entities:entity-identifier, Entity identifier>>.
  16. * Annotations on accessors are no longer valid. See <<reference:annotating-entities, Annotating entities>>.
  17. * Loading with depth `-1` calls have to be reviewed (please see the Neo4j-OGM migration guide under _Migration from 2.1 to 3.0 / Performance and unlimited load depth_).
  18. * The `ogm.properties` file and environment variable have been removed.
  19. You have to explicitly provide the configuration file now or configure the driver programmatically.
  20. See <<reference:configuration:driver, the configuration section>>.
  21. * The driver class name in the configuration is now inferred from connection URL.
  22. * Java 8 dates are now better supported ; the use of `java.util.Date` or converters is not required anymore. You may want to switch to more fine grained date types like `Instant`. See <<reference:type-conversion:built-in, conversions>>.
  23. * The query filters are now immutable. See <<reference:filters, Filters>>.
  24. [[migration.4-2]]
  25. == Migrating from 4.0/4.1 -> 4.2
  26. Spring Data Neo4j 4.2 significantly reduces complexity of configuration for application developers.
  27. There is no longer a need to extend from `Neo4jConfiguration` or define a `Session` bean. Configuration for various types
  28. of applications are described <<reference.getting_started.spring-configuration,here>>
  29. 1. Remove any subclassing of `Neo4jConfiguration`
  30. 2. Define the `sessionFactory` bean with an instance of `SessionFactory` and the `transactionManager` bean with an instance of `Neo4jTransactionManager`. Be sure to pass the `SessionFactory` into the constructor for the transaction manager.
  31. [[migration.4-0]]
  32. == Migrating from pre 4.0 -> 4.2
  33. [[migration.4-0.packages]]
  34. === Package Changes
  35. Because the Neo4j Object Graph Mapper can be used independently of Spring Data Neo4j, the core annotations have been
  36. moved out of the spring framework packages:
  37. `org.springframework.data.neo4j.annotation` -> `org.neo4j.ogm.annotation`
  38. [NOTE]
  39. ====
  40. The `@Query` and `@QueryResult` annotations are only supported in the Spring modules, and are not used by the core
  41. mapping framework. These annotations have not changed.
  42. ====
  43. [[migration.4-0.annotations]]
  44. === Annotation Changes
  45. There have been some changes to the annotations that were used in previous versions of Spring Data Neo4j.
  46. Wherever possible we have tried to maintain the previous annotations verbatim, but in a few cases this has not been
  47. possible, usually for technical reasons but sometimes for aesthetic ones. Our goal has been to minimise the number
  48. of annotations you need to use as well as trying to make them more self-explanatory. The following annotations
  49. have been changed.
  50. |===
  51. h| Old h| New
  52. m| @RelatedTo m| @Relationship
  53. m| @RelatedToVia m| @Relationship
  54. m| @GraphProperty m| @Property
  55. m| @MapResult m| @QueryResult
  56. m| @ResultColumn m| @Property
  57. m| Relationship Direction.BOTH m| Relationship.UNDIRECTED
  58. |===
  59. [[migration.4-0.custom_converters]]
  60. === Custom Type Conversion
  61. SDN provides automatic type conversion for the obvious candidates: byte[] and Byte[] arrays, Dates, BigDecimal and
  62. BigInteger types. In order to define bespoke type conversions for particular entity attribute, you can annotate a
  63. field or method with `@Convert` to specify your own implementation of `org.neo4j.ogm.typeconversion.AttributeConverter`.
  64. You can find out more about type conversions here: <<reference_programming-model_conversion,Custom Converters>>
  65. [[migration.4-0.date-format]]
  66. === Date Format Changes
  67. The default Date converter is <<reference:type-conversion:built-in,@DateString>>.
  68. SDN 3.x and earlier represented Dates as a String value consisting of the number of milliseconds since January 1, 1970, 00:00:00 GMT.
  69. If you are upgrading to SDN 4.x from these versions and your application used the default, then you need to annotate your `Date`
  70. properties with `@DateLong`.
  71. Moreover, the property values in the graph need to be converted to numbers.
  72. .Upgrade Date properties to numbers
  73. [source,cypher]
  74. ----
  75. MATCH (n:Foo) //All nodes which contain date properties to be migrated
  76. WHERE NOT HAS(n.migrated)// Take the first 10k nodes that haven't been migrated yet
  77. WITH n LIMIT 10000
  78. SET n.dateProperty = toInt(n.dateProperty),n.migrated=1 //where dateProperty is the date with a String value to be migrated
  79. RETURN count(n); //Run until the statement returns zero records
  80. //Similar process to remove the migrated flag
  81. ----
  82. However, if your application already represented Dates as `@GraphProperty(propertyType = Long.class)` then simply changing this to
  83. `@DateLong` is sufficient.
  84. [[migration.4-0.indexing]]
  85. === Indexing
  86. The best way to retrieve start nodes for traversals and queries is by using Neo4j's integrated index facilities.
  87. SDN supports Index and Constraint management but differs in how it does this to previous versions.
  88. [[migration.4-0.obsolete-annotations]]
  89. === Obsolete Annotations
  90. The following annotations are no longer used, either because they are no longer needed, or cannot be supported via Cypher.
  91. * @GraphTraversal
  92. * @RelatedToVia
  93. * @RelatedTo
  94. * @TypeAlias
  95. * @Fetch
  96. [[migration.4-0.no-support]]
  97. === Features No Longer Supported
  98. Some features of the previous annotations have been dropped.
  99. Overriding @Property Types::
  100. Support for overriding property types via arguments to @Property has been dropped. If your attribute requires
  101. a non-default conversion to and from a database property, you can use a <<migration.4-0.custom_converters,Custom Converter>> instead.
  102. @Relationship enforceTargetType::
  103. In previous versions of Spring Data Neo4j, you would have to add an `enforceTargetType` attribute into every clashing
  104. `@Relationship` annotation. Thanks to changes in the underlying object-graph mapping mechanism, this is no longer
  105. necessary.
  106. .Clashing Relationship Types
  107. [source,java]
  108. ----
  109. @NodeEntity
  110. class Person {
  111. @Relationship(type="OWNS")
  112. private Car car;
  113. @Relationship(type="OWNS")
  114. private Pet pet;
  115. ...
  116. }
  117. ----
  118. Cross-store Persistence::
  119. Neo4j is dropping XA support and therefore SDN does not provide any capability for cross-store persistence
  120. TypeRepresentationStrategy::
  121. SDN 4 replaces the existing `TypeRepresentionStrategy` configuration with a straightforward convention based on simple class-names
  122. or entities using `@NodeEntity(label=...)`
  123. AspectJ Support::
  124. Support for AspectJ-based persistence has been removed from SDN 4 as the write-and-read-through approach only works with an integrated, embedded database, not Neo4j server. The performance improvements in SDN 4 should make their use as a performance optimisation unnecessary anyway.
  125. === Deprecation of Neo4jTemplate
  126. Users that rely on a direct interaction with the database should be using the Neo4j-OGM `Session` directly.
  127. `Neo4jTemplate` has been kept to give upgrading users a better experience.
  128. The `Neo4jTemplate` has been slimmed-down significantly for SDN 4. It contains the exact same methods as `Session`. In fact `Neo4jTemplate` is just a very thin wrapper with an ability to support SDN Exception Translation.
  129. Many of the operations are no longer needed or can be expressed with a straightforward Cypher query.
  130. If you do use `Neo4jTemplate`, then you should code against its `Neo4jOperations` interface instead of the template class.
  131. The following table shows the `Neo4jTemplate` functions that have been retained for version 4 of Spring Data Neo4j. In some cases the method names have changed but the same functionality is offered under the new version.
  132. [cols="1,1,2"]
  133. .Neo4j Template Method Migration
  134. |===
  135. |Old Method Name|New Method Name|Notes
  136. |`findOne`
  137. |`load`
  138. |Overloaded to take optional depth parameter
  139. |`findAll`
  140. |`loadAll`
  141. |Overloaded to take optional depth parameter, also now returns a `Collection` rather than a `Result`
  142. |`query`
  143. |`query`
  144. |Return type changed from `Result` to be `Iterable`
  145. |`save`
  146. |`save`
  147. |
  148. |`delete`
  149. |`delete`
  150. |
  151. |`count`
  152. |`count`
  153. |No longer defines generic type parameters
  154. |`findByIndexedValue`
  155. |`loadByProperty`
  156. |Indexes are not supported natively, but you can index node properties in your database setup and use this method to find by them
  157. |===
  158. To achieve the old `template.fetch(entity)` equivalent behaviour, you should call one of the load methods specifying the fetch depth as a parameter.
  159. It's also worth noting that `exec(GraphCallback)` and the `create...()` methods have been made obsolete by Cypher.
  160. Instead, you should now issue a Cypher query to the new `execute` method to create the nodes or relationships that you need.
  161. Dynamic labels, properties and relationship types are not supported as of this version, server extensions should be considered instead.
  162. ==== Built-In Query DSL Support
  163. Previous versions of SDN allowed you to use a DSL to generate Cypher queries. There are many different DSL
  164. libraries available and you're free to use which of these - or none - that you want. With Cypher changing on a regular
  165. basis, avoiding a DSL implementation in SDN means less ongoing maintenance and less likelihood of your code
  166. being incompatible with future versions of Neo4j.
  167. ==== Graph Traversal and Node/Relationship Manipulation
  168. These features cannot be supported by Cypher and have therefore been dropped from `Neo4jTemplate`.
  169. Please provide feedback on the new APIs of SDN 5 and the migration needs to spring-data-neo4j@neotechnology.com or via a https://jira.spring.io/browse/DATAGRAPH[JIRA issue]