4
respostas

Lazy é default?

Boa noite,

Estou em dúvida se LAZY é default como diz no vídeo aula. Pesquisei na documentação oficial do hibernate e me parece que lá diz que EAGER é o default. Abaixo coloco o trecho que fala do assunto e o link.

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. See the BytecodeEnhancement for additional information on fetching and on bytecode enhancement.

http://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html

Gratidão pela atenção.

4 respostas

Lazy é o default apenas para relacionamentos do tipo *ToMany. Para as outras propriedades, o default é eager.

Poderia por gentileza me passar o local onde cita que Lazy é default para *ToMany na documentação oficial? É que não achei essa informação lá.

Gratidão!

https://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#example.collection.mapping.annotations

Example 7.6. Elements of the mapping

Ele ta falando de um map, mas vale para sets, lists etc.

Como dito na aula e repassado pelo Alberto, somente em relações *ToMany a JPA assume o lazy por default.

Abraços!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software