File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubt on @OneToOne bi-directional Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubt on @OneToOne bi-directional" Watch "Doubt on @OneToOne bi-directional" New topic

Doubt on @OneToOne bi-directional

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

What happens when we do not say optional = "false" in the OneToOne definition as below @OneToOne(mappedBy="billingInfo", optional="false");

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!
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

The optional attribute is a hint used for schema generation. In the case we are talking about, the inverse (non-owning) side of a OneToOne association, my guess is that this attribute is ignored.
[ September 01, 2008: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
S Bhanage

Joined: Oct 28, 2009
Posts: 13

The default value of optional is "true"
which implies that property can take null values while persistence.

If we explicitely specifies optional = "false"
This means we do not want to persist 'Null' value for this perticular property.

You can refer EJB 3 spec for more details.
I agree. Here's the link:
subject: Doubt on @OneToOne bi-directional
It's not a secret anymore!