0

I am creating table one to many mapping via hibernate but some problem occur it could not update table.

StackTrace

    May 05, 2015 8:36:45 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
May 05, 2015 8:36:45 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
May 05, 2015 8:36:45 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Organisation.hbm.xml
May 05, 2015 8:36:45 PM 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!
May 05, 2015 8:36:45 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Data.hbm.xml
May 05, 2015 8:36:45 PM 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!
May 05, 2015 8:36:45 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
May 05, 2015 8:36:45 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
May 05, 2015 8:36:45 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
May 05, 2015 8:36:45 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
May 05, 2015 8:36:45 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/notifier]
May 05, 2015 8:36:45 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****}
May 05, 2015 8:36:45 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
May 05, 2015 8:36:45 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
May 05, 2015 8:36:45 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
May 05, 2015 8:36:45 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: notifier.data
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [org_id, id, user_name, address, date, city, mobile_no]
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: notifier.organisation
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [org_id, username, person_mobile_no, email, person_name, estimatedpeople, orgname, org_mobile_no, password, orgaddress, city]
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
May 05, 2015 8:36:45 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
May 05, 2015 8:36:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: HHH000388: Unsuccessful: alter table DATA add index FK1FE7AA2ED256C (ORG_ID), add constraint FK1FE7AA2ED256C foreign key (ORG_ID) references ORGANISATION (ORG_ID)
May 05, 2015 8:36:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: Can't create table 'notifier.#sql-b18_c' (errno: 150)
May 05, 2015 8:36:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete

Error is showing in 3rd last line in stacktrace

Data.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

<class name="hibernate.Data" table="DATA">

    <id name="id" column="ID">
        <generator class="increment" />
    </id>

    <many-to-one name="" class="hibernate.Organisation">
        <column name="ORG_ID"></column>
    </many-to-one>


    <property name="orgId" column="ORG_ID" insert="true" update="false"
        length="10" />

    <property name="date" column="DATE" length="20" />
    <property name="userName" column="USER_NAME" length="20" />
    <property name="mobileNo" column="MOBILE_NO" length="20" />
    <property name="address" column="ADDRESS" length="20" />
    <property name="city" column="CITY" length="20" />


</class>

Organisation.hbm.xml

<?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

 <hibernate-mapping>
 <class name="hibernate.Organisation" table="ORGANISATION">

    <id name="orgId" column="ORG_ID" length="5">
        <generator class="increment" />
    </id>
    <property name="orgName" column="ORGNAME" length="25" />
    <property name="orgAddress" column="ORGADDRESS" length="500" />
    <property name="city" column="CITY" length="25" />
    <property name="orgMobileNO" column="ORG_MOBILE_NO" length="12" />
    <property name="personName" column="PERSON_NAME" length="25" />
    <property name="personMobileNo" column="PERSON_MOBILE_NO"
        length="12" />
    <property name="email" column="EMAIL" length="50" />
    <property name="estimatedPeople" column="ESTIMATEDPEOPLE"
        length="25" />

    <property name="userName" column="USERNAME" />
    <property name="password" column="PASSWORD" />


    <set name="data" table="DATA" cascade="all">
        <!-- used to specify name of foreign key should be created in child table -->
        <key column="ORG_ID" />
        <one-to-many class="hibernate.Data" />
    </set>
</class>

hibernate.cfg.xml

     <?xml version='1.0' encoding='UTF-8'?>
     <!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
     <!-- Generated by MyEclipse Hibernate Tools. -->
     <hibernate-configuration>
    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
        <property name="connection.username">root</property>
        <property name="connection.password">kartik</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping resource="Organisation.hbm.xml" />
        <mapping resource="Data.hbm.xml" />
    </session-factory>

</hibernate-configuration>

Is any thing wrong with mapping or problem with something else.

Please help me out.

Thanks in advance

3
  • 1
    It's possible that data types are not the same for DATA.ORG_ID and ORGANIZATION.ORG_ID, so check that. Also, your mappings seems to be wrong, like mapping same column as property and join column for collection, or many-to-many with no name... Commented May 5, 2015 at 15:27
  • thanks. data type were different. Problem solved Commented May 5, 2015 at 15:31
  • Great. I'll post it as an answer since it helped. Commented May 5, 2015 at 15:32

1 Answer 1

1

It's possible that data types are not the same for DATA.ORG_ID and ORGANIZATION.ORG_ID, so check that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.