Hibernate session.load not populating the arraylist property of the object

I have a problem using hibernate session.load function. I'm trying to get an object according to an id and it returns a nice object, but only primitive properties are set on the instance. I have a property with - it is a set (mapped to some other object), but it is not retrieved after the set, and the given field is null.

Does anyone know why sampling is not working as expected?



source to share

3 answers

Check out your selection strategy on ORM. Some of the properties can be set to be lazy rather than impatient. You may need to use Hibernate.Initialize after loading to populate all properties. Otherwise, you will have to change the ORM to use eager loading. Using annotaions, you should set the following property after the @entity attribute is disabled by default:

@ org.hibernate.annotations.Proxy (lazy = false)

However, this will download the entire file on checkout.



I think Set is lazy, if you want it to be full you can just call the receiver of that set and it will be loaded. If you want it to be loaded all the time, you can add

fetch = FetchType.EAGER



@OneToMany(mappedBy = "program", fetch=FetchType.EAGER)
private final List<Instruction> instructions = new ArrayList<Instruction>();


to display your entity



If you're not 100% sure you always want kids to be loaded, customization EAGER

can lead to unwanted effects. By default, JBoss Tools selects a value LAZY


Instead, you need to initialize the child association, which can be done in various ways:

  • Hibernate.initialize(myObject.getChildren())

  • Call size

    in associations:myObject.getChildren().size()

  • In the request, Criteria

    set FetchMode

    in the association JOIN

    :criteria.setFetchMode("children", FetchMode.JOIN);



All Articles