aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0 and manytomany, how to create Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 and manytomany, how to create" Watch "EJB 3.0 and manytomany, how to create" New topic
Author

EJB 3.0 and manytomany, how to create

ing erl
Greenhorn

Joined: Jan 27, 2006
Posts: 15
Hello,

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.

Found an example <a href="http://www.j3ltd.com/articles/ejbrels/EJBRelationships.htm</a rel="nofollow">" target="_blank">http://www.j3ltd.com/articles/ejbrels/EJBRelationships.htm[/url]
but the exmample crashes in more than one location.
The relationship is ;
Homes has many Persons, and a Person can have many Homes.
The tables are simple HOME has an 'ID' and a 'STREETADDRESS', PERSON has
an 'ID' and a 'NAME', a middle table is created HOMEPERSONS ( with PK from HOME and PK from PERSON). All tables are created.

There are 2 Entity-beans, Home and Person.

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.

best regards, i
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hello ing,

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.

Regards,
Shailesh


Shailesh Kini.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 and manytomany, how to create
 
Similar Threads
incomplete @JoinColumns
problem with @ManyToMany using MapKeyClass
ManyToMany: ternary Relationship
Still getting duplicate in JPA ManyToMany Entity Relationship
org hibernate PropertyAccessException