• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB 3.0 and manytomany, how to create

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic