diff --git a/hsarback/src/de/hsadmin/mods/pac/Pac.java b/hsarback/src/de/hsadmin/mods/pac/Pac.java index d37d996..398efaf 100644 --- a/hsarback/src/de/hsadmin/mods/pac/Pac.java +++ b/hsarback/src/de/hsadmin/mods/pac/Pac.java @@ -39,7 +39,7 @@ public class Pac extends AbstractEntity implements Serializable { @Id @GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen") - @Column(name = "packet_id") + @Column(name = "packet_id", columnDefinition = "integer") private long id; @Column(name = "packet_name", unique = true) diff --git a/hsarback/src/de/hsadmin/mods/pac/PacComponent.java b/hsarback/src/de/hsadmin/mods/pac/PacComponent.java index b5074dd..d57bf8c 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacComponent.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacComponent.java @@ -58,8 +58,17 @@ public class PacComponent { public PacComponent(BasePac basePac, BaseComponent baseComp, Pac pac, int quantity, Date created, Date cancelled) { this.basePac = basePac; + if (basePac != null) { + this.basePacId = basePac.id(); + } this.pac = pac; + if (pac != null) { + this.pacId = pac.id(); + } this.baseComponent = baseComp; + if (baseComponent != null) { + this.baseComponentId = baseComp.id(); + } this.quantity = quantity; this.created = created; this.cancelled = cancelled; @@ -71,6 +80,9 @@ public class PacComponent { public void setbasePac(BasePac basePac) { this.basePac = basePac; + if (basePac != null) { + this.basePacId = basePac.id(); + } } public BaseComponent getBaseComponent() { @@ -79,6 +91,9 @@ public class PacComponent { public void setBaseComponent(BaseComponent baseComponent) { this.baseComponent = baseComponent; + if (baseComponent != null) { + this.baseComponentId = baseComponent.id(); + } } public Pac getPac() { @@ -87,6 +102,9 @@ public class PacComponent { public void setPac(Pac pac) { this.pac = pac; + if (pac != null) { + this.pacId = pac.id(); + } } public int getQuantity() { diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java index cb0fddd..dcccd0c 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java @@ -26,9 +26,10 @@ public class PacModuleImpl extends AbstractModuleImpl { @Override public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException { - Date now = new Date(); EntityManager em = getTransaction().getEntityManager(); Pac pac = (Pac) newEntity; + Date now = new Date(); + pac.setCreated(now); BasePac basepac = pac.getBasepac(); if (basepac == null || basepac.getName() == null || basepac.getName().length() == 0) { throw new HSAdminException("basepac required"); @@ -38,8 +39,6 @@ public class PacModuleImpl extends AbstractModuleImpl { qBasepac.setParameter("valid", Boolean.TRUE); basepac = (BasePac) qBasepac.getSingleResult(); pac.setBasepac(basepac); - Query qComponents = em.createQuery("SELECT c FROM Components c WHERE c.basePacId = :basepac"); - qComponents.setParameter("basepac", basepac.id()); INetAddress curINetAddr = pac.getCurINetAddr(); if (curINetAddr == null || curINetAddr.getInetAddr() == null || curINetAddr.getInetAddr().length() == 0) { throw new HSAdminException("curinetaddr required"); @@ -63,7 +62,8 @@ public class PacModuleImpl extends AbstractModuleImpl { qHive.setParameter("name", hive.getName()); hive = (Hive) qHive.getSingleResult(); pac.setHive(hive); -// em.persist(newEntity); + Query qComponents = em.createQuery("SELECT c FROM Components c WHERE c.basePacId = :basepac"); + qComponents.setParameter("basepac", basepac.id()); List componentsList = qComponents.getResultList(); Set pacComponents = new HashSet(); for (Object cObj : componentsList) { @@ -74,7 +74,7 @@ public class PacModuleImpl extends AbstractModuleImpl { pacComponent.setCreated(now); pacComponent.setPac(pac); pacComponent.setQuantity(comp.getDefaultQuantity()); -// em.persist(pacComponent); + pacComponents.add(pacComponent); } pac.setPacComponents(pacComponents); return super.add(newEntity);