I looked at the dependent object example. I updated to try to make the foriegn parent pk part of the childs primary key. So, I still need help with this please....
SQL executed by Hibernate
12:41:43,953 DEBUG SchemaExport:154 - create table Parent (
firstName varchar2(255) not null,
lastName varchar2(255) not null,
age number(10,0),
primary key (firstName, lastName)
)
12:41:45,046 DEBUG SchemaExport:154 - create table Child (
firstName varchar2(255) not null,
lastName varchar2(255) not null,
parenFirstName varchar2(255) not null,
parentLastName varchar2(255) not null,
primary key (firstName, lastName)
)
12:41:45,109 DEBUG SchemaExport:154 - alter table Child add constraint FK3E104FC157CBEB0 foreign key (parenFirstName, parentLastName) references Parent
12:41:45,140 INFO SchemaExport:166 - schema export complete
Child pojo
Code:
@Entity(access = AccessType.FIELD)
public class Child implements Serializable {
@Id(generate = GeneratorType.NONE)
public ChildPk id;
}
Child PKCode:
@DependentObject(access = AccessType.FIELD)
public class ChildPk implements Serializable {
String firstName;
String lastName;
@ManyToOne()
@JoinColumns ({
@JoinColumn(name="parentLastName", referencedColumnName = "lastName"),
@JoinColumn(name="parenFirstName", referencedColumnName = "firstName")
})
public Parent parent;
}
Parent PKCode:
@Entity(access = AccessType.FIELD)
public class Parent implements Serializable {
@Id
public ParentPk id;
public int age;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumns ({
@JoinColumn(name="parentLastName", referencedColumnName = "lastName"),
@JoinColumn(name="parenFirstName", referencedColumnName = "firstName")
})
public Set<Child> children;
}
[/code]