I have a couple of weeks starting with hibernate.
I have this code database
| TABLE A |
-------------------------------
idA integer not null (PK) |
name varchar(45) not null |
lastname varchar(45) not null |
| TABLE B |
-------------------------------
idB integer not null (PK) |
name varchar(45) not null |
lastname varchar(45) not null |
| TABLE A_B |
-------------------------------
idA integer not null (PK) |
idB integer not null (PK) |
and these are my entities in java
@Entity
public class A{
@Id
private int id;
@Column
private String name;
@Column
private String lastName;
@ManyToMany(cascade={CascadeType.ALL})
@JoinTable(name="A_B", joinColumns={@JoinColumn(name="idA")}, inverseJoinColumns={@JoinColumn(name="idB")})
private List<B> ManyB;
//Getter and Setters
}
@Entity
public class B{
@Id
private int id;
@Column
private String name;
@Column
private String lastName;
@ManyToMany(mappedBy="ManyB", cascade={CascadeType.ALL})
private List<A> ManyA;
//Getter and Setters
}
I have 2 objects with many to many relationship and I have created the database in an intermediate table to make it in one to many relationship. I have several questions about this.
1 -. To add a record in the A_B table only lets me when I add objects B in the list declared in class A, if I do it the other way around, from class A by adding objects B I add in table A but not the A_B table.
. 2 - How do I delete or modify a record in the table A_B without having to delete or modify objects in Table A or B.
. 3 - When you get a list of all objects, for example I get the class A, I Returns a list and it contains A, and make an infinite recursively toString, this affects performance in memory or program?
Thanks attentive to your comments.