• 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

entity bean and multiple tables

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic