Fragment handling decreasing performance for large number of cmHandles
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / entities / FragmentEntity.java
index 6776528..2fdfa05 100755 (executable)
@@ -1,6 +1,7 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Pantheon.tech
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -44,7 +45,6 @@ import lombok.NoArgsConstructor;
 import lombok.Setter;
 import org.hibernate.annotations.Type;
 import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
 
 /**
  * Entity to store a fragment.
@@ -57,7 +57,7 @@ import org.hibernate.annotations.TypeDefs;
 @Builder
 @Entity
 @Table(name = "fragment")
-@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)})
+@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
 public class FragmentEntity implements Serializable {
 
     private static final long serialVersionUID = 7737669789097119667L;
@@ -70,6 +70,9 @@ public class FragmentEntity implements Serializable {
     @Column(columnDefinition = "text")
     private String xpath;
 
+    @Column(name = "parent_id")
+    private Long parentId;
+
     @Type(type = "jsonb")
     @Column(columnDefinition = "jsonb")
     private String attributes;
@@ -83,7 +86,7 @@ public class FragmentEntity implements Serializable {
     @JoinColumn(name = "anchor_id")
     private AnchorEntity anchor;
 
-    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
     @JoinColumn(name = "parent_id")
     private Set<FragmentEntity> childFragments;
 }