I wanted to create User and Role Entity class but the @Column annotation asks for a data source?

huangapple go评论85阅读模式
英文:

I wanted to create User and Role Entity class but the @Column annotation asks for a data source?

问题

对于我获取到的 @Column 名称,从 IntelliJ 中分配数据源,我已经设置了 h2 作为我的平台和数据库 URL。我不知道如何设置这个数据库源。

这是 User 实体类:

@Entity
@Table(name = "users")
public class User {

    @Id
    @Column(name = "user_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String username;
    private String password;
    private boolean enabled;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(
            name = "users_roles",
            joinColumns = @JoinColumn(name = "user_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id")
    )
    private Set<Role> roles = new HashSet<>(); 

    // GETTERS AND SETTERS
}

而这是 Role 实体类:

@Entity
@Table(name = "roles")
public class Role {

    @Id
    @Column(name = "role_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;

    // GETTERS AND SETTERS

}
英文:

For the @Column names I am getting, assign data source from IntelliJ, I have set up the h2 as my platform and database url. I don't know how to setup this database source.

This is the User Entity class,

@Entity
@Table(name = &quot;users&quot;)
public class User {

    @Id
    @Column(name = &quot;user_id&quot;)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String username;
    private String password;
    private boolean enabled;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(
            name = &quot;users_roles&quot;,
            joinColumns = @JoinColumn(name = &quot;user_id&quot;),
            inverseJoinColumns = @JoinColumn(name = &quot;role_id&quot;)
    )
    private Set&lt;Role&gt; roles = new HashSet&lt;&gt;(); 


and this is the Role entity class,

@Entity
@Table(name = &quot;roles&quot;)
public class Role {

    @Id
    @Column(name = &quot;role_id&quot;)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;

    // GETTERS AND SETTERS

}

答案1

得分: 0

你可以按照这里的描述在IntelliJ中配置数据库连接。

尽管如此,只有在你希望IntelliJ检查你在代码中输入的表名、列名、查询等是否正确时,才需要这样做。如果在IntelliJ中不设置数据源,不会以任何方式影响你的应用程序。

英文:

You can configure database connections in IntelliJ as described here.

That said you only need to do that if you want IntelliJ to check if table and column names, queries, etc. you put in your code are correct. Not setting datasource in IntelliJ will not affect your application in any way.

huangapple
  • 本文由 发表于 2020年8月25日 02:04:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63566368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定