Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Use of Embeddable annotation

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

I'm trying to fully understand this annotation. From what I read from the Pro EJB 3 book is that for an user entity when we have the address information in the user itself, then we could very well make it as a seperate entity and mark it as embedabble and use this entity in the user. But normally we model the aaddress class as a seperate entity as it will be a physical table representation in the database. So this example does not justifies to me the need for Embeddable. Can anyone here help me with a better example?
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, you can have Name class.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi...
What i think is you use @Embeddable annotation to designate persistent objects that need
not have an identity(something like a primary key in DB scenario) of their own. They are simply used as convenient data holders/groupings.(Am i correct..?)
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran Savirigana wrote:hi...
What i think is you use @Embeddable annotation to designate persistent objects that need
not have an identity(something like a primary key in DB scenario) of their own. They are simply used as convenient data holders/groupings.(Am i correct..?)



Yes, this looks like a valid point to me. But there is another scenario where in you use this annotation. When you have to represent an Id class....which looks totally in contrary to what you said (data holders/groupings not have an identity...). What I feel is the real use of this class is like reusable chunk of a POJO that I can use across multiple entities and override the defaults (using @AttributeOverrides...) as and when needed.
 
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But there is another scenario where in you use this annotation. When you have to represent an Id class....which looks totally in contrary to what you said (data holders/groupings not have an identity...). What I feel is the real use of this class is like reusable chunk of a POJO that I can use across multiple entities and override the defaults (using @AttributeOverrides...) as and when needed.


I think that the @Embeddable class itself is ignorant of whether it is used as Properties or Id. From this point of view, it is simply served as a data holders/groupings. How this grouping is used (either ID by @EmbeddedId or properties by @Embedded) is dependant on the "consumer" of the Embeddable class.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic