package com.clusstre.connectionservice.domain;
import lombok.*;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.Version;
import org.neo4j.ogm.id.UuidStrategy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import java.time.LocalDateTime;
import java.util.UUID;
@NoArgsConstructor
@AllArgsConstructor
@Getter @Setter
public class BasicDomain {
@Id
@GeneratedValue(strategy = UuidStrategy.class)
private String id;
@Version
private Long version;
@CreatedDate
private LocalDateTime createdDate;
@LastModifiedDate
private LocalDateTime lastModifiedDate;
public BasicDomain(String id) {
this.id = id;
}
}
Entity 1 -
package com.clusstre.connectionservice.domain;
import com.sun.istack.internal.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.neo4j.ogm.annotation.*;
import org.neo4j.ogm.id.IdStrategy;
import org.neo4j.ogm.id.InternalIdStrategy;
import javax.annotation.Generated;
import javax.validation.constraints.NotEmpty;
import java.util.*;
@NodeEntity
@Getter @Setter @EqualsAndHashCode
@NoArgsConstructor
public class Clusstre extends BasicDomain{
@Index
@NotNull
@NotEmpty
private String uid;
@NotNull
@NotEmpty
private String name;
@Relationship(type = "CONNECTED", direction = Relationship.INCOMING)
private Set<Connection> connections = new HashSet<Connection>();
public Clusstre(String uid) {
this.uid = uid;
}
public Clusstre(String id, String uid, String name) {
super(id);
this.uid = uid;
this.name = name;
}
public Clusstre(String uid, String name) {
this.uid = uid;
this.name = name;
}
}
Node Entity 2 -
package com.clusstre.connectionservice.domain;
import lombok.*;
import org.neo4j.ogm.annotation.Index;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import java.util.*;
@NodeEntity
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class User extends BasicDomain{
@Index
private Long uid;
@Index
private String email;
@Relationship(type = "CONNECTED", direction = Relationship.OUTGOING)
private Set<Connection> connections = new HashSet<Connection>();
public User( String email) {
this.email = email;
}
public User(Long uid, String email) {
this.uid = uid;
this.email = email;
}
public User(String id, Long uid, String email) {
super(id);
this.uid = uid;
this.email = email;
}
}
package com.clusstre.connectionservice.domain;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.neo4j.ogm.annotation.*;
import org.neo4j.ogm.id.IdStrategy;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Objects;
@RelationshipEntity(type = "CONNECTED")
@Getter @Setter
public class Connection extends BasicDomain{
@StartNode
private Clusstre clusstre;
@EndNode
private User user;
@Property
private LocalDateTime connectionOn;
public Connection(Clusstre clusstre, User user) {
super();
this.clusstre = clusstre;
this.user = user;
this.connectionOn = java.time.LocalDateTime.now();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Connection)) return false;
Connection that = (Connection) o;
return getClusstre().equals(that.getClusstre()) &&
getUser().equals(that.getUser());
}
@Override
public int hashCode() {
return Objects.hash(getClusstre(), getUser());
}
}
First of all I am persisting both @NodeEntity
classes then @RelationshipEntity
.
I can see connections in DB, but while fetching User & Clusstre node entity I cant fetch connections regarding both @NodeEntity
entities.
please suggest .