users@glassfish.java.net

JPA Fetch Type Lazy Causes Null Pointer?

From: <glassfish_at_javadesktop.org>
Date: Thu, 25 Feb 2010 10:52:13 PST

I have a simple entity which uses FetchType.Lazy.

[code]
import javax.persistence.FetchType;
...
...
public class FileContent implements Serializable {

@Id
private Long fid;

@Basic(fetch = FetchType.LAZY)
@Lob
private String contents;

...
..
public String getContents() {
  return contents;
}
}
[/code]


During run time the object behaves as expected for the majority of its purposes (sets work and data is inserted into the database appropriately). And the contents of the file are never loaded into memory. However - -
Later on; When I attempt to use this object (for example through a series of gets)

Similar to this:
getMainObject().getFileContent().getContents();

I receive a null pointer exception. If I remove @Basic Mapping and the corresponding FetchType.LAZY, all works well.

I'm probably doing something incorrect here. Most of my access is done through POJOs which wrap Local EJBs.

Any tips or thoughts are appreciated
Thanks alot!
[Message sent by forum member 'hoffman462' (HoffmanDanielG_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=388760