This is my entity:
public class PersonItem implements Serializable{
@Id
@Column(name=\"col1\")
private String guid;
@Column(name=\"col2\")
Entity graphs are meant to control which relationships (e.g. one-to-one, one-to-many, etc.) are loaded lazily or eagerly. They may not work for loading individual columns (it depends on the provider).
Hibernate has some support for this, but it is fairly difficult to get working, described here. However, they mention the following reticence towards this approach (which I whole-heartedly agree with):
Please note that this is mostly a marketing feature; optimizing row reads is much more important than optimization of column reads.
So I would not recommend going too far down this road until you've confirmed that this is indeed a bottleneck in your application (e.g. this kind of fetch tuning can be a symptom of premature optimization).
UPDATE:
As pointed out, JPA does leave it up to the provider as to whether or not simple columns (non-associations) are lazily fetched.
The EAGER strategy is a requirement on the persistence provider runtime that data must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime that data should be fetched lazily when it is first accessed. The implementation is permitted to eagerly fetch data for which the LAZY strategy hint has been specified. In particular, lazy fetching might only be available for Basic mappings for which property-based access is used.
Starting with Hibernate 5, official support for bytecode enhancement was added and this may allow for lazy attribute fetching.
From the latest Hibernate docs we have:
2.3.2
fetch - FetchType (defaults to EAGER)
Defines whether this attribute should be fetched eagerly or lazily. JPA says that EAGER is a requirement to the provider (Hibernate) that the value should be fetched when the owner is fetched, while LAZY is merely a hint that the value be fetched when the attribute is accessed. Hibernate ignores this setting for basic types unless you are using bytecode enhancement.
And this next snippet that describes the advantages of bytecode enhancement.
Lazy attribute loading
Think of this as partial loading support. Essentially you can tell Hibernate that only part(s) of an entity should be loaded upon fetching from the database and when the other part(s) should be loaded as well. Note that this is very much different from proxy-based idea of lazy loading which is entity-centric where the entity’s state is loaded at once as needed. With bytecode enhancement, individual attributes or groups of attributes are loaded as needed.