Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB

 
alan kent
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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???
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic