I am currently reading the Apress-book 'Beginning EJB 3 application development, from novice to professional' and 'PRO EJB 3 API ...' from the same company. The examples are not that good in those two books, the authors were probably in a hurry and did not get everything into the books.
I am using jdk 1.5 and JBoss 4.2.1 if that should matter.
One thing that I cannot make happen, is how to Add an Item to a @ManyToMany - relationship. The key word is 'Add' here.
The Home-bean has the following statement (excluding all others ):
and Person has the following statement (excluding all others ):
The example states that we only need to do the following to add Home and a Person and that the middle-table is filled in some way. This is their example:
Am I doing something wrong, or are they missing something important at 'www.j3ltd.com' ? Hope that you can help me out here, cannot consider myself being able to handle this technique if I do not know how to insert a @ManyToMany.
Yes you are correct. The createTestData() method does not add the relation between Home and Person to the HomePersons table.
I haven't tried the sample yet so this is just my best guess. To be able to add a relation to the HomePersons table you will have to call addPerson(person) on your home object and setHome(home) on your person object. Once this is done you can call em.persist() and that should save the relationship to the HomePersons table. Please give it a try. I will try it on my end once I get some free time.
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss