All,
I am using Hibernate 3 with Oracle 9 database and am using Hibernate annotations. My problem is that I have to query a legacy database table that does not have a primary key. So I am trying to create a composite primary key out of several columns.
On reading the hibernate documentation at :
http://www.hibernate.org/hib_docs/annot ... e/#d0e1662
I found that this can be done using the @Embeddable annotation.
I tried that and it works only if I do not use any columns from the primary key class in the HQL. If I do use a column from the Primary key class a QuerySyntaxException exception is thrown.
My Mapping class is as follows:
Code:
@Entity
public class Address {
@EmbeddedId
private addressPK AddressKey;
@Column(name="DEPARTMENT")
private String department;
// more columns and their getters and setters
}
My Primary key class is as follows:
Code:
@Embeddable
public class AddressPK implements Serializable
{
private String building;
// more columns and their getters and setters
}
If the following HQL is used, it works:
Code:
from Address address where address.department='aaa'
If the following HQL is used, an Exception is thrown.
Code:
from Address address, AddressKey key where key.building='bb'
The exception thrown is as follows:
Code:
org.hibernate.hql.ast.QuerySyntaxException: AddressPK is not mapped [from test.Address address, AddressPK key where key.building='bb']
Another thing to mention is i have also created an enty for the primary key class in the hibernate.cfg.xml. So the mapping section now looks as follows:
Code:
<mapping class="test.PostalAddress"/>
<mapping class="test.PostalAddressPK"/>
Can anyone help? Is there something I am doing wrong?