Hibernate Lazy Property

0

Witam,
mam problem z działaniem Lazy property w Hibernate już tłumacze dlaczego uważam, że nie działa:
Mapowanie:

@Entity
@Access(AccessType.PROPERTY)
public class SomeEntity {

	private Long id;

	private String name;

	private String note;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	**@Basic(fetch = FetchType.LAZY)**
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}
}

Kod wołający

SomeEntity find = em.getReference(SomeEntity.class, 1L);

System.out.println(find.getName());
System.out.println(find.getNote());

Generuje mi SQL na wszystkie kolumny czyli id,name i note. A spodziewam się, że pójdą 2 sql'e pierwszy bez note a drugi tylko na note. CO robię źle?

Instrumentacja - działa bo jak dekompiluje kod to widze wstawki hibernate

    <plugin>
            <groupId>org.hibernate.orm.tooling</groupId>
            <artifactId>hibernate-enhance-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>

1

from the specification of JPA they say that even if you use annotate a property to be fetched lazily, this is not guaranteed to be applied, so the properties may or may not be loaded lazily (depends on the implementer of JPA), however if you specify that you should fetch them Eagerly then the JPA implementer must load them eagerly.

Bottom line: @basic(fetch = FetchType.LAZY) may or may not work, depends on the JPA implementer.

https://docs.oracle.com/javaee/6/api/javax/persistence/FetchType.html

LOB jest lazy domyślnie bo dużo może zajmować ...

1 użytkowników online, w tym zalogowanych: 0, gości: 1