Olá colegas bom dia!
Na minha aplicação estou usando Hibernate e necessitando de um mapeamento bidirecional… mais especifico o uso de lista para o one-to many…
Entrei na documentação online do Hibernate e olhei um exemplo la assim:
If you use a List (or other indexed collection) you need to set the key column of the foreign key to not null, and let Hibernate manage the association from the collections side to maintain the index of each element (making the other side virtually inverse by setting update=“false” and insert=“false”):
<class name="Person">
<id name="id"/>
...
<many-to-one name="address"
column="addressId"
not-null="true"
insert="false"
update="false"/>
</class>
<class name="Address">
<id name="id"/>
...
<list name="people">
<key column="addressId" not-null="true"/>
<list-index column="peopleIdx"/>
<one-to-many class="Person"/>
</list>
</class>
It is important that you define not-null=“true” on the element of the collection mapping if the underlying foreign key column is NOT NULL. Don’t only declare not-null=“true” on a possible nested element, but on the element.
Bom… a primeira coisa que eu queria saber é se preciso criar o campo “peopleIdx”, como ele deve ser e em que tabela ?
Outra coisa que não entendi muito bem é quando é citado em cima que o insert e o update devem ficar como false.
Valeu ai pessoal!
Um abraço e Bom dia ! 8)