我最近一直致力于我的项目领域模型,其中一个NeoUser可以拥有多个NeoPost。每个Neopost都使用名为user的字段引用其所有者。 现在我注意到当我将Neopost设置为NeoUser.thisusersposts中的条目以及作为用户的NeoImage对象时,我得到递归关系和Stackoverflow错误。
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错误?非常感谢你。
答案 0 :(得分:0)
好吧,我找到了解决问题的方法。 经过数小时的调试,我通过使用Lombok注释排除NeoPost中的用户来消除哈希码中的循环引用:
// firebase access key
define( 'API_ACCESS_KEY', 'AAAAAG78XmM:APA91bFRHpzuEIgiQRmPUm4uRy8bygNGr1h2Oq3ydc5WtKbrfJA8NVAaGIAxbQELfcOWwN2OR4pf5NzSRuuWOYj_P-XXXXXXXX');
// target device 'fcm' id
$device[0]='JI8YHo7GEo:APA9-aGWOU3U3CXXXXXXXXXXX';
$device[1]='JI8YHo7GEo:APA9-aGWOU3U3CXXXXXXXXXXX';
$url = 'https://fcm.googleapis.com/fcm/send';
// "to": "e1w6hEbZn-8:APA91bEUIb2JewYCIiApsMu5JfI5Ak...", // for single device (insted of "registration_ids"=>"$device" )
$data = array("registration_ids" => $device, // for multiple devices
"notification" => array(
"title" => "Party Night",
"body" => "Invitation for pool party!",
"message"=>"Come at evening...",
'icon'=>'https://www.example.com/images/icon.png'
),
"data"=>array(
"name"=>"xyz",
'image'=>'https://www.example.com/images/minion.jpg'
)
);
$data_string = json_encode($data);
$headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' );
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL,$url );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);
$result = curl_exec($ch);