Primary Key class (@IdClass) used as object values and implies foreign key
--------------------------------------------------------------------------
Key: HHH-3791
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3791
Project: Hibernate Core
Issue Type: Improvement
Components: core, metamodel, query-hql
Reporter: Timothy Twelves
As per:
http://forums.hibernate.org/viewtopic.php?t=991417
Map primary key objects enforcing referential integrity without mapping the actual
object.
This ensures that there is no possibility for lazy loading and also becomes nice for
serialization and data transport.
{code:title=MyExample.java|borderStyle=solid}
@Entity
@IdClass(AccountPk.class)
class Account {
long accountNo;
PersonPk owner; // <---- here we refer many to one but using
PersonPk instead of Person
}
class AccountPk {
long accountNo;
}
class PersonPk {
int person;
}
@Entity
@IdClass(PersonPk.class)
class Person {
int id;
AccountPk primaryAccount;
Collection<AccountPk> accounts; // <---- here we have one to many but using
AccountPk instead of Account
}
{code}
The above example is insufficient as the PK object does not indicate its entity.
@PrimaryEntity and @PrimaryEntityCollection is used below as an example how this would be
marked appropriately.
{code:title=MyExample.java|borderStyle=solid}
@Entity
@IdClass(AccountPk.class)
class Account {
long accountNo;
@PrimaryEntity(entity=Person.class)
PersonPk owner;
}
class AccountPk {
long accountNo;
}
class PersonPk {
int person;
}
@Entity
@IdClass(PersonPk.class)
class Person {
int id;
AccountPk primaryAccount;
@PrimaryEntityCollection(entity=Person.class, primarykey=AccountPk.class)
Collection<AccountPk> accounts;
}
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira