This week's book giveaway is in the Programmer Certification forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I able to generate the schema but when I try to insert, I am getting the error com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'id' cannot be null. My Phone table primary key is a composite key consisting of phoneNumber and foreign key id.
The way I have the schema, I have id column in Phone table as both primary key and foreign key to Student table and its failing while trying to perform an insert. How can I get this to work? Below is from logs.
I just took a glance at all that code, I didnt go in the details but according to your hibernate logs ,
Hibernate: create table Phone (phoneNumber varchar(255) not null, color varchar(255), id integer not null, primary key (phoneNumber, id))
The table Phone is created with coloumn 'id' as not null , however when inserting a new record in the this table you are doing it like
Hibernate will be expecting that you specify an appropriate value for couloumn 'id' as well otherwise it will fail at the binding process like it is as seen in your logs below
5:09:29,367 DEBUG SQL:104 - insert into Phone (color, phoneNumber, id) values (?, ?, ?)
15:09:29,369 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - Black
15:09:29,370 TRACE BasicBinder:84 - binding parameter [2] as [VARCHAR] - 1111111111
15:09:29,371 TRACE BasicBinder:72 - binding parameter [3] as [INTEGER] - <null>
15:09:29,376 WARN SqlExceptionHelper:145 - SQL Error: 1048, SQLState: 23000
15:09:29,377 ERROR SqlExceptionHelper:147 - Column 'id' cannot be null
15:09:29,393 INFO AbstractBatchImpl:195 - HHH000010: On release of batch it still contained JDBC statements
Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Thanks for your reply but shouldn't id column value of Phone table be auto inserted from the student table id value? Its a foreign key to the student table too.
Hibernate: alter table Phone add index FK_aoj0eivd0ap3drxnoyk4xj10q (id), add constraint FK_aoj0eivd0ap3drxnoyk4xj10q foreign key (id) references Student (id)
I want all the inserts to happen from the student side and not from both sides. How do I make this happen?