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?)

-Tom

Michael Simons wrote:
Hello,

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})
	@JoinTable(name="product_product_compatibility",
		joinColumns={@JoinColumn(name="prev_product_id")},
		inverseJoinColumns={@JoinColumn(name="next_product_id")})
	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
15:48:09.88--ClientSession(5978600)--Connection(23637841)--Thread(Thread[main,5,main])--UPDATE
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
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top