It's possible to add a single element into a table without loading the table and the related elements. It's a GUI use case where the users adds a new element 'PrepaymentModel' without loading the big underlying table.
Annotation :
@Entity
@Table(name = "CUSTOMER_BEHAVIOUR")
@AttributeOverride(name = "id", column = @Column(name = "CUSTOMER_BEHAVIOUR_ID", nullable = false))
@SequenceGenerator(name = "SEQ", sequenceName = "S_CUSTOMER_BEHAVIOUR")
public class CustomerBehaviourModel extends A
{
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "PREPAYMENT_MODEL_MAP", joinColumns = joinColumn(name = "CUSTOMER_BEHAVIOUR_ID"), inverseJoinColumns = @JoinColumn(name = "PREPAYMENT_MODEL_ID"))
@MapKeyManyToMany(joinColumns = @JoinColumn(name = "ACCOUNT_ID", nullable = false))
private Map<Account, PrepaymentModel> prepaymentModels = new HashMap();
...
}
A possible solution would be mapping the JoinTable with a new Annotated class (somehow we need to cheat on the Id...)
@Table(PREPAYMENT_MODEL_MAP)
class JoinTableClass
{
... these two are the key
@Column("CUSTOMER_BEHAVIOUR_ID")
long parentId;
@Column("ACCOUNT_ID")
long accountId;
@Column("PREPAYMENT_MODEL_ID")
PrepaymentModel prepModel;
}
Somebody has a more elegant solution
Thanks for your help,
|