Results 1 to 2 of 2
  1. #1
    Nomula is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Unable to insert rows

    I able to generate the schema but when I try to insert, I am getting the error com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityCons traintViolationException: Column 'id' cannot be null. My Phone table primary key is a composite key consisting of phoneNumber and foreign key id.

    I have my classes as below

    Student.java

    Java Code:
    import java.io.Serializable;  
    import java.util.Set;  
    import javax.persistence.CascadeType;  
    import javax.persistence.Entity;  
    import javax.persistence.GeneratedValue;  
    import javax.persistence.GenerationType;  
    import javax.persistence.Id;  
    import javax.persistence.JoinColumn;  
    import javax.persistence.OneToMany;  
      
    @Entity  
    @SuppressWarnings("serial")  
    public class Student implements Serializable {  
      
    @Id  
    @GeneratedValue(strategy = GenerationType.AUTO)  
    private int id;  
      
    private String fName;  
      
    private String lName;  
      
    private String mname;  
      
    @OneToMany(cascade = CascadeType.ALL)  
    @JoinColumn(name = "id")  
    private Set<Phone> phones;  
      
    /** 
    * @return the fName 
    */  
    public String getfName() {  
        return fName;  
    }  
      
    /** 
    * @return the id 
    */  
    public int getId() {  
        return id;  
    }  
      
    /** 
    * @return the lName 
    */  
    public String getlName() {  
        return lName;  
    }  
      
    /** 
    * @return the mname 
    */  
    public String getMname() {  
        return mname;  
    }  
      
    /** 
    * @return the phones 
    */  
    public Set<Phone> getPhones() {  
        return phones;  
    }  
      
    /** 
    * @param fName 
    *            the fName to set 
    */  
    public void setfName(final String fName) {  
        this.fName = fName;  
    }  
      
    /** 
    * @param id 
    *            the id to set 
    */  
    public void setId(final int id) {  
        this.id = id;  
    }  
      
    /** 
    * @param lName 
    *            the lName to set 
    */  
    public void setlName(final String lName) {  
        this.lName = lName;  
    }  
      
    /** 
    * @param mname 
    *            the mname to set 
    */  
    public void setMname(final String mname) {  
        this.mname = mname;  
    }  
      
    /** 
    * @param phones 
    *            the phones to set 
    */  
    public void setPhones(final Set<Phone> phones) {  
        this.phones = phones;  
    }  
      
    }
    Phone.java

    Java Code:
    import java.io.Serializable;  
      
    import javax.persistence.Entity;  
    import javax.persistence.GeneratedValue;  
    import javax.persistence.GenerationType;  
    import javax.persistence.Id;  
    import javax.persistence.IdClass;  
    import javax.persistence.JoinColumn;  
    import javax.persistence.ManyToOne;  
      
    @IdClass(PhonePK.class)  
    @Entity  
    @SuppressWarnings("serial")  
    public class Phone implements Serializable {  
      
    @Id  
    private String phoneNumber;  
      
    @Id  
    @ManyToOne  
    @JoinColumn(name = "id", insertable = false, updatable = false)  
    private Student student;  
      
    private String color;  
      
    /** 
    * @return the color 
    */  
    public String getColor() {  
        return color;  
    }  
      
    /** 
    * @return the phoneNumber 
    */  
    public String getPhoneNumber() {  
        return phoneNumber;  
    }  
      
    /** 
    * @return the student 
    */  
    public Student getStudent() {  
        return student;  
    }  
      
    /** 
    * @param color 
    *            the color to set 
    */  
    public void setColor(final String color) {  
        this.color = color;  
    }  
      
    /** 
    * @param phoneNumber 
    *            the phoneNumber to set 
    */  
    public void setPhoneNumber(final String phoneNumber) {  
        this.phoneNumber = phoneNumber;  
    }  
      
    /** 
    * @param student 
    *            the student to set 
    */  
    public void setStudent(final Student student) {  
        this.student = student;  
    }  
      
    }
    PhonePK.java

    Java Code:
    import java.io.Serializable;  
      
    @SuppressWarnings("serial")  
    public class PhonePK implements Serializable {  
      
    private String phoneNumber;  
      
    private Student student;  
      
    /** 
    * @return the phoneNumber 
    */  
    public String getPhoneNumber() {  
        return phoneNumber;  
    }  
      
    /** 
    * @return the student 
    */  
    public Student getStudent() {  
        return student;  
    }  
      
    /** 
    * @param phoneNumber 
    *            the phoneNumber to set 
    */  
    public void setPhoneNumber(final String phoneNumber) {  
        this.phoneNumber = phoneNumber;  
    }  
      
    /** 
    * @param student 
    *            the student to set 
    */  
    public void setStudent(final Student student) {  
        this.student = student;  
    }  
      
    }
    hibernate.cfg.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE hibernate-configuration PUBLIC  
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  
    <hibernate-configuration>  
    <session-factory>  
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>  
    <property name="hibernate.connection.password">pwd</property>  
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>  
    <property name="hibernate.connection.username">user</property>  
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>  
    <property name="connection.pool_size">1</property>  
    <property name="show_sql">true</property>  
    <property name="hbm2ddl.auto">create</property>  
    <property name="hibernate.show_sql">true</property>  
      
    </session-factory>  
    </hibernate-configuration>
    Main.java

    Java Code:
    import java.util.LinkedHashSet;  
    import java.util.Set;  
      
    import org.hibernate.HibernateException;  
    import org.hibernate.Session;  
    import org.hibernate.SessionFactory;  
    import org.hibernate.Transaction;  
    import org.hibernate.cfg.Configuration;  
      
    public class Main {  
      
        public static void main(final String args[]) {  
              
            Configuration configuration = new Configuration();  
            Transaction transaction = null;  
              
            configuration.addAnnotatedClass(Student.class);  
            configuration.addAnnotatedClass(Phone.class);  
            configuration.addAnnotatedClass(PhonePK.class);  
            configuration.configure("hibernate.cfg.xml");  
      
            SessionFactory sessionFactory = configuration.buildSessionFactory();  
      
            Session session = sessionFactory.openSession();  
              
      
            Student student = new Student();  
            student.setfName("Bob");  
            student.setlName("Buster");  
            Set<Phone> phones = new LinkedHashSet<Phone>();  
            Phone ph1 = new Phone();  
            ph1.setColor("Black");  
            ph1.setPhoneNumber("1111111111");  
      
            Phone ph2 = new Phone();  
            ph2.setColor("Blue");  
            ph2.setPhoneNumber("2222222222");  
            phones.add(ph1);  
            phones.add(ph2);  
      
            student.setPhones(phones);  
              
            try {  
                transaction = session.beginTransaction();  
                session.save(student);  
                transaction.commit();  
            } catch (HibernateException e) {  
                transaction.rollback();  
                e.printStackTrace();  
            } finally {  
                session.close();  
            }  
              
                }  
    }

    Console output

    Java Code:
    Jun 29, 2013 11:22:49 AM org.hibernate.annotations.common.Version <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
    Jun 29, 2013 11:22:49 AM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {4.2.2.Final}
    Jun 29, 2013 11:22:49 AM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    Jun 29, 2013 11:22:49 AM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    Jun 29, 2013 11:22:49 AM org.hibernate.cfg.Configuration configure
    INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
    Jun 29, 2013 11:22:49 AM org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: HHH000040: Configuration resource: hibernate.cfg.xml
    Jun 29, 2013 11:22:49 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
    WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
    Jun 29, 2013 11:22:50 AM org.hibernate.cfg.Configuration doConfigure
    INFO: HHH000041: Configured SessionFactory: null
    Jun 29, 2013 11:22:50 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
    Jun 29, 2013 11:22:50 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 1
    Jun 29, 2013 11:22:50 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: false
    Jun 29, 2013 11:22:50 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/test]
    Jun 29, 2013 11:22:50 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000046: Connection properties: {user=user, password=****}
    Jun 29, 2013 11:22:51 AM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    Jun 29, 2013 11:22:52 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
    WARN: HHH000038: Composite-id class does not override equals(): PhonePK
    Jun 29, 2013 11:22:52 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
    WARN: HHH000039: Composite-id class does not override hashCode(): PhonePK
    Jun 29, 2013 11:22:52 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
    INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
    Jun 29, 2013 11:22:52 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
    INFO: HHH000397: Using ASTQueryTranslatorFactory
    Jun 29, 2013 11:22:52 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000227: Running hbm2ddl schema export
    Hibernate: alter table Phone drop foreign key FK_aoj0eivd0ap3drxnoyk4xj10q
    Hibernate: drop table if exists Phone
    Hibernate: drop table if exists Student
    Hibernate: create table Phone (phoneNumber varchar(255) not null, color varchar(255), id integer not null, primary key (phoneNumber, id))
    Hibernate: create table Student (id integer not null auto_increment, fName varchar(255), lName varchar(255), mname varchar(255), primary key (id))
    Hibernate: alter table Phone add index FK_aoj0eivd0ap3drxnoyk4xj10q (id), add constraint FK_aoj0eivd0ap3drxnoyk4xj10q foreign key (id) references Student (id)
    Jun 29, 2013 11:22:53 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000230: Schema export complete
    Hibernate: insert into Student (fName, lName, mname) values (?, ?, ?)
    Hibernate: select phone_.phoneNumber, phone_.id, phone_.color as color2_0_ from Phone phone_ where phone_.phoneNumber=? and phone_.id=?
    Hibernate: select phone_.phoneNumber, phone_.id, phone_.color as color2_0_ from Phone phone_ where phone_.phoneNumber=? and phone_.id=?
    Hibernate: insert into Phone (color, phoneNumber, id) values (?, ?, ?)
    Jun 29, 2013 11:22:53 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 1048, SQLState: 23000
    Jun 29, 2013 11:22:53 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: Column 'id' cannot be null
    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
    Jun 29, 2013 11:22:53 AM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
    INFO: HHH000010: On release of batch it still contained JDBC statements
    Last edited by Nomula; 06-29-2013 at 07:32 PM.

  2. #2
    Nomula is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Re: Unable to insert rows

    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.

    Java 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

Similar Threads

  1. Replies: 5
    Last Post: 05-03-2013, 02:08 PM
  2. Unable to download maven repository - Unable to load the mojo
    By tejkiransharma in forum Apache Maven
    Replies: 0
    Last Post: 12-31-2012, 04:44 PM
  3. read rows
    By Andrew_2 in forum New To Java
    Replies: 9
    Last Post: 04-22-2011, 03:00 PM
  4. insert multiple rows in the table from List
    By Bulelakes in forum JDBC
    Replies: 2
    Last Post: 11-15-2010, 02:19 PM
  5. Replies: 3
    Last Post: 02-28-2009, 10:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •