休眠 - 如何在保存时排除列

时间:2017-11-09 02:32:22

标签: java hibernate

我正在尝试在我的主表和子表中保存数据,这个调用my.domain.client.model.Employee emp = new Employee();创建一个包含对象wslog的select语句。这在数据库中不存在,并且导致错误,因为"无效的标识符"。我使用了transient,它仍然使用列来创建select语句。如何解决这个问题?

服务代码

    my.domain.client.model.Wslog wsLog = new Wslog();
    wsLog.setRecords_rcvd(getRecords_rcvd());
    wsLogRepository.save(wsLog);
    List<my.domain.client.model.Employee> empList = new ArrayList<my.domain.client.model.Employee>();
    for (my.domain.client.model.Employee emp : wsLog.getEmployees()) {
        my.domain.client.model.Employee emp = new Employee();            
        emp.setID(getEid());
        emp.setEname(getEname());
        empList.add(emp);
    }
    wsLog.setEmployees(empList);
    wsLogRepository.save(wsLog);

休眠模型

    WsLog(Primary)
    @Column(name = "logid") //has sequence
    private long logid;
    @Column(name = "totrecords")
    private long totrecords;
    @OneToMany(mappedBy = "emp") 
    private List<Emp> emplist;

    Emp(Child)
    @Column(name = "logid")
    private long logid;
    @Column(name = "eid")
    private Long eid;
    @Column(name = "ename")
    private String ename;
    @JoinColumn(name = "logid")
    @ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    private Wslog wslog;

0 个答案:

没有答案