如何配置基于hibernate注释的关系?

时间:2017-02-06 09:28:11

标签: java hibernate spring-mvc vaadin7 spring-annotations

我有一张名为" Pstn"并且有用户表。用户不必使用Pstn表。但有些用户可以使用它。因此,如果pstn有用户,我们希望看到谁。如何配置hibernate注释?

 pstnBbkTable.setVisibleColumns(new Object[]{"pstn", "bbk", "user.firstName", "inReserve", "creationDate", "expireDate", "button"});

java.lang.IllegalArgumentException:Ids必须存在于Container中或作为生成的列,缺少id:user.firstName     在com.vaadin.ui.Table.setVisibleColumns(Table.java:691)

用户表:

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "user_Id")
    private long userId;

    @Column(name = "username", nullable = false)
    private String username;

    @Column(name = "password", nullable = false)
    private String password;

    @Column(name = "first_name", nullable = false)
    private String firstName;

    @Column(name = "last_name", nullable = false)
    private String lastName;

Pstn表:

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "pstn_Id")
    private long pstnId;

    @Column(name = "pstn")
    private String pstn;

    @Column(name = "bbk")
    private String bbk;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_Id")
    private User user;

*********************更新后的解决方案****************

我像上面一样替换了pstn bean字段。我认为这是因为FetchType.EAGER-Lazy ..

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_Id")
    private User owner;

1 个答案:

答案 0 :(得分:0)

我像上面一样替换了pstn bean字段。我认为这是因为FetchType.EAGER-Lazy ..

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user_Id")
private User owner;