i have next situation. 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 parameters table/class donation. 2 classes entities. , use spring+hibernate. question if correctly initiate class donation created in constructor of project class? think using new operator inside spring smells bad. maybe there way task? - create class/table filled table/class. maybe separate parameters 2 classes , not use 1 constructor initiate classes? use setters of donation class? if have many parameters, many setters need use((( hmm((
i think using new operator inside spring smells bad.
not really. but, anyway, shouldn't use new
in @entity
class , whole model layer. instead of should move new
service layer, because looks business logic in entity class.
returning question: should better reconsider app architecture. said, new
operator shouldn't used inside model layer , @entity
classes. creating new bean, looks logic action. move action @service
class , use @repository
dao access basic operations on persistence objects. dao support , handle @onetoone
annotation without writing new
in entity beans.
helpful link: effective pattern data access jpa
Comments
Post a Comment