Help: Multiple simple foreign key annotations for Hibernate [message #627971] |
Thu, 23 September 2010 04:08  |
Eclipse User |
|
|
|
If I have a MySQL database with an Equipment table, a Tool table, and a Hand-Held Tool table (for instance) like this:
(foreign keys are listed for this table)
Equipment Columns:
int pkEquipment
varchar20 nameoftool
Equipment foreign keys:
Tool pkTool
Hand-Held Tool pkHHTool
(these two tables let's say they are just primary keys)
Tool Columns:
int pkTool
Hand-Held Tools Columns:
int pkHHTool
Can anyone explain how to annotate the two foreign keys for the equipment class and seeing the other two classes (in case they have annotation elements in reverse) would be nice as well. Here is the class code so far:
@Entity(name="Equipment")
public class Equipment {
@Id //primary key
@Column(name = "EQUIPMENT_ID", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private int equipmentId;
@Column(name="nameoftool", nullable=false, length=25)
private String nameoftool;
...
// foreign key annotations go here
...
}
@Entity(name="Tool")
public class Tool {
@Id //primary key
@Column(name = "TOOL_ID",nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private int toolId;
...
// any supporting annotation for equipment table? (im guessing no)
...
}
@Entity(name="Hand-Held Tool")
public class HHTool {
@Id //primary key
@Column(name = "HHTOOL_ID",nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private int hhtoolId;
...
// any supporting annotation for equipment table? (im guessing no)
...
}
[Updated on: Thu, 23 September 2010 04:13] by Moderator
|
|
|
Re: Help: Multiple simple foreign key annotations for Hibernate [message #628021 is a reply to message #627971] |
Thu, 23 September 2010 04:48  |
Eclipse User |
|
|
|
You should ask a hibernate/jpa forum (hibernate.org). JPA implementation
@Eclipse is eclipse.rt.eclipselink
Tom
Am 23.09.10 10:08, schrieb Robert:
> If I have a MySQL database with an Equipment table, a Tool table, and a
> Hand-Held Tool table (for instance) like this:
>
> (foreign keys are listed for this table)
> Equipment Columns: Equipment foreign keys
> int pkEquipment Tool pkTool
> varchar20 nameoftool Hand-Held Tool pkHHTool
>
> (these two tables let's say they dont have any foreign keys)
> Tool Columns Hand-Held Tools Columns
> int pkTool int pkHHTool
>
> Can anyone explain how to annotate the two foreign keys for the
> equipment class and seeing the other two classes (in case they have
> annotation elements in reverse) would be nice as well. Here is the
> class code so far:
>
> @Entity(name="Equipment")
> public class Equipment {
> @Id //primary key
> @Column(name = "EQUIPMENT_ID", nullable = false)
> @GeneratedValue(strategy = GenerationType.AUTO)
> private int equipmentId;
> @Column(name="nameoftool", nullable=false, length=25)
> private String nameoftool;
>
> ...
> // foreign key annotations go here
> ...
> }
>
> @Entity(name="Tool")
> public class Tool {
> @Id //primary key
> @Column(name = "TOOL_ID",nullable = false)
> @GeneratedValue(strategy = GenerationType.AUTO)
> private int toolId;
>
> ...
> // any supporting annotation for equipment table? (im guessing no)
> ...
> }
>
> @Entity(name="Hand-Held Tool")
> public class HHTool {
> @Id //primary key
> @Column(name = "HHTOOL_ID",nullable = false)
> @GeneratedValue(strategy = GenerationType.AUTO)
> private int hhtoolId;
>
> ...
> // any supporting annotation for equipment table? (im guessing no)
> ...
> }
|
|
|
Powered by
FUDForum. Page generated in 0.43897 seconds