[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Primary key object mapping
MikeDougherty
do-not-reply at jboss.com
Tue Feb 27 14:29:09 EST 2007
Hello,
I have the following class structure:
| @Entity
| @Table(name="FOO")
| @IdClass(FooPK.class)
| public class Foo {
| private Long id;
| private String name;
| private String description;
| private List<FooBar> bars;
|
| @Id @Column(name="FOO_ID")
| public Long getId() {
| return id;
| }
| public void setId(Long id) {
| this.id = id;
| }
|
| @Id @Column(name="FOO_NAME")
| public String getName() {
| return name;
| }
| public void setName(String name) {
| this.name = name;
| }
|
| public static class FooPK {
| private Long id;
| private String name;
|
| @Id @Column(name="FOO_ID")
| public Long getId() {
| return id;
| }
| public void setId(Long id) {
| this.id = id;
| }
|
| @Id @Column(name="FOO_NAME")
| public String getName() {
| return name;
| }
| public void setName(String name) {
| this.name = name;
| }
| }
| }
|
|
| @Entity
| @Table(name="BAR")
| @IdClass(BarPK.class)
| public class Bar {
| private Long id;
| private String name;
| private String description;
|
| @Id @Column(name="BAR_ID")
| public Long getId() {
| return id;
| }
| public void setId(Long id) {
| this.id = id;
| }
|
| @Id @Column(name="BAR_NAME")
| public String getName() {
| return name;
| }
| public void setName(String name) {
| this.name = name;
| }
|
| public static class BarPK {
| private Long id;
| private String name;
|
| @Id @Column(name="BAR_ID")
| public Long getId() {
| return id;
| }
| public void setId(Long id) {
| this.id = id;
| }
|
| @Id @Column(name="BAR_NAME")
| public String getName() {
| return name;
| }
| public void setName(String name) {
| this.name = name;
| }
| }
| }
|
|
| @Entity
| @Table(name="FOO_BAR")
| @IdClass(FooBarPK.class)
| public class FooBar {
| private Foo foo;
| private Bar bar;
| private Date effectiveDate;
| private Date endDate;
|
| @Id @JoinColumn(name="FOO_ID")
| public Foo getFoo() {
| return foo;
| }
| @Id @JoinColumn(name="BAR_ID")
| public Bar getBar() {
| return bar;
| }
| @Id @Column(name="EFF_DATE")
| public Date getEffectiveDate() {
| return effectiveDate;
| }
|
| public static class FooBarPK {
| private Foo foo;
| private Bar bar;
| private Date effectiveDate;
|
| @Column(name="FOO_ID")
| public Foo getFoo() {
| return foo;
| }
| @Column(name="BAR_ID")
| public Bar getBar() {
| return bar;
| }
| @Column(name="EFF_DATE")
| public Date getEffectiveDate() {
| return effectiveDate;
| }
| }
| }
|
The question I have relates to the FooBar class. The table behind it has FOO_ID and BAR_ID columns as part of the primary key. But I can't seem to figure out how to map these column values to appropriate Foo.id and Bar.id values. Any ideas on how I might be able to do this?
Thanks for your help.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4023249#4023249
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4023249
More information about the jboss-user
mailing list