Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Creation of M-M-Relation/Association fails

Hi Michael,

What is the actual code you are running? (i.e. how do you get your entity manager, what does the code that persists your objects look like? how are you getting your transactions?)


Michael Simons wrote:

I've got an Entity class Product with a self-relation:
	/** Set of products this one is compatible with.*/
	@ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.REFRESH})
	private Set<Product> compatibleProducts = new HashSet<Product>();

Guess what happens when I add products to this set like this:
	public boolean addCompatibleProduct (Product product) {
		if (compatibleProducts == null)
			compatibleProducts = new HashSet<Product>();
		boolean added = compatibleProducts.add (product);
		if (added)
			product.addCompatibleProduct (this);
		return added;

If you said nothing, you've won. The only SQL that was generated is:
[EL Fine]: 2010-03-15
product SET jdo_version = ? WHERE ((product_id = ?) AND (jdo_version = ?))
	bind => [43, 30, 42]
[EL Fine]: 2010-03-15

What can I do to avoid this? Or is this a bug of EclipseLink?

Kind Regards, Michael
eclipselink-users mailing list

Back to the top