Back Forum Reply New

JPA handles ManyToMany very inefficient... or am I wrong?

Ok, here is may problem...
Take the @ManyToMany example form jee5 javadoc:
   In Customer class:Code:   @ManyToMany   @JoinTable(name=quot;CUST_PHONESquot;)   public Set getPhones() { return phones; }   In PhoneNumber class:

Code: @ManyToMany(mappedBy=quot;phonesquot;)   public Set getCustomers() { return customers; }  Now say that you want to add another phone number to a customer:
The method would look like this:Code:
void associatePhone(PhoneNumber nr){

getPhones().add(nr);
nr.getCustomers.add(this);

}
The customers and phones set are of course LAZY loaded. What I find very inefficent is that in order to add a new association between a customer and a phone requires both sets to be loaded. This would mean 2 select queries that could retrive a LOT of data when all that actually needs to be done is simply adding a new entry in the JoinTable... I find this very inefficient...

Looking forward for your opinion...
¥
Back Forum Reply New