2011-06-22 154 views
0

我有兩個類Group和Permission,當我嘗試向Group添加新權限時,Group有一個Permission列表。我設置了新的權限列表併成功提交,但在數據庫沒有發生更新。我正在使用jpa 1(hibernate作爲提供程序)。我正在爲entitymanager(而不是jta)創建請求。我的託管bean請求範圍(a4j:keepalive),我嘗試使用它來查找錯誤但不成功。JPA manytomany單向映射更新問題

1-獲取用於編輯當前組爲選擇克選自G聯接取g.permissions其中g.id =:ID如果它從懶惰導致獲取許可列表的(as here

2-刷新從數據庫列表中的所有權限然後合併組。

public class GroupEditorBean extends AbstractGroupBean { 
    private static final long serialVersionUID = -7454051588934099916L; 



    @PostConstruct 
    public void init() { 
     this.group= groupAccessor.findGroup(Long.valueOf(getParameter("group"))); 
     perms = this.group.getPermIdList(); 
    } 


    public String save() { 
     if(group.isRoot()){ 
      addError("Root group can not be updated"); 
      return ""; 
     } 
     List<Permission> permissions= convertToPermission(perms); 
     this.group.setPermissions(permissions); 
     groupAccessor.merge(group); 
     logger.log(String.format("Updated group %s", group.getName()), "group", 
       Log.Severity.INFO); 

     return "modules/user/groups.xhtml"; 
    } 







@Entity 
@Table(name = "GROUPS") 
public class Group implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "GID") 
    private Long id; 



    @ManyToMany(cascade={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH}) 
    @JoinTable(name = "GROUP_PERMISSION", joinColumns = @JoinColumn(name = "GID"), inverseJoinColumns = @JoinColumn(name = "PID")) 
    private List<Permission> permissions; 





@Entity 
@Table(name = "PERMISSIONS") 
public class Permission implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "PID") 
    private Long id; 

    @NotNull 
    @Column(name = "READABLE_ID", unique = true) 
    private String readableId; 
+0

如果我設置權限清單和合並之前更新組它是成功的。但我認爲這是一個錯誤。 – ayengin

回答

0

JPA 1與孤兒實體有問題,並且JPA-1實現jar的hibernate有一些額外的錯誤。設置列表爲null解決了我的問題,我希望JPA-2解決了這個問題。