Comments on: EJB 3.0 Persistence – ManyToMany relations or the objectification of the intersection table https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/ Friends of Oracle and Java Wed, 24 Jun 2015 09:59:44 +0000 hourly 1 http://wordpress.org/?v=4.2.2 By: Peter https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2752 Sat, 07 Jun 2008 08:00:43 +0000 http://technology.amis.nl/blog/?p=972#comment-2752 The refresh() exception is not a contradiction to the specification. Per the specification, the entity passed to the merge() method becomes unmanaged, and the method returns a new T entity that IS managed. For the example, the following code would be successful:

tx.begin();
jsf.setTitle(jsf.getTitle()+”?”);
jsf = libraryService.getEntityManager().merge(jsf);
libraryService.getEntityManager().refresh(jsf);
tx.commit();

Make sure you don’t lose managed objects through the merge() operation — or many methods could throw the same exception refresh() did.

–PE

]]>
By: mario kofler https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2751 Thu, 13 Dec 2007 14:10:23 +0000 http://technology.amis.nl/blog/?p=972#comment-2751 hello jim,

i believe he is doing this because he wants to have the possibility to delete the data in the join_table starting from both entities (author and book). if one would be mapped by the “mappedBy” parameter starting the deletion from this entity would not be possible because it is not the “owning” side of the relation.

]]>
By: Jim McCollom https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2750 Tue, 23 Oct 2007 15:43:08 +0000 http://technology.amis.nl/blog/?p=972#comment-2750 Great article. I was wondering why you mapped both of your classes with the @JoinTable annotation, instead of using the mappedBy parameter.
Like:
In Books.java:

@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(table = @Table(name = “als_authorships”), joinColumns = {
@JoinColumn(name = “bok_id”)
}, inverseJoinColumns = {
@JoinColumn(name = “atr_id”)
})
public Collection getAuthors() {
return this.authors;
}

And in Authors.java

@ManyToMany(mappedBy=”authors”, cascade=CascadeType.ALL)
public Collection getBooks() {
return this.books;
}

]]>
By: jeroen dijkmeijer https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2749 Wed, 03 Oct 2007 13:35:10 +0000 http://technology.amis.nl/blog/?p=972#comment-2749 Good article,
but i’m not sure whether the whole many-to-many mapping option in jpa is the right approach for use case like this, read my blog http://jdijkmeijer.blogspot.com/2007/10/many-to-many-jsf-solutions.html for some information and 2 short examples on how to implement it.
Jeroen.

]]>
By: Iner https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2748 Tue, 02 Oct 2007 20:21:26 +0000 http://technology.amis.nl/blog/?p=972#comment-2748 Hello,

Thanks for the article.
Having a bit of trouble though, you fill the tables with data from your als_data.sql.
Could you provide some code on how a fill up the book and the author, does the ‘ALS_AUTHORSHIPS’-table
get filled in some ‘magical’ way ? I mean we do not have an Entity-class for that table.
So how would I write the correct code for inserting the books – would like to do that from a small web-page.

seen some examples out there, but they are full with errors.

hope that you can provide som help.

regards, Iner

]]>
By: Thomas https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2747 Sun, 23 Sep 2007 13:02:01 +0000 http://technology.amis.nl/blog/?p=972#comment-2747 Good article :) I’m also wondering how to get the intersection table attribute Contributor Type.
An Author has contributed to many books (stored in the Collection books), but it doesn’t store if the author wrote the whole book or drew the illustrations. What is the best way to solve that?

]]>
By: Roger Allen https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2746 Thu, 15 Feb 2007 18:37:06 +0000 http://technology.amis.nl/blog/?p=972#comment-2746 I was just wondering how you would get to the intersection table attribute Contributor Type.

]]>
By: Lucas Jellema https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2745 Mon, 16 Oct 2006 08:01:37 +0000 http://technology.amis.nl/blog/?p=972#comment-2745 Good point. I was a bit sloppy when coding the example. Thanks for the correction.

Lucas

]]>
By: Chris https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2744 Thu, 22 Jun 2006 18:00:30 +0000 http://technology.amis.nl/blog/?p=972#comment-2744 Great writeup. One thing I’d like to mention though is the merge/refresh functionality. Refresh is only to be used on Managed entities, where as merge is used on detatched entities and will return the managed instance with the changes merged into it. So to avoid the exception, your code really should be:

managedJsf = libraryService.getEntityManager().merge(jsf);
libraryService.getEntityManager().refresh(managedJsf );

Though it might be better just to call find and then refresh on the returned entity.

Best Regards

]]>
By: John https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2743 Fri, 14 Apr 2006 02:43:41 +0000 http://technology.amis.nl/blog/?p=972#comment-2743 Very good articles you wrote. Thank you very much for sharing.

]]>
By: Lucas Jellema https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2742 Mon, 02 Jan 2006 16:11:44 +0000 http://technology.amis.nl/blog/?p=972#comment-2742 The ER Diagram in this article was created using Oracle Designer. The Server diagram showing the tables was done with Oracle JDeveloper. Thanks for your kind words!

regards,

Lucas

]]>
By: Marcello https://technology.amis.nl/2006/01/02/ejb-30-persistence-manytomany-relations-or-the-objectification-of-the-intersection-table/#comment-2741 Mon, 02 Jan 2006 11:11:07 +0000 http://technology.amis.nl/blog/?p=972#comment-2741 I am reading with interest your EJB3 articles. Thanks!
Which tool are you using to create the ER diagrams present in this article?

]]>