Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move output setting to device table #974

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import java.util.stream.Collectors;
import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
Expand All @@ -36,6 +38,8 @@
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.Type;
import org.opensmartgridplatform.domain.core.valueobjects.Address;
Expand Down Expand Up @@ -96,6 +100,15 @@ public class Device extends AbstractEntity {
@Type(type = "org.opensmartgridplatform.shared.hibernate.InetAddressUserType")
protected InetAddress networkAddress;

/**
* The output settings are only used in the ssld table but in the database it is linked to the
* Device Table.
*/
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
@CollectionTable(name = "device_output_setting", joinColumns = @JoinColumn(name = "device_id"))
protected List<DeviceOutputSetting> outputSettings = new ArrayList<>();

Comment on lines +103 to +111
Copy link
Member

@smvdheijden smvdheijden Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have an SSLD specific field in the generic device Entitiy. It would probably be better to change the relationship in the DB and change the foreign key to point to the ssld id (which should effectively be the same as the device id due to the inheritance relation between them)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True that would be better but that would be a big change in the data model.
This just fixes the application issues with the data model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a big change in the data model is needed. Setting ON DELETE CASCADE will probably also work?

/** Cell ID on a Base Transceiver Station. */
@Column private Integer cellId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import java.util.Map;
import java.util.TreeMap;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
Expand Down Expand Up @@ -56,11 +54,6 @@ public class Ssld extends Device {
@LazyCollection(LazyCollectionOption.FALSE)
private final List<Ean> eans = new ArrayList<>();

@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
@CollectionTable(name = "device_output_setting", joinColumns = @JoinColumn(name = "device_id"))
private List<DeviceOutputSetting> outputSettings = new ArrayList<>();

@OneToMany(
mappedBy = "device",
cascade = {CascadeType.MERGE, CascadeType.PERSIST},
Expand Down