• Post Reply Bookmark Topic Watch Topic
  • New Topic

entity bean and multiple tables

 
Arundhathi Menon
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!
1)Is it possible use an entity bean to represent two tables ? Or else if the field in one table is the foreign key of the other table, how do we get the beans to access the other fields ( am talkin abt mapping these nested queries in CMP)....
2)Is it possible to specify multiple table entries in the ejb-jar.xml file??
3)Have u come across the 'Could not create entity: Java.lang.NullPointerException'...how did u rectify it?
Thank u very much!!!
regards,
Menon
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Read about CMR (Container Managed Relationship) in Ed Roman's "Mastering EJB II"
2) You don't have to have one bean manage two tables. In this case you use CMR.
3) This is a very common exception and it's pretty clear that you have an uninitialized object there.
 
Appu Chan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arundhathi Menon:
Hi All!
1)Is it possible use an entity bean to represent two tables ? Or else if the field in one table is the foreign key of the other table, how do we get the beans to access the other fields ( am talkin abt mapping these nested queries in CMP)....
Yes. But the modality is dependent on specific application server vendors.
2)Is it possible to specify multiple table entries in the ejb-jar.xml file??
as above.
3)Have u come across the 'Could not create entity: Java.lang.NullPointerException'...how did u rectify it?
No
Thank u very much!!!
regards,
Menon
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)Is it possible use an entity bean to represent two tables ? Or else if the field in one table is the foreign key of the other table, how do we get the beans to access the other fields ( am talkin abt mapping these nested queries in CMP)....
You can map an Entity Bean across multiple tables if your Application Server supports it. However, this is not a standardized in the spec so it is non-portable.
2)Is it possible to specify multiple table entries in the ejb-jar.xml file??
Table entries are not specified in the ejb-jar.xml, only the abstract schema . Again, mapping across multiple tables is not a part of the spec so it is vendor dependent.
3)Have u come across the 'Could not create entity: Java.lang.NullPointerException'...how did u rectify it?
You will need to give much context for someone to help you on this one.
 
Nichole Kim
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This question maybe stupid, but I am really curious. So if an entity bean is mapped to multiple tables, it's not portable, why is that? Then if an entity bean is only mapped to one table, is it portable then? What's the reason behind this?
Thank you!
Nichole
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nichole Kim:
Hi,
This question maybe stupid, but I am really curious. So if an entity bean is mapped to multiple tables, it's not portable, why is that? Then if an entity bean is only mapped to one table, is it portable then? What's the reason behind this?
Thank you!
Nichole

Not all Application Servers support mapping an entity bean to multiple tables... therefore it is not guaranteed by the EJB Specification to be portable.
 
jim ke
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have an entity bean that is backed by more than one table, you can use Bean Managed Persistence instead of Container Managed Persistence to keep the object's portability between app servers.
It's likley that you'll want to write your own database table access logic anyway. You'd likely want to return something, ( message, etc..), when you have a parent table record with no corresponding child table record.
Peace,
jim
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!