我有两张桌子:
CREATE TABLE [LeTYPE](
[LeNAME] [varchar](100) NOT NULL,
[Le_DESC] [varchar](500) NULL,
[LeFOR] [varchar](50) NOT NULL,
CONSTRAINT [PK_LeTYPE] PRIMARY KEY CLUSTERED
(
[LeNAME] ASC
)
)
CREATE TABLE [Le](
[SN] [int] IDENTITY(1,1) NOT NULL,
[LeNAME_FK] [varchar](100) NOT NULL,
[Le_SN] [int] NULL,
[LOWERRANGE] [float] NOT NULL,
[UPPERRANGE] [float] NOT NULL,
[Le_DESC] [varchar](500) NULL,
[COLOR] [varchar](45) NULL,
CONSTRAINT [Le_pk] PRIMARY KEY CLUSTERED
(
[SN] ASC
))
GO
ALTER TABLE [Le] WITH CHECK ADD CONSTRAINT [FK_Le_LeTYPE] FOREIGN KEY([LeNAME_FK])
REFERENCES [LeTYPE] ([LeNAME])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [Le] CHECK CONSTRAINT [FK_Le_LeTYPE]
GO
LETYPE 中的一个元组将有多个 LE。
netbeans 生成的 JPA 实体:
public class Letype implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 100)
@Column(nullable = false, length = 100)
private String Lename;
@Size(max = 500)
@Column(name = "Le_DESC", length = 500)
private String LeDesc;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 50)
@Column(nullable = false, length = 50)
private String Lefor;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "LenameFk", fetch = FetchType.LAZY)
private List<Le> LeList;
}
public class Le implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column(nullable = false)
private Integer sn;
@Column(name = "Le_SN")
private Integer LeSn;
@Basic(optional = false)
@NotNull
@Column(nullable = false)
private double lowerrange;
@Basic(optional = false)
@NotNull
@Column(nullable = false)
private double upperrange;
@Size(max = 500)
@Column(name = "Le_DESC", length = 500)
private String LeDesc;
@Size(max = 45)
@Column(length = 45)
private String color;
@JoinColumn(name = "LeNAME_FK", referencedColumnName = "LeNAME", nullable = false)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Letype LenameFk;
}
现在,我想要的是,如果我从 JSF 视图添加一个 LETYPE,我想同时添加多个 LE。
LETYPE
-LE1
-LE2
-LE3
netbean 生成的实体结构letypeList
与中乐而不是相反。我的数据库结构是错误的还是如何做对?