facebook

hibernate mysql reference error

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #306766 Reply

    amir55
    Participant

    one_to_many_c2_student [student_id])) must have same number of columns as the referenced primary key [id,list_index]

    I use mywclipse 8 and mysql and hibernate 3.2

    1 – the error is next
    Caused by: org.hibernate.MappingException: Foreign key (FKF596D4C0392C5790:one_to_many_c2_student [student_id])) must have same number of columns as the referenced primary key (one_to_many_c2_user [id,list_index])

    2- it is to do with mapping of the User in the two course.cfg.xml and the user.cfg.xml here is both full codes.

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 3.0//EN” “http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&#8221; >
    <hibernate-mapping package=”one_to_many_c2″ auto-import=”false”>
    <class name=”Course1″ table=”one_to_many_c2_course”>
    <id name=”id” column=”id” type=”java.lang.Integer”>
    <generator class=”increment”/>
    </id>
    <discriminator column=”courseLevel” type=”string”></discriminator>
    <property name=”name” type=”string”></property>
    <property name=”courseLevel” type=”string” insert=”false” update=”false”></property>

    <list name=”users” table=”one_to_many_c2_user”>
    <key column=”id” not-null=”true” foreign-key=”one_to_many_c2_user_id_fkey” ></key>
    <list-index column=”list_index”></list-index>
    <composite-element class=”User”>
    <property name=”name” type=”string”></property>
    <property name=”userType” type=”string”></property>
    </composite-element>
    </list>

    <!– if use cascade=”save-update, delete” u delete all –>
    <subclass name=”Arabic” discriminator-value=”year1″>
    <join table=”one_to_many_c2_arabic”>
    <key column=”arabic_id”></key>
    <property name=”name” type=”string”></property>
    </join>
    </subclass>

    <subclass name=”English” discriminator-value=”year2″>
    <join table=”one_to_many_c2_english”>
    <key column=”english_id”></key>
    <property name=”name” type=”string”></property>
    </join>
    </subclass>

    </class>

    </hibernate-mapping>
    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    <hibernate-mapping package=”one_to_many_c2″ auto-import=”false”>
    <class name=”User” table=”one_to_many_c2_user” > <!–catalog not needed –>
    <id name=”id” column=”id” type=”java.lang.Integer”>
    <generator class=”increment”/> <!– if not auto increment string use assigned –>
    </id>
    <discriminator column=”userType” type=”string”></discriminator>

    <version name=”version” column=”version” unsaved-value=”negative”/>
    <property name=”name” type=”string”></property>
    <property name=”userType” type=”string” insert=”false” update=”false”></property>

    <subclass name=”Student” discriminator-value=”student”>
    <join table=”one_to_many_c2_student”>
    <key column=”student_id” foreign-key=”one_to_many_c2_user_id_fkey” ></key>
    <property name=”name” type=”string”></property>
    <property name=”userType” type=”string”></property>
    </join>
    </subclass>
    <subclass name=”Tutor” discriminator-value=”tutor”>
    <join table=”one_to_many_c2_tutor”>
    <key column=”tutor_id”></key>
    <property name=”name” type=”string”></property>
    <property name=”userType” type=”string”></property>
    </join>
    </subclass>

    </class>
    </hibernate-mapping>

    so many thanks if u could adjjust the relation

    #306834 Reply
Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: hibernate mysql reference error

You must be logged in to post in the forum log in