Moin Leute.
Ich habe hier einen Fehler in meiner Vererbung und komme nicht auf die Lösung.
Meine Abstrakte Klasse.
Meine konkrete Klasse
Factory
Erstellen des Objektes und Zuweisung
Fehlermeldung in Eclipse
The method setSand(Sand) is undefined for the type ReefTankAbstract
Wieso soll ich laut Eclipse die Methoden in der Abstrakten Klasse anlegen ?
Ich dachte das beim erstellen des Objektes
mir ein Objekt der konkreten Klasse zurückgegeben wird. Das müsste dann alle Eigenschaften der abstrakten Klasse + die Eigenschaften der konkreten Klasse sein ??
Oder liege ich da falsch ?
Grüße und schon mal danke
Ich habe hier einen Fehler in meiner Vererbung und komme nicht auf die Lösung.
Meine Abstrakte Klasse.
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ReefTankAbstract {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "reefTankIDgenerator")
@SequenceGenerator(name = "reefTankIDgenerator", sequenceName = "reefTankIDSequenz", allocationSize = 10, initialValue = 10)
@Column(name = "reefTankid")
private long id;
@Column(name = "reefManufacturer")
private String rtManufacturer;
@Column(name = "reefManufacturerTyp")
private String rtManufacturerTyp;
@Column(name = "reefDescription")
private String rtDescription;
@Column(name = "reefCreatedOn")
private LocalDate rtCreatedOn;
@Column(name = "reefGrossVolume")
private double rtGrossVolume;
@Column(name = "reefNetVolume")
private double rtNetVolume;
@Column(name = "reefLenght")
private double rtLength;
@Column(name = "reefWidth")
private double rtWidth;
@Column(name = "reefHeight")
private double rtHeight;
@Column(name = "reefFillingQuantity")
private double rtFillingQuantity;
@OneToMany(mappedBy = "reefTankAbstract", cascade = CascadeType.ALL, orphanRemoval = true)
@Column(name = "reefMessureValues")
private List<Messung> messureWaterValues;
public ReefTankAbstract(long id, String rtManufacturer, String rtManufacturerTyp, String rtDescription,
LocalDate rtCreatedOn, double rtGrossVolume, double rtNetVolume, double rtLength, double rtWidth,
double rtHeight, double rtFillingQuantity, List<Messung> messureWaterValues) {
super();
this.id = id;
this.rtManufacturer = rtManufacturer;
this.rtManufacturerTyp = rtManufacturerTyp;
this.rtDescription = rtDescription;
this.rtCreatedOn = rtCreatedOn;
this.rtGrossVolume = rtGrossVolume;
this.rtNetVolume = rtNetVolume;
this.rtLength = rtLength;
this.rtWidth = rtWidth;
this.rtHeight = rtHeight;
this.rtFillingQuantity = rtFillingQuantity;
this.messureWaterValues = messureWaterValues;
}
public ReefTankAbstract() {
super();
}
// getter
// setter
Meine konkrete Klasse
Code:
@Entity
@Table(name = "reefTankOnlySandRocks")
public class ReefTankOnlySandRocks extends ReefTankAbstract {
@OneToOne(mappedBy = "reefTankOnlySandRocks", cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
private Sand sand;
@OneToOne(mappedBy = "reefTankOnlySandRocks", cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
private Rock rock;
public ReefTankOnlySandRocks(long id, String rtManufacturer, String rtManufacturerTyp, String rtDescription,
LocalDate rtCreatedOn, double rtGrossVolume, double rtNetVolume, double rtLength, double rtWidth,
double rtHeight, double rtFillingQuantity, List<Messung> messureWaterValues, Sand sand, Rock rock) {
super(id, rtManufacturer, rtManufacturerTyp, rtDescription, rtCreatedOn, rtGrossVolume, rtNetVolume, rtLength,
rtWidth, rtHeight, rtFillingQuantity, messureWaterValues);
this.sand = sand;
// this.rock = rock;
}
public ReefTankOnlySandRocks() {
// TODO Auto-generated constructor stub
}
Factory
Code:
public class ReefTankFactory {
public static ReefTankAbstract createReefTank(int itemID) {
ReefTankAbstract neTankAbstract = null;
if (itemID == 1) {
return new ReefTankOnlyDefault();
} else if (itemID == 2) {
return new ReefTankOnlySandRocks();
}
Code:
ReefTankAbstract reefTank = ReefTankFactory.createReefTank(cbAquariumTyp.getSelectionModel().getSelectedIndex());
// Hier der Fehler
reefTank.setSand(sand);
reefTank.setRock(rock);
sand.setReefTankAbstract(reefTank);
rock.setReefTankAbstract(reefTank);
Fehlermeldung in Eclipse
The method setSand(Sand) is undefined for the type ReefTankAbstract
Wieso soll ich laut Eclipse die Methoden in der Abstrakten Klasse anlegen ?
Ich dachte das beim erstellen des Objektes
Code:
ReefTankAbstract reefTank = ReefTankFactory.createReefTank(cbAquariumTyp.getSelectionModel().getSelectedIndex());
Oder liege ich da falsch ?
Grüße und schon mal danke