I have an entity bean that contain 2 list of the same entity:
Code:
public Class Toto {
@OneToMany()
public List<Customer> getNiceCustomers() {..}
@OneToMany()
public List<Customer> getBadCustomers() {..}
}
If I writte bean like previous one, when I try to add customers in my Toto, I add an exception:
Code:
16:44:34,094 WARN [JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
16:44:34,094 ERROR [JDBCExceptionReporter] Duplicate entry '0' for key 1
16:44:34,094 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert collection: [Toto.niceCustomers#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
In the DB I can see that only one table as been created for mapping the 2 collections.
To workaound that issue I need to explicitely declared JoinTable:
Code:
public Class Toto {
@OneToMany()
@JoinTable(name = "Toto_niceCustomer", joinColumns = { @JoinColumn(name = "toto_id") }, inverseJoinColumns = @JoinColumn(name = "position_id"))
public List<Customer> getNiceCustomers() {..}
@OneToMany()
@JoinTable(name = "Toto_BadCustomer", joinColumns = { @JoinColumn(name = "toto_id") }, inverseJoinColumns = @JoinColumn(name = "position_id"))
public List<Customer> getBadCustomers() {..}
}
Will it be possible that hibernate automatically create the 2 join tables ?
[/code]