Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different Explainations abt Embeddable Classes

 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAP Spec Section 2.1.5 Page 23,

An entity may use other fine-grained classes to represent entity state. Instances of these classes, unlike
entity instances themselves, do not have persistent identity. Instead, they exist only as embedded objects
of the entity to which they belong. Such embedded objects belong strictly to their owning entity, and are
not sharable across persistent entities. Attempting to share an embedded object across entities has undefined
semantics. Because these objects have no persistent identity, they are typically mapped together
with the entity instance to which they belong


Which one is correct?

My thought is If both main entity and embeddable are persisted in same table we should have a way to share

And other question is , Can we persist embeddable object in a secondaryTable?


Thanks



EJB 3 in Action Section 8.3 Page 273 (Shaded area)

One of the most useful features of embeddable classes is that they can be shared
between entities. For example, our Address object could be embedded inside a
BillingInfo object to store billing addresses while still being used by the User
entity. The important thing to keep in mind is that the embeddable class definition
is shared in the OO world and not the actual data in the underlying relational tables.
As we noted, the embedded data is created/populated using the table mapping of
the entity class. However, this means that all the embeddable data must be
mapped to both the USERS and BILLING_INFO tables. In other words, both tables
must contain some mappable street, city, or zip columns.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And other question is , Can we persist embeddable object in a seco


EJB in Avtion
This is because EJB 3 does not allow embedded objects to be mapped
to a table different from the enclosing entity

Is so why we cant share embeddable class as per spec?
 
Juggy Obhi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chaminda,

Embeddable Classes can be shared in an OO Context, by that i mean both BillingInfo and User can have reference to the same Address Object. But when Address is actually mapped as @Embedded, the Address fileds are embedded separately in "both" BillingInfo Table and User Table and hence Address is not being shared by BillingInfo and User in the Relational World Context.

Now to answer the next question one should be good in EJB which i am not . Embeddable classes are embedded into the Owner table. You can not mark your entity with @Embedded and mark the same with @SecondaryTable. This do not make much sense to me. I would like to know the real concept behind keeping the Embeddable Entity in the same Table. Because ideally if Address is sharable in the OO Context why not in Relational Context?
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Juggy

Thanks for the reply,

But why spec says Embedded s are not shareable?

We have to rely on spec in this case ha?

Thanks
 
Juggy Obhi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks to me as an option to the Developer for accessing a separate object without the need of any "Join" Operation.

It is like if you have a huge Entity that goes in single table. You want to split/Fragment the bigger entity into more meaningful, easy to handle, (Sharable in the OO Context) Entities, which look separate but goes into the same table AND can be accessed without any Join Operation.


@Embedded forces the fields to be mapped/persisted to the Owner's Table, this is what makes Embedded Entities not sharable.
[ October 08, 2008: Message edited by: Juggy Obhi ]
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Both spec and book says about Object, not the table record. Its meaningful that table record cannot be shareable.

Lets take an example,



Is this sharing has been prohibited by spec? or have I mistaken

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic