better mapping of paccomponent
This commit is contained in:
parent
85be33e6a1
commit
3b61da9c17
@ -10,7 +10,6 @@ import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityManager;
|
||||
@ -97,9 +96,11 @@ public class Pac extends AbstractEntity implements Serializable {
|
||||
pacComponents = new HashSet<PacComponent>();
|
||||
Date today = new Date();
|
||||
for (Component comp : basepac.getComponents()) {
|
||||
PacComponent pacComp = new PacComponent(basepac,
|
||||
comp.getBaseComponent(), this, comp.getDefaultQuantity(),
|
||||
today, null);
|
||||
PacComponent pacComp = new PacComponent();
|
||||
pacComp.setCreated(today);
|
||||
pacComp.setComponent(comp);
|
||||
pacComp.setPac(this);
|
||||
pacComp.setQuantity(comp.getDefaultQuantity());
|
||||
pacComponents.add(pacComp);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
@ -27,13 +28,11 @@ public class PacComponent implements Serializable {
|
||||
|
||||
@Id
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "basecomponent_id")
|
||||
private BaseComponent baseComponent;
|
||||
|
||||
@Id
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "basepacket_id")
|
||||
private BasePac basePac;
|
||||
@JoinColumns({
|
||||
@JoinColumn(name = "basecomponent_id"),
|
||||
@JoinColumn(name = "basepacket_id")
|
||||
})
|
||||
private Component component;
|
||||
|
||||
@Column(name = "quantity", columnDefinition = "integer")
|
||||
private int quantity;
|
||||
@ -46,33 +45,12 @@ public class PacComponent implements Serializable {
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date cancelled;
|
||||
|
||||
public PacComponent() {
|
||||
}
|
||||
|
||||
public PacComponent(BasePac basePac, BaseComponent baseComp, Pac pac,
|
||||
int quantity, Date created, Date cancelled) {
|
||||
this.basePac = basePac;
|
||||
this.pac = pac;
|
||||
this.baseComponent = baseComp;
|
||||
this.quantity = quantity;
|
||||
this.created = created;
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public BasePac getBasePac() {
|
||||
return basePac;
|
||||
}
|
||||
|
||||
public void setbasePac(BasePac basePac) {
|
||||
this.basePac = basePac;
|
||||
return getComponent().getBasePac();
|
||||
}
|
||||
|
||||
public BaseComponent getBaseComponent() {
|
||||
return baseComponent;
|
||||
}
|
||||
|
||||
public void setBaseComponent(BaseComponent baseComponent) {
|
||||
this.baseComponent = baseComponent;
|
||||
return getComponent().getBaseComponent();
|
||||
}
|
||||
|
||||
public Pac getPac() {
|
||||
@ -107,4 +85,12 @@ public class PacComponent implements Serializable {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public void setComponent(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,27 +3,25 @@ package de.hsadmin.mods.pac;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
|
||||
public class PacComponentId implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private long pac;
|
||||
private long basePac;
|
||||
private long baseComponent;
|
||||
private ComponentId component;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj != null && obj instanceof PacComponentId) {
|
||||
PacComponentId other = (PacComponentId) obj;
|
||||
return getPac() == other.getPac() && getBaseComponent() == other.getBaseComponent() && getBasePac() == other.getBasePac();
|
||||
return getPac() == other.getPac() && getComponent().equals(other.getComponent());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (new Long(getPac() ^ getBaseComponent() ^ getBasePac() % Integer.MAX_VALUE)).intValue();
|
||||
return (new Long(getPac() ^ component.hashCode() % Integer.MAX_VALUE)).intValue();
|
||||
}
|
||||
|
||||
public void setPac(long pacId) {
|
||||
@ -34,20 +32,12 @@ public class PacComponentId implements Serializable {
|
||||
return pac;
|
||||
}
|
||||
|
||||
public void setBaseComponent(long baseComponentId) {
|
||||
this.baseComponent = baseComponentId;
|
||||
public ComponentId getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public long getBaseComponent() {
|
||||
return baseComponent;
|
||||
}
|
||||
|
||||
public void setBasePac(long basePacId) {
|
||||
this.basePac = basePacId;
|
||||
}
|
||||
|
||||
public long getBasePac() {
|
||||
return basePac;
|
||||
public void setComponent(ComponentId component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -79,8 +79,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
||||
Component comp = (Component) cObj;
|
||||
PacComponent pacComponent = new PacComponent();
|
||||
BaseComponent baseComponent = comp.getBaseComponent();
|
||||
pacComponent.setBaseComponent(baseComponent);
|
||||
pacComponent.setbasePac(comp.getBasePac());
|
||||
pacComponent.setComponent(comp);
|
||||
pacComponent.setCreated(now);
|
||||
pacComponent.setPac(pac);
|
||||
String feature = baseComponent.getFeature();
|
||||
|
Loading…
Reference in New Issue
Block a user