I have a simple entity Configuration
, which has an ID and a String property.
@Data
@AllArgsConstructor
@NoArgsConstructor
@Wither
@Entity
@Table(name = "CONFIGURATION")
public class Configuration {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@Column(name = "CONFIG_OBJECT")
private String configItem1;
}
I have simple JPA repository
public interface ConfigurationRepository extends JpaRepository<Configuration, Long> {
}
And in a Cucumber test I try to access the field
final Configuration configuration = configurationRepository.getOne(1L);//id 1 exists
configuration.getConfigItem1(); //the exception is thrown here
But I'm getting this exception
could not initialize proxy [com.mk.myapp.model.Configuration#1] - no Session
I assume, that the property configItem1
is being lazily loaded, but why? I would expect this when I have some entitites in a relation, but why should a String property be lazily loaded?