I have two table:
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
One tuple in LETYPE will have many LE.
JPA Entity generated by netbeans:
public class Letype implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@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;
}
Now, What I wanted was if I add a LETYPE from JSF view I would like to add multiple LE also at the same time.
LETYPE
-LE1
-LE2
-LE3
Do I need to set LenameFk manually in Le entity since I am getting *Cannot insert the value NULL into column 'LENAME_FK'*? Why won't it automatically take it from Le enityt?