If I use cascading, hibernate does not create a table user.
But you can see in the output, that hibernate tries to create a table 'user'.
Is it because I want to create a user who has a many-to-one mapping instead of creating a constraint with a one-to-many mapping.
It is important for me to create a user, with a constraint, and not the reverse (a constraint with users). (see Main class).
Following error occured:
Code:
14:19:02,062 DEBUG SchemaExport:132 - drop table if exists USER
14:19:02,062 DEBUG SchemaExport:132 - drop table if exists CONSTRAINTS
14:19:02,062 DEBUG SchemaExport:149 - create table USER (
ID BIGINT NOT NULL AUTO_INCREMENT,
NAAM VARCHAR(255),
CONSTRAINT BIGINT not null,
primary key (ID)
)
14:19:02,078 ERROR SchemaExport:154 - Unsuccessful: create table USER (ID BIGINT NOT NULL AUTO_INCREMENT, NAAM VARCHAR(255), CONSTRAINT BIGINT not null, primary key (ID))
14:19:02,078 ERROR SchemaExport:155 - Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'BIGINT not null, primary key (ID))' at line 1"
14:19:02,078 DEBUG SchemaExport:149 - create table CONSTRAINTS (
ID BIGINT NOT NULL AUTO_INCREMENT,
primary key (ID)
)
14:19:02,109 DEBUG SchemaExport:149 - alter table USER add index (CONSTRAINT), add constraint FK27E3CB119101DD foreign key (CONSTRAINT) references CONSTRAINTS (ID)
14:19:02,109 ERROR SchemaExport:154 - Unsuccessful: alter table USER add index (CONSTRAINT), add constraint FK27E3CB119101DD foreign key (CONSTRAINT) references CONSTRAINTS (ID)
14:19:02,109 ERROR SchemaExport:155 - Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT), add constraint FK27E3CB119101DD foreign key (CONST"
14:19:02,109 INFO SchemaExport:160 - schema export complete
14:19:02,125 INFO DriverManagerConnectionProvider:143 - cleaning up connection pool: jdbc:mysql://127.0.0.1:3306/test3
Constraints of User1:
User: user2
User: user3
Hibernate: insert into CONSTRAINTS values ( )
Hibernate: insert into CONSTRAINTS values ( )
Hibernate: insert into USER (NAAM, CONSTRAINT) values (?, ?)
14:19:02,250 WARN JDBCExceptionReporter:38 - SQL Error: 1064, SQLState: 42000
14:19:02,250 ERROR JDBCExceptionReporter:46 - Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT) values ('user2', 2)' at line 1"
14:19:02,265 WARN JDBCExceptionReporter:38 - SQL Error: 1064, SQLState: 42000
14:19:02,265 ERROR JDBCExceptionReporter:46 - Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT) values ('user2', 2)' at line 1"
14:19:02,265 ERROR JDBCExceptionReporter:38 - could not insert: [User]
java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT) values ('user2', 2)' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1905)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)