Hibernate外键为null

时间:2015-03-12 02:55:57

标签: hibernate

我有2个表,这里是实体。

现在,当我插入表时,employee_address表中的外键为null。正确插入其他值。

员工

@Entity
@Table(name="Employee")
//@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    private Timestamp created;

    @Temporal(TemporalType.DATE)
    private Date dob;

    private String email;

    @Column(name="FATHER_NAME")
    private String fatherName;

    private String firstname;

    private String lastname;

    private String married;

    @Column(name="MOTHER_NAME")
    private String motherName;

    private String telephone;

    //bi-directional many-to-one association to EmployeeAddress
    @OneToMany(mappedBy="employee", fetch=FetchType.EAGER, cascade = CascadeType.ALL)
    private List<EmployeeAddress> employeeAddresses;

EmployeeAddress

@Table(name="employee_address")
@NamedQuery(name="EmployeeAddress.findAll", query="SELECT e FROM EmployeeAddress e")
public class EmployeeAddress implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    private String apt_no;

    private String city;

    private String country;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="create_dt")
    private Date createDt;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="end_dt")
    private Date endDt;

    private String state;

    private String street_addr;

    private String zip_Code;

    //bi-directional many-to-one association to Employee
    @ManyToOne
    @JoinColumn(name="emp_id")
    private Employee employee;

0 个答案:

没有答案