I have the next situation. I have POJO class:
@Entity
@Table(name="project")
public class Project {
public Donation donation;
public Project() {}
public Project(int param1, int param2 ...) {
...//other field initialisied
donation = new Donation(param1, param2);
}
//methods
@OneToOne
@JoinColumn(name = "donation_project_id")
public Donation getDonation() {
return donation;
}
}
public void setDonation(Donation donation) {
this.donation = donation;
}
}
Donation class:
@Entity
@Table(name="donation")
public class Donation {
public Donation() {}
public DonationLogic(int param1, int param2) {
//initialisation
}
//other methods
}
Project table/class relays some parameters to another table/class Donation. Two classes are Entities. And I use Spring+Hibernate. My question is if I correctly initiate class Donation which is created in constructor of Project class? I think using new operator inside Spring smells bad. Maybe there is another way to do this task? - create class/table that is filled from another table/class. Maybe separate parameters for two classes and not use one constructor to initiate to classes? But use setters of Donation class? However if I have many parameters, many setters I will need to use((( Hmm((