Help: Multiple simple foreign key annotations for Hibernate [message #627971] |
Thu, 23 September 2010 08:08 |
Robert Messages: 14 Registered: September 2010 |
Junior Member |
|
|
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 08:13] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02844 seconds