Salome HOME
Attribute DAO
[modules/gde.git] / projects / GDE_App / GDE-ejb / src / java / com / edf / gde / entities / AttributeGroup.java
index 3a068efd9098abd950eaeea03f52b77a5eb9650a..5fe68e6468e62494dff9652ce47fbeff799e998d 100644 (file)
@@ -38,6 +38,7 @@ import javax.xml.bind.annotation.XmlTransient;
     @NamedQuery(name = "AttributeGroup.findById", query = "SELECT a FROM AttributeGroup a WHERE a.id = :id")
 })
 public class AttributeGroup implements Serializable {
+
     private static final long serialVersionUID = 1L;
     @Id
     @Basic(optional = false)
@@ -46,7 +47,8 @@ public class AttributeGroup implements Serializable {
     @SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
     @Column(name = "id")
     private long id;
-    @OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, cascade = {CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REMOVE,CascadeType.REFRESH})
+    
+    @OneToMany (fetch = FetchType.EAGER, orphanRemoval = true, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH})
     private Collection<Attribute> attributeCollection;
 
     public AttributeGroup() {
@@ -76,28 +78,31 @@ public class AttributeGroup implements Serializable {
     public static AttributeGroup fromAttributeGroupTO(AttributeGroupTO agto) {
         AttributeGroup group = new AttributeGroup();
         group.id = agto.getId();
-        
-        group.attributeCollection = new ArrayList<>();
         Collection<AttributeTO> attributes = agto.getAttributeCollection();
-        for (AttributeTO ato : attributes) {
-            group.attributeCollection.add(Attribute.fromAttributeTO(ato));
+        if (attributes != null) {
+            group.attributeCollection = new ArrayList<>();
+            for (AttributeTO ato : attributes) {
+                group.attributeCollection.add(Attribute.fromAttributeTO(ato));
+            }
         }
-    
         return group;
     }
-    
+
     public AttributeGroupTO toAttributeGroupTO() {
         AttributeGroupTO agto = new AttributeGroupTO();
         agto.setId(this.id);
-        
+
         Collection<AttributeTO> atos = new ArrayList<>();
-        for (Attribute a : this.attributeCollection) {
-            atos.add(a.toAttributeTO());
+        if (attributeCollection != null) {
+            for (Attribute a : this.attributeCollection) {
+                atos.add(a.toAttributeTO());
+            }
+            agto.setAttributeCollection(atos);
         }
-        agto.setAttributeCollection(atos);
+
         return agto;
     }
-    
+
     @Override
     public String toString() {
         return "com.edf.gde.entities.AttributeGroup[ id=" + id + " ]";