Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring JPA实体一致性-如何处理?_Spring_Jpa_Transactions_Entity_Consistency - Fatal编程技术网

Spring JPA实体一致性-如何处理?

Spring JPA实体一致性-如何处理?,spring,jpa,transactions,entity,consistency,Spring,Jpa,Transactions,Entity,Consistency,假设我有实体:用户、组和通知 //User has field List<Group> groups and List<Notification> myNotifications. public class User { private List<Group> groups; private List<Notification> myNotifications; } //Group has field List<Notifi

假设我有实体:用户、组和通知

//User has field List<Group> groups and List<Notification> myNotifications.
public class User {
    private List<Group> groups;
    private List<Notification> myNotifications;
}

//Group has field List<Notification> notifications.
public class Group {
    private List<Notification> notifications;
}
//用户有字段列表组和列表通知。
公共类用户{
私人名单组;
私人名单通知;
}
//组具有字段列表通知。
公共课组{
私人名单通知;
}
现在,当用户创建他的帐户时,我将用户实体保存到数据库中,其中包含空的组列表。 然后,当用户创建或将被添加到一个组时,他希望向该组添加一些通知

创建并保存通知时,我希望将其保存到某些组通知列表和某些用户(通知创建者)通知列表中。 我不希望我的通知保存到一个或另一个列表中。我需要确保通知将同时保存到用户通知列表实体和组通知列表

我应该如何避免不一致

目前,我的服务的方法被注释为@Transactional(SpringTransaction),因为据说它提供了一致性。但我想知道这是否足够

提前谢谢

是的,足够了。我读过那篇文章:)谢谢@JBNizet