Hello !!
I am new in JPA / ObjectDB development and I have many questions:
3. Object relationship
I try to create a 1->n relation (EBVerlag is 1 and EBUser is n) between two tables:
Table "EBVerlag":
@Entity(name="VERLAG") public class EBVerlag extends Pojo implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany (fetch=FetchType.LAZY,cascade=CascadeType.ALL, mappedBy="VERLAG_ID") private List<EBUser> users;
Table "EBUser":
@Entity(name="USER") public class EBUser extends Pojo implements Serializable{ private static final long serialVersionUID = 1L; @Id @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ManyToOne @Column(name = "VERLAG_ID") @JoinColumn(name="VERLAG_ID", insertable=false, updatable=false) private EBVerlag verlag=null;
3.1. Please take a look at column names and tell me, if I did the connection between these two tables correctly or not.
3.2. Both POJO-s extend my own class "Pojo.class" which looks like this:
public class Pojo { private transient boolean changed=false; public boolean isChanged(){ return changed; } public void setChanged(boolean changed){ this.changed = changed; }
...as you can see, I tried to manage changes inside of the tables by the hand. So let's say: if I call a set-method of my POJO and the new value is different than the old value, then I call setChanged(true). Is there a better way to manage such changes (maybe automatically?). Please consider that I cannot use Spring or similar, because the test-project works inside of GWT-context.