英文:
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 = "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<>();
and this is the Role entity class,
@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
}
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论