File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB" Watch "EJB" New topic
Author

EJB

alan kent
Greenhorn

Joined: Jan 25, 2003
Posts: 19
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

Joined: Oct 11, 2000
Posts: 1134

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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: EJB