• 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

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I insert and update in 2 tables using EJB??
For example, after inserting a row in table of employee (a new employee) ,
I want to update a table of company (the field "number of employees"
will be added 1).
I am using session bean and entity bean but it seens that each entity bean is related with only one table.
Is there some pattern for this case???
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ken,
Although I saw no mention of it in your post, I assume you are using CMP entity beans. Usually, you can only create CMP entity beans for a single table -- as you seem to have discovered.
In my opinion, you have two choices:
  • BMP entity beans
  • CMRs


  • I believe the second option is only possible when there is a foreign-key relationship between the tables -- in your case I presume the relevant tables are the EMPLOYEE and COMPANY tables. Also the second option -- CMRs (Container Managed Relationships) -- was introduced in version 2.0 of the EJB specification. Again, I saw no mention in your post regarding which EJB container you are using -- nor which EJB version it supports -- so I'll just suggest that you do some research on the two topics I've listed above.
    By the way, do people give you a hard time because your name is Kenny Rogers (like the singer) ?
    Good Luck,
    Avi.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic