This content has been marked as final.
Show 3 replies
-
1. Re: How do I use a primary key that is a foreign key to anot
dornus Sep 8, 2005 10:21 AM (in response to dornus)Is anyone able to answer this?
I have the following which is not working. I need to know the correct way of doing this.public class TableOne{ private int myId; // more variables, etc... @Id(generate = GeneratorType.AUTO) public int getMyId() { return myId; } public void setMyId( int myId ) { this.myId = myId; } // more getters and setters for misc variables etc... } public class TableTwo{ private TableOne myId; // more variables, etc... @Id(generate = GeneratorType.AUTO) //DOESN'T WORK @ManyToOne //DOESN'T WORK @JoinColumn(name = "myForeignId") //DOESN'T WORK public TableOne getMyId() { return myId; } public void setMyId( TableOne myId ) { this.myId = myId; } // more getters and setters for misc variables etc... }
-
2. Re: How do I use a primary key that is a foreign key to anot
epbernard Sep 8, 2005 11:32 AM (in response to dornus)@Id String myOtherEntityId; @ManyToOne @JoinColumn(insertable=false, updatable=false, name="myOtherEntityId") MyOtherEntity myOtherEntity;
-
3. Re: How do I use a primary key that is a foreign key to anot
dornus Sep 8, 2005 1:04 PM (in response to dornus)"epbernard" wrote:
@Id String myOtherEntityId; @ManyToOne @JoinColumn(insertable=false, updatable=false, name="myOtherEntityId") MyOtherEntity myOtherEntity;
Excellent! Thank you for the response. I modified the code to the following and it works.public class TableTwo{ private int myForeignId; private TableOne myId; // more variables, etc... @Id public int getMyForeignId() { return myForeignId; } public void setMyForeignId( int myForeignId ) { this.myForeignId = myForeignId; } @ManyToOne @JoinColumn(insertable=false, updatable=false, name="myForeignId") public TableOne getMyId() { return myId; } public void setMyId( TableOne myId ) { this.myId = myId; } // more getters and setters for misc variables etc... }