I am having problems retrieving data for objects that have a bi-directional many-to-many relationship. If I use Listto store entities, I cannot retrieve multiple amounts at the same time. If I change my code to use Set, I get a stackoverflow error.
Details:
- Spring 3.0.3
- Hibernate-core: 3.5.1-Final
- Hibernate annotations: 3.5.1-Final
- hibernate-common-annotations: 3.2.0-Final
- hibernate-entitymanager: 3.5.1-Final
- Mysql database
- Junit 4
The user has many bank accounts; A bank account can have many users.
User.java
@ManyToMany(fetch = FetchType.EAGER, mappedBy="user")
private List<BankAccount> bankAccounts = new ArrayList<BankAccount>();
BankAccount.java
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "user_bankaccount",
joinColumns = @JoinColumn(name="bank_account_id"),
inverseJoinColumns = @JoinColumn(name = "user_id")
)
private List<User> user = new ArrayList<User>();
DB Tables
Users
user_id PK
Bankaccount
bank_account_id PK
user_bankaccount
bank_account_id PK ( references bankaccount.bank_account_id )
user_id PK ( references user.user_id )
the questions
- (
getAllUsers) JUnit, . Set HashSet List ArrayList , stackoverflow.
, , libs, .