aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Use of Embeddable annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Use of Embeddable annotation" Watch "Use of Embeddable annotation" New topic
Author

Use of Embeddable annotation

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

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?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
For example, you can have Name class.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Ravi Kiran Savirigana
Greenhorn

Joined: Nov 24, 2008
Posts: 20
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..?)


Thanks,
Ravi
SCJP 5.0 | SCWCD 5.0
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

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

Joined: Sep 28, 2005
Posts: 192


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.


SCJP, SCJD, SCWCD, SCBCD, SCEA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use of Embeddable annotation