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.
Code:
log4j:ERROR Could not find value for key log4j.appender.file
log4j:ERROR Could not instantiate appender named "file".
15:09:24,405 DEBUG BasicTypeRegistry:148 - Adding type registration boolean -> org.hibernate.type.BooleanType@24e2dae9
15:09:24,413 DEBUG BasicTypeRegistry:148 - Adding type registration boolean -> org.hibernate.type.BooleanType@24e2dae9
15:09:24,413 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@24e2dae9
15:09:24,423 DEBUG BasicTypeRegistry:148 - Adding type registration numeric_boolean -> org.hibernate.type.NumericBooleanType@5c74c3aa
15:09:24,427 DEBUG BasicTypeRegistry:148 - Adding type registration true_false -> org.hibernate.type.TrueFalseType@29edc073
15:09:24,429 DEBUG BasicTypeRegistry:148 - Adding type registration yes_no -> org.hibernate.type.YesNoType@6c121f1d
15:09:24,438 DEBUG BasicTypeRegistry:148 - Adding type registration byte -> org.hibernate.type.ByteType@37922221
15:09:24,438 DEBUG BasicTypeRegistry:148 - Adding type registration byte -> org.hibernate.type.ByteType@37922221
15:09:24,439 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Byte -> org.hibernate.type.ByteType@37922221
15:09:24,443 DEBUG BasicTypeRegistry:148 - Adding type registration character -> org.hibernate.type.CharacterType@2c64f6cd
15:09:24,444 DEBUG BasicTypeRegistry:148 - Adding type registration char -> org.hibernate.type.CharacterType@2c64f6cd
15:09:24,444 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Character -> org.hibernate.type.CharacterType@2c64f6cd
15:09:24,451 DEBUG BasicTypeRegistry:148 - Adding type registration short -> org.hibernate.type.ShortType@95c083
15:09:24,452 DEBUG BasicTypeRegistry:148 - Adding type registration short -> org.hibernate.type.ShortType@95c083
15:09:24,452 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Short -> org.hibernate.type.ShortType@95c083
15:09:24,458 DEBUG BasicTypeRegistry:148 - Adding type registration integer -> org.hibernate.type.IntegerType@687b6889
15:09:24,464 DEBUG BasicTypeRegistry:148 - Adding type registration int -> org.hibernate.type.IntegerType@687b6889
15:09:24,465 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Integer -> org.hibernate.type.IntegerType@687b6889
15:09:24,471 DEBUG BasicTypeRegistry:148 - Adding type registration long -> org.hibernate.type.LongType@5b6df84b
15:09:24,472 DEBUG BasicTypeRegistry:148 - Adding type registration long -> org.hibernate.type.LongType@5b6df84b
15:09:24,473 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Long -> org.hibernate.type.LongType@5b6df84b
15:09:24,480 DEBUG BasicTypeRegistry:148 - Adding type registration float -> org.hibernate.type.FloatType@2d66a22b
15:09:24,480 DEBUG BasicTypeRegistry:148 - Adding type registration float -> org.hibernate.type.FloatType@2d66a22b
15:09:24,481 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Float -> org.hibernate.type.FloatType@2d66a22b
15:09:24,486 DEBUG BasicTypeRegistry:148 - Adding type registration double -> org.hibernate.type.DoubleType@3daa57fb
15:09:24,487 DEBUG BasicTypeRegistry:148 - Adding type registration double -> org.hibernate.type.DoubleType@3daa57fb
15:09:24,487 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Double -> org.hibernate.type.DoubleType@3daa57fb
15:09:24,493 DEBUG BasicTypeRegistry:148 - Adding type registration big_decimal -> org.hibernate.type.BigDecimalType@4d630ab9
15:09:24,494 DEBUG BasicTypeRegistry:148 - Adding type registration java.math.BigDecimal -> org.hibernate.type.BigDecimalType@4d630ab9
15:09:24,499 DEBUG BasicTypeRegistry:148 - Adding type registration big_integer -> org.hibernate.type.BigIntegerType@790bc49d
15:09:24,499 DEBUG BasicTypeRegistry:148 - Adding type registration java.math.BigInteger -> org.hibernate.type.BigIntegerType@790bc49d
15:09:24,502 DEBUG BasicTypeRegistry:148 - Adding type registration string -> org.hibernate.type.StringType@4ac4aad3
15:09:24,503 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.String -> org.hibernate.type.StringType@4ac4aad3
15:09:24,506 DEBUG BasicTypeRegistry:148 - Adding type registration nstring -> org.hibernate.type.StringNVarcharType@78ce5b1c
15:09:24,508 DEBUG BasicTypeRegistry:148 - Adding type registration ncharacter -> org.hibernate.type.CharacterNCharType@86e293a
15:09:24,511 DEBUG BasicTypeRegistry:148 - Adding type registration url -> org.hibernate.type.UrlType@67e8a1f6
15:09:24,513 DEBUG BasicTypeRegistry:148 - Adding type registration java.net.URL -> org.hibernate.type.UrlType@67e8a1f6
15:09:24,520 DEBUG BasicTypeRegistry:148 - Adding type registration date -> org.hibernate.type.DateType@28d08633
15:09:24,521 DEBUG BasicTypeRegistry:148 - Adding type registration java.sql.Date -> org.hibernate.type.DateType@28d08633
15:09:24,526 DEBUG BasicTypeRegistry:148 - Adding type registration time -> org.hibernate.type.TimeType@1b543c88
15:09:24,527 DEBUG BasicTypeRegistry:148 - Adding type registration java.sql.Time -> org.hibernate.type.TimeType@1b543c88
15:09:24,532 DEBUG BasicTypeRegistry:148 - Adding type registration timestamp -> org.hibernate.type.TimestampType@5ca352a5
15:09:24,533 DEBUG BasicTypeRegistry:148 - Adding type registration java.sql.Timestamp -> org.hibernate.type.TimestampType@5ca352a5
15:09:24,534 DEBUG BasicTypeRegistry:148 - Adding type registration java.util.Date -> org.hibernate.type.TimestampType@5ca352a5
15:09:24,538 DEBUG BasicTypeRegistry:148 - Adding type registration dbtimestamp -> org.hibernate.type.DbTimestampType@21f3aa07
15:09:24,541 DEBUG BasicTypeRegistry:148 - Adding type registration calendar -> org.hibernate.type.CalendarType@42704baa
15:09:24,542 DEBUG BasicTypeRegistry:148 - Adding type registration java.util.Calendar -> org.hibernate.type.CalendarType@42704baa
15:09:24,543 DEBUG BasicTypeRegistry:148 - Adding type registration java.util.GregorianCalendar -> org.hibernate.type.CalendarType@42704baa
15:09:24,545 DEBUG BasicTypeRegistry:148 - Adding type registration calendar_date -> org.hibernate.type.CalendarDateType@65b4fad5
15:09:24,548 DEBUG BasicTypeRegistry:148 - Adding type registration locale -> org.hibernate.type.LocaleType@4a0c68c3
15:09:24,549 DEBUG BasicTypeRegistry:148 - Adding type registration java.util.Locale -> org.hibernate.type.LocaleType@4a0c68c3
15:09:24,552 DEBUG BasicTypeRegistry:148 - Adding type registration currency -> org.hibernate.type.CurrencyType@1cc7b00c
15:09:24,553 DEBUG BasicTypeRegistry:148 - Adding type registration java.util.Currency -> org.hibernate.type.CurrencyType@1cc7b00c
15:09:24,557 DEBUG BasicTypeRegistry:148 - Adding type registration timezone -> org.hibernate.type.TimeZoneType@7ddf5a8f
15:09:24,558 DEBUG BasicTypeRegistry:148 - Adding type registration java.util.TimeZone -> org.hibernate.type.TimeZoneType@7ddf5a8f
15:09:24,561 DEBUG BasicTypeRegistry:148 - Adding type registration class -> org.hibernate.type.ClassType@7e80fa6f
15:09:24,562 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Class -> org.hibernate.type.ClassType@7e80fa6f
15:09:24,568 DEBUG BasicTypeRegistry:148 - Adding type registration uuid-binary -> org.hibernate.type.UUIDBinaryType@485329c5
15:09:24,569 DEBUG BasicTypeRegistry:148 - Adding type registration java.util.UUID -> org.hibernate.type.UUIDBinaryType@485329c5
15:09:24,571 DEBUG BasicTypeRegistry:148 - Adding type registration uuid-char -> org.hibernate.type.UUIDCharType@31f26605
15:09:24,574 DEBUG BasicTypeRegistry:148 - Adding type registration pg-uuid -> org.hibernate.type.PostgresUUIDType@26544ec1
15:09:24,578 DEBUG BasicTypeRegistry:148 - Adding type registration binary -> org.hibernate.type.BinaryType@6b4da8f4
15:09:24,578 DEBUG BasicTypeRegistry:148 - Adding type registration byte[] -> org.hibernate.type.BinaryType@6b4da8f4
15:09:24,579 DEBUG BasicTypeRegistry:148 - Adding type registration [B -> org.hibernate.type.BinaryType@6b4da8f4
15:09:24,583 DEBUG BasicTypeRegistry:148 - Adding type registration wrapper-binary -> org.hibernate.type.WrapperBinaryType@39d85f79
15:09:24,583 DEBUG BasicTypeRegistry:148 - Adding type registration Byte[] -> org.hibernate.type.WrapperBinaryType@39d85f79
15:09:24,584 DEBUG BasicTypeRegistry:148 - Adding type registration [Ljava.lang.Byte; -> org.hibernate.type.WrapperBinaryType@39d85f79
15:09:24,587 DEBUG BasicTypeRegistry:148 - Adding type registration image -> org.hibernate.type.ImageType@33c282a1
15:09:24,590 DEBUG BasicTypeRegistry:148 - Adding type registration characters -> org.hibernate.type.CharArrayType@77d80e6d
15:09:24,591 DEBUG BasicTypeRegistry:148 - Adding type registration char[] -> org.hibernate.type.CharArrayType@77d80e6d
15:09:24,592 DEBUG BasicTypeRegistry:148 - Adding type registration [C -> org.hibernate.type.CharArrayType@77d80e6d
15:09:24,597 DEBUG BasicTypeRegistry:148 - Adding type registration wrapper-characters -> org.hibernate.type.CharacterArrayType@4a4e79f1
15:09:24,598 DEBUG BasicTypeRegistry:148 - Adding type registration [Ljava.lang.Character; -> org.hibernate.type.CharacterArrayType@4a4e79f1
15:09:24,598 DEBUG BasicTypeRegistry:148 - Adding type registration Character[] -> org.hibernate.type.CharacterArrayType@4a4e79f1
15:09:24,602 DEBUG BasicTypeRegistry:148 - Adding type registration text -> org.hibernate.type.TextType@79dfc547
15:09:24,605 DEBUG BasicTypeRegistry:148 - Adding type registration ntext -> org.hibernate.type.NTextType@2911a3a4
15:09:24,620 DEBUG BasicTypeRegistry:148 - Adding type registration blob -> org.hibernate.type.BlobType@1bc74f37
15:09:24,620 DEBUG BasicTypeRegistry:148 - Adding type registration java.sql.Blob -> org.hibernate.type.BlobType@1bc74f37
15:09:24,622 DEBUG BasicTypeRegistry:148 - Adding type registration materialized_blob -> org.hibernate.type.MaterializedBlobType@7a3570b0
15:09:24,639 DEBUG BasicTypeRegistry:148 - Adding type registration clob -> org.hibernate.type.ClobType@690da5eb
15:09:24,640 DEBUG BasicTypeRegistry:148 - Adding type registration java.sql.Clob -> org.hibernate.type.ClobType@690da5eb
15:09:24,652 DEBUG BasicTypeRegistry:148 - Adding type registration nclob -> org.hibernate.type.NClobType@24a4e2e3
15:09:24,652 DEBUG BasicTypeRegistry:148 - Adding type registration java.sql.NClob -> org.hibernate.type.NClobType@24a4e2e3
15:09:24,654 DEBUG BasicTypeRegistry:148 - Adding type registration materialized_clob -> org.hibernate.type.MaterializedClobType@3934f69a
15:09:24,656 DEBUG BasicTypeRegistry:148 - Adding type registration materialized_nclob -> org.hibernate.type.MaterializedNClobType@26fd68b1
15:09:24,660 DEBUG BasicTypeRegistry:148 - Adding type registration serializable -> org.hibernate.type.SerializableType@2321ab80
15:09:24,669 DEBUG BasicTypeRegistry:148 - Adding type registration object -> org.hibernate.type.ObjectType@2cb0ce8f
15:09:24,670 DEBUG BasicTypeRegistry:148 - Adding type registration java.lang.Object -> org.hibernate.type.ObjectType@2cb0ce8f
15:09:24,672 DEBUG BasicTypeRegistry:148 - Adding type registration imm_date -> org.hibernate.type.AdaptedImmutableType@42a9c09e
15:09:24,673 DEBUG BasicTypeRegistry:148 - Adding type registration imm_time -> org.hibernate.type.AdaptedImmutableType@16a4e743
15:09:24,673 DEBUG BasicTypeRegistry:148 - Adding type registration imm_timestamp -> org.hibernate.type.AdaptedImmutableType@244aeb52
15:09:24,674 DEBUG BasicTypeRegistry:148 - Adding type registration imm_dbtimestamp -> org.hibernate.type.AdaptedImmutableType@329f671b
15:09:24,674 DEBUG BasicTypeRegistry:148 - Adding type registration imm_calendar -> org.hibernate.type.AdaptedImmutableType@7f2a3793
15:09:24,675 DEBUG BasicTypeRegistry:148 - Adding type registration imm_calendar_date -> org.hibernate.type.AdaptedImmutableType@2ca6d51e
15:09:24,676 DEBUG BasicTypeRegistry:148 - Adding type registration imm_binary -> org.hibernate.type.AdaptedImmutableType@7cf1bb78
15:09:24,676 DEBUG BasicTypeRegistry:148 - Adding type registration imm_serializable -> org.hibernate.type.AdaptedImmutableType@624b035d
15:09:24,743 INFO Version:37 - HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
15:09:24,765 INFO Version:41 - HHH000412: Hibernate Core {4.2.2.Final}
15:09:24,771 INFO Environment:239 - HHH000206: hibernate.properties not found
15:09:24,808 INFO Environment:342 - HHH000021: Bytecode provider name : javassist
15:09:24,890 INFO Configuration:1985 - HHH000043: Configuring from resource: hibernate.cfg.xml
15:09:24,891 INFO Configuration:2004 - HHH000040: Configuration resource: hibernate.cfg.xml
15:09:25,080 WARN DTDEntityResolver:74 - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
15:09:25,189 INFO Configuration:2126 - HHH000041: Configured SessionFactory: null
15:09:25,380 INFO DriverManagerConnectionProviderImpl:98 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
15:09:25,404 INFO DriverManagerConnectionProviderImpl:134 - HHH000115: Hibernate connection pool size: 1
15:09:25,404 INFO DriverManagerConnectionProviderImpl:137 - HHH000006: Autocommit mode: false
15:09:25,405 INFO DriverManagerConnectionProviderImpl:151 - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/test]
15:09:25,406 INFO DriverManagerConnectionProviderImpl:156 - HHH000046: Connection properties: {user=user, password=****}
15:09:26,535 INFO Dialect:130 - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
15:09:27,310 WARN RootClass:288 - HHH000038: Composite-id class does not override equals(): PhonePK
15:09:27,311 WARN RootClass:289 - HHH000039: Composite-id class does not override hashCode(): PhonePK
15:09:27,329 INFO TransactionFactoryInitiator:68 - HHH000399: Using default transaction strategy (direct JDBC transactions)
15:09:27,354 INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
15:09:27,424 TRACE TypeFactory:71 - Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@25e222e
15:09:28,196 INFO SchemaExport:343 - HHH000227: Running hbm2ddl schema export
15:09:28,208 DEBUG SQL:104 - alter table Phone drop foreign key FK_aoj0eivd0ap3drxnoyk4xj10q
15:09:28,240 DEBUG SQL:104 - drop table if exists Phone
15:09:28,267 DEBUG SQL:104 - drop table if exists Student
15:09:28,279 DEBUG SQL:104 - create table Phone (phoneNumber varchar(255) not null, color varchar(255), id integer not null, primary key (phoneNumber, id))
15:09:28,415 DEBUG SQL:104 - create table Student (id integer not null auto_increment, fName varchar(255), lName varchar(255), mname varchar(255), primary key (id))
15:09:28,503 DEBUG SQL:104 - alter table Phone add index FK_aoj0eivd0ap3drxnoyk4xj10q (id), add constraint FK_aoj0eivd0ap3drxnoyk4xj10q foreign key (id) references Student (id)
15:09:28,749 INFO SchemaExport:405 - HHH000230: Schema export complete
15:09:29,118 DEBUG SQL:104 - insert into Student (fName, lName, mname) values (?, ?, ?)
15:09:29,192 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - Bob
15:09:29,195 TRACE BasicBinder:84 - binding parameter [2] as [VARCHAR] - Buster
15:09:29,195 TRACE BasicBinder:72 - binding parameter [3] as [VARCHAR] - <null>
15:09:29,283 DEBUG SQL:104 - select phone_.phoneNumber, phone_.id, phone_.color as color2_0_ from Phone phone_ where phone_.phoneNumber=? and phone_.id=?
15:09:29,285 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - 1111111111
15:09:29,287 TRACE BasicBinder:72 - binding parameter [2] as [INTEGER] - <null>
15:09:29,324 DEBUG SQL:104 - select phone_.phoneNumber, phone_.id, phone_.color as color2_0_ from Phone phone_ where phone_.phoneNumber=? and phone_.id=?
15:09:29,326 TRACE BasicBinder:84 - binding parameter [1] as [VARCHAR] - 2222222222
15:09:29,326 TRACE BasicBinder:72 - binding parameter [2] as [INTEGER] - <null>
15: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
org.hibernate.exception.ConstraintViolationException: could not execute statement
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:74)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3067)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at Main.main(Main.java:48)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'id' cannot be null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
... 14 more