Im trying to create table using hibernate, but I get sql syntax error and I dont know why.
User
@Entity
@Table(name="users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@ManyToMany
@JoinTable(name="user_role", joinColumns = @JoinColumn(name="user_id"),
inverseJoinColumns = @JoinColumn(name="role_id)"))
private Set<Role> roles;
}
Role
@Entity
@Table(name="role")
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
@ManyToMany(mappedBy="roles")
private Set<User> users;
}
application.properties
spring.datasource.url = jdbc:mysql://localhost/basket
spring.datasource.username = root
spring.datasource.password =
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = create
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000388: Unsuccessful: create table user_role (user_id bigint not null, role_id) bigint not null, primary key (user_id, role_id)))
org.hibernate.tool.hbm2ddl.SchemaUpdate : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') bigint not null, primary key (user_id, role_id)))' at line 1
org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000388: Unsuccessful: alter table user_role add constraint FK_75dvukqj0muwehqn7y8qi9j5c foreign key (role_id)) references role (id)
org.hibernate.tool.hbm2ddl.SchemaUpdate : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') references role (id)' at line 1
org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000388: Unsuccessful: alter table user_role add constraint FK_apcc8lxk2xnug8377fatvbn04 foreign key (user_id) references users (id)
org.hibernate.tool.hbm2ddl.SchemaUpdate : Table 'basket.user_role' doesn't exist
Im using MariaDB 10.1.16.
create table user_role (user_id bigint not null, role_id bigint not null, primary key (user_id, role_id))
It's like after every role id there is a one unnecessary parenthesis but i dont know where i made mistake and how to fix it. – crooked