Neo4j рекурсивный в DM - PullRequest
0 голосов
/ 21 мая 2018

Недавно я работал над моей моделью домена для проекта, в котором один NeoUser может иметь несколько NeoPosts.Каждый Neopost ссылается на своего владельца с полем под названием user.Теперь я заметил, что когда я устанавливаю Neopost как запись в NeoUser.thisusersposts, а также в NeoImage Object как пользователь, я получаю рекурсивное отношение и ошибку Stackoverflow.

Модель, которую я пытаюсь достичь, должнавыглядеть примерно так: enter image description here

NeoPost:

@Id
@GeneratedValue
Long postId;

@NotNull
@NotBlank
@Size(min = 1, max = 600)
String question;

/**
 * Images that are involved in that post
 */
@NotEmpty
@Relationship(type = "STARES", direction = Relationship.OUTGOING)
Set<Neoimage> neoimageSet = new HashSet<>();

/**
 * User that made this post
 */
@Relationship(type = "WAS_CREATED_BY", direction = Relationship.OUTGOING)
NeoUser user;


/**
 * Users that somehow in a way possible described in Userinteractiontype enum
 * with this current post.
 */
@Relationship(type = "INTERACTED_WITH", direction = Relationship.INCOMING)
Set<NeoInteraction> incomingInteractions = new HashSet<>();

NeoUser:

 @Id
@GeneratedValue
Long nodeId;

@Size(min = 2, max = 20, message = "Username length has to be between 2 and 20 characters.")
@Property(name = "user")
String username;

//Relationships / Interactions that were initiated by this user with image of another user
@Relationship(type = "INTERACTED_WITH", direction = Relationship.OUTGOING)
Set<NeoInteraction> outgoingInteraction = new HashSet<>();

//Posts that this user created
@Relationship(type = "OWNS", direction = Relationship.OUTGOING)
Set<NeoPost> thisusersposts = new HashSet<>();

@Relationship(type = "SUBSCRIBED", direction = Relationship.OUTGOING)
Set<NeoUser> usersubscriptions = new HashSet<>();

Что я сейчас спрашиваю:

Есть ли какая-то аннотация, которая предотвращает эту рекурсивность и, следовательно, ошибку Stackoverflow?Большое вам спасибо.

1 Ответ

0 голосов
/ 23 мая 2018

Ну, я нашел решение своей проблемы.После нескольких часов отладки я удалил циклическую ссылку в хеш-коде, исключив пользователя из NeoPost с помощью аннотации Lombok:

@EqualsAndHashCode(exclude = "user")
...