This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of Embeddable annotation

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, you can have Name class.
 
Ravi Kiran Savirigana
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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 Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jiafan Zhou
Ranch Hand
Posts: 193
Fedora Linux Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic