Pretty childish question, but I'm confused. I use Hibernate. He also creates tables. There is an entity user, there is an entity session. One user can have many sessions.
public class Session { @Id @Column(name = "id") @GeneratedValue() private long id; @Column(name = "token") private String token; @ManyToOne(fetch = FetchType.LAZY) private User user; } public class User { @Id @Column(name = "id") @GeneratedValue private long id; @Column(name = "name", nullable = false) private String name; @OneToMany(fetch = FetchType.LAZY) private List<Session> sessions; } Actually what's wrong. I want this structure to be generated in the database:
Users(id, name) Sessions(id, token, userId) In general, then it happened. And even filled correctly. But additionally, another table is generated, which remains empty. With test creation and user login:
Table Users
Sessions Table
UserSessions table
Can someone chew me what's what? I basically understand why creating such a table at all. One user may (actually, no, but the hibernate does not know this) theoretically several sessions, and at the same time several users may have one session, ala space saving + database integrity. But why is it not filled then?
In order to understand both cases, how to make it (the UserSessions table) fill in and remove this userId from the Sessions table is interesting; and vice versa, how to remove the UserSessions table, leaving userId. And how did it happen for me that an unused table is being created?


