Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363674 - FetchType.LAZY fails on @OneToOne within @Embeddable, gives null when accessed
Summary: FetchType.LAZY fails on @OneToOne within @Embeddable, gives null when accessed
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P2 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-14 02:20 EST by darren CLA
Modified: 2022-06-09 10:07 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description darren CLA 2011-11-14 02:20:12 EST
I have an @Embeddable with a @OneToOne relationship:

@Embeddable
public class GreenStar_ implements Serializable, IGreenStar
{
    private GreenStarOfficeProject officeProject;

    @OneToOne(fetch= FetchType.LAZY)
    public GreenStarOfficeProject getOfficeProject() {
        return officeProject;
    }

Which is used as:

@Entity
public class GreenStarActivity extends Activity implements IGreenStarElement
{
    private GreenStar_ greenStar;
    @Embedded
    public GreenStar_ getGreenStar() {
        return greenStar;
    }

   public GreenStarActivity(Element owner, GreenStarOfficeProject officeProject, String name) {
       super(owner, officeProject, name);
       greenStar = new GreenStar_(officeProject);
       init();
   }

When getOfficeProject() is accessed in the following transient method in a GreenStarActivity it returns as null (although it was clearly already set):

    @Transient
    @Override
    public boolean isPassed() {
        String $i = "isPassed";        
        boolean test = true;
        resetFailures();         
        if (getGreenStar()==null) {
            log_error($i,"getGreenStar()==null");
        }
        else if (getGreenStar().getOfficeProject()==null) { 
            log_error($i,"getGreenStar().getOfficeProject()==null");
        }
        BooleanValue redevelopment = getGreenStar().getOfficeProject().getV893_refurbishment_redevelopment();

I get a NullPointerException on trying to access a getter within the null OfficeProject object above.
(I can tell it is null already from the verbose logging, and the GreenStar_ object is clearly not null.)

However this works fine when the default FetchType.EAGER is used, it only fails for LAZY.

And it only occurs on the relationship within the @Embeddable.
Comment 1 darren CLA 2011-11-14 19:39:52 EST
Wrongly reported as for version 2.0.3, the correct version is Eclipse Persistence Services - 2.2.0.v20110202-r8913
Comment 2 Tom Ware CLA 2011-11-17 14:03:50 EST
I am wondering if this is somehow related to how we weave.  If so, changing your access type from PROPERTY to FIELD may provide a workaround.
Comment 3 Tom Ware CLA 2011-11-24 15:25:17 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:07:48 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink