Using:
Eclipse version: 3.1
Hibernate version: 3.1
Hibernate Synchronizer version: 3.1.1
I have mappings like this:
Assinantes:
Code:
<class
name="Assinante"
table="assinantes"
>
<id
name="Id"
type="long"
column="CODIGO"
>
<generator class="increment"/>
</id>
<property
name="Email"
column="EMAIL"
type="string"
not-null="true"
length="50"
/>
<set name="assinaturas"
inverse="true"
cascade="all-delete-orphan">
<key column="CODIGO_ASSINANTE"/>
<one-to-many class="Assinatura" />
</set>
</class>
Assinaturas
Code:
<class
name="Assinatura"
table="assinaturas"
>
<id
name="Id"
type="long"
column="CODIGO"
>
<generator class="increment"/>
</id>
<property
name="EdicaoInicial"
column="EDICAO_INICIAL"
type="integer"
not-null="true"
length="11"
/>
<property
name="EdicaoFinal"
column="EDICAO_FINAL"
type="integer"
not-null="true"
length="11"
/>
<many-to-one
name="assinante"
column="CODIGO_ASSINANTE"
class="Assinante"
/>
</class>
My tables:
Code:
Assinantes
+--------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+-------+
| CODIGO | int(20) unsigned | | PRI | 0 | |
| EMAIL | varchar(50) | | MUL | | |
+--------+------------------+------+-----+---------+-------+
Assinaturas
+------------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+-------+
| CODIGO | int(10) unsigned | | PRI | 0 | |
| CODIGO_ASSINANTE | int(10) unsigned | | MUL | 0 | |
| EDICAO_INICIAL | int(11) | | | 0 | |
| EDICAO_FINAL | int(11) | | | 0 | |
+------------------+------------------+------+-----+---------+-------+
The question is, how can i get the set assinaturas into the object Assinante? When i do this:
Code:
Assinante assinante = session.get(Assinante.class, new Long(2));
It just loads the properties from the Assinantes table, not the set from the Assinaturas table, then if i do:
Code:
Set assinaturas = assinante.getAssinaturas();
it returns null.
When i add a 'assinatura' to the 'assinante' like this:
Code:
Assinatura assinatura = new Assinatura();
assinatura.setEmail("email@blabla");
assinante.getAssinaturas.add(assinatura);
it inserts in the table right, i just cant get the set..