0 Replies Latest reply on Aug 12, 2014 7:11 AM by Chaitanya Kumar

    when to set insertable and updateable as false in hibernate

    Chaitanya Kumar Newbie

      As per Hibernate documentation at http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch05.html, in below example:


      [code]    <class name="Customer">

             <composite-id name="id" class="CustomerId">

                <key-property name="firstName" column="userfirstname_fk"/>

                <key-property name="lastName" column="userfirstname_fk"/>

                <key-property name="customerNumber"/>



             <property name="preferredCustomer"/>


             <many-to-one name="user">

                <column name="userfirstname_fk" updatable="false" insertable="false"/>

                <column name="userlastname_fk" updatable="false" insertable="false"/>




          <class name="User">

             <composite-id name="id" class="UserId">

                <key-property name="firstName"/>

                <key-property name="lastName"/>



             <property name="age"/>





      [quote]Notice a few things in the previous example:


      the order of the properties (and column) matters. It must be the same between the association and the primary key of the associated entity


      the many to one uses the same columns as the primary key and thus must be marked as read only (insertable and updatable to false).


      unlike with @MapsId, the id value of the associated entity is not transparently copied, check the foreign id generator for more information.[/quote]


      I am new to Hibernate so finding it difficulty in understanding these.


      - Why the order of the properties is matters? Which is called as association and which one is associated in first statement?


      - Why the columns needs to be set as false for insertable and updateable?


      - What is copying transparently? How @MapId makes a difference here?



      Can someone please help me in clarifying these.