is there an example about jpacontainer manytomany on your site?
thank you
is there an example about jpacontainer manytomany on your site?
thank you
I got this working.
My domain class:
@Entity
public class Trader {
@Id
private long id;
private String name;
private String email;
@ManyToMany
private Set<Stock> stocks;
// getters/setters
}
@Entity
public class Stock {
@Id
private String symbol;
private String name;
@ManyToMany(mappedBy = "stocks")
private Set<Trader> traders;
// getters/setters
}
Now, when I want to create a new Stock which refers to particular Trader:
EntityItem<Stock> stockItem;
Item stockTableItem = newStocksTable.getItem(newStocksTable.getValue()); // newStocksTable is a Table
if( !stocks.containsId( stockTableItem.getItemProperty("symbol") ) ){ // stocks is a JPAContainer for stocks
final BeanItem<Stock> stockBeanItem = new BeanItem<Stock>(new Stock());
stockBeanItem.getItemProperty("symbol").setValue( stockTableItem.getItemProperty("symbol") );
stockBeanItem.getItemProperty("name").setValue( stockTableItem.getItemProperty("name") );
// you can see nothing about Set of traders here
stocks.addEntity(stockBeanItem.getBean());
}
stockItem = stocks.getItem( stockTableItem.getItemProperty("symbol").toString() );
Set<Stock> stockSet = (Set<Stock>) traderItem.getItemProperty("stocks").getValue(); // traderItem is an Item object of particular trafer
stockSet.add(stockItem.getEntity());
traderItem.getItemProperty("stocks").setValue(stockSet);
After that I got a new row in stock row in stock db table and a new linking in trader_stock db table.
Hope it helps!
thank for your reply.
my problem is, that i could not delete an Relation between these two entities.
and my first try was with a manytomany relation with association class, so that there is an association entity and the mappings are onetomany and manytoone.
but i have decided to start with a simpler way and tried manytomany mapping. but the problem is just the same. java.util.concurrentmodification exception or jpacontainer deletes nothing!
thank you!