Search code examples
javahibernatespring-mvcvaadin7spring-annotations

How to i configure hibernate annotation based relationship?


I have a table which name is "Pstn" and there is User table. Users does not have to use Pstn table. But some users can use it. So if a pstn has an user we want to see who is. How can i configure hibernate annotations?

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

java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column, missing id: user.firstName at com.vaadin.ui.Table.setVisibleColumns(Table.java:691)

User table:

    @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 Table:

    @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;

********************* UPDATED SOLUTION ****************

I replaced pstn bean field like above. I think it occured because of FetchType.EAGER-Lazy..

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

Solution

  • I replaced pstn bean field like above. I think it occured because of FetchType.EAGER-Lazy..

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