java - Create index on column in one-to-many relationship -


i have one-to-many relationship between 2 classes this:

class parent {     list<child> children; }  class child {     string name; } 

i'm using .hbm.xml file define mapping java classes tables. this:

<class name="parent" table="parent">     <list name="children">         <key column="parent_id" />         <list-index column="idx" />         <one-to-many class="child" />     </list> </class>  <class name="child" table="child">     <property name="name" type="string" /> </class> 

that works fine.

now want create column index (not list index) on child.parent_id column. seems <one-to-many> tag doesn't allow nested <column> tags, tried adding bidirectional association child mapping this:

<many-to-one name="parent" insert="false" update="false">     <column name="parent_id" index="true"> </many-to-one> 

but exception:

 org.hibernate.propertynotfoundexception: not find getter parent in class child 

so, how can create index on child.parent_id column without adding parent field child class? i'm using hibernate 3.5.6 , postgresql 9.3.

at first didn't looking for, think figure out.

you defined list-index used save index of java.util.list , not parent_id of child. looking how create real database index. can easy done annotation this;

@onetomany(cascade = { cascadetype.all }) @joincolumn(name="parent_id") @index(name = "idx_parent_id", columnnames = "parent_id") private list<child> images = new arraylist<child>();  

and in xml configuration like,

  <list name="children">    <key>     <column index="parent_id_idx" name="parent_id"/>    </key>    <list-index column="idx"/>    <one-to-many class="hr.winkme.server.model.entities.child"/>   </list> 

hope helps.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -