I have 3 classes plus id classes (weak example):
Group (table group...columns: group_id)
Person (table person...columns: group_id, person_id)
PersonId (personId, groupId)
Address (table address...columns: group_id, person_id, address_id)
AddressId (personId, groupId)
there are one to many Person for the Group class, and one to many Address for the Person class.
Group
Code:
[color=blue]private Set<Person> persons= new HashSet<Person>( 0 );
...
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "group")
public Set<Person> getPersons()
{
return this.persons;
}[/color]
Person
Code:
[color=blue]
Group group;
private Set<Address> addresses= new HashSet<Address>( 0 );
...
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "GROUP_ID", ...)
public Group getGroup()
{
return this.group;
}
...
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "person")
public Set<Address> getAddress()
{
return this.address;
}[/color]
PersonId
Code:
[color=blue]Integer groupId;
Integer personId;
@Column(name = "GROUP_ID", ...)
public Integer getGroupId()
{
return this.groupId;
}
@Column(name = "PERSON_ID", ...)
public Integer getPersonId()
{
return this.personId;
}[/color]
Address
Code:
[color=blue]
Person person;
...
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumns( {
@JoinColumn(name = "GROUP_ID",...),
@JoinColumn(name = "PERSON_ID",...) })
public TPal getPerson()
{
return this.person;
}[/color]
AddressId
Code:
[color=blue]Integer groupId;
Integer personId;
Integer addressId;
@Column(name = "GROUP_ID", ...)
public Integer getGroupId()
{
return this.groupId;
}
@Column(name = "PERSON_ID", ...)
public Integer getPersonId()
{
return this.personId;
}
@Column(name = "ADDRESS_ID", ...)
public Integer getAddressId()
{
return this.addressId;
}[/color]
I didn't show the obvious like @EmbeddedId, and some of the @AttributeOverride entries...
I have retrieved the object Group from the db.
Here is the following code to get down to the Address object(s)
Code:
[color=blue] Group group = ....
Set<Person> peeps = group.getPersons();
//-- fetch data from db is done here
Iterator<Person> pi = peeps.iterator();
while( pi.hasNext() )
{
Person person = pi.next();
Set<Address> addresses = person.getAddresses();
//-- Query returns nothing since the mapping key->params is
//-- totally wrong
Iterator<Address> ai = addresses.iterator();
...
}[/color]
so...basically....this is my query log output
where
address_.GROUP_ID=?
and address_.PERSON_ID=?
DEBUG NullableType - binding '11111' to parameter: 1
DEBUG NullableType - binding '99999' to parameter: 2
11111 is the PERSON_ID
and
99999 is the GROUP_ID
the key values in the peeps Set is in the order of person/group values. Debugging into hibernate code, I cannot see that it is doing any kind of mapping. It is simply doing a for loop on the key sets and adding that to the parameter list. It doesn't really appear to be mapping the key to the column at all.......
HELP!