关于下面显示的小型休眠应用程序,有些事情我不明白mapping xml
。
<class name="pojo.Ghazal" table="ghazal">
<id name="s_no">
<generator class="increment" />
</id>
<property name="poem" />
<property name="poet" />
<map name="map" table="linked" cascade="all">
<key column="s_no" />
<index column="key_" type="string" />
<many-to-many column="val_" class="pojo.Singer" />
</map>
</class>
<class name="pojo.Singer" table="singer">
<id name="s_no">
<generator class="increment" />
</id>
<property name="singer_name" />
<property name="country" />
</class>
有 2 个,pojos
即Ghazal
和Singer
。我了解Singer
类的映射,但我不了解类的映射Ghazal
。
当我运行以下程序时:
Configuration config = new Configuration().configure();
SessionFactory sessFact = config.buildSessionFactory();
Session sess = sessFact.openSession();
Transaction trans = sess.beginTransaction();
Ghazal ghazal = new Ghazal();
Singer singer = new Singer();
singer.setCountry("Pakistan");
singer.setSinger_name("Mehdi Hasan");
Singer singer_1 = new Singer();
singer_1.setCountry("India");
singer_1.setSinger_name("Jagjit Singh");
HashMap map = new HashMap();
map.put("key_1", singer);
map.put("key_2", singer_1);
ghazal.setPoem("Woh Jo Hum Mein Tum Mein Qarar Tha");
ghazal.setPoet("Momin Khan Momin");
ghazal.setMap(map);
sess.save(ghazal);
trans.commit();
数据自动存储在三个表中ghazal, linked, singer
。singer
当我只提交类的对象时,数据如何存储在表中ghazal
?
标签是什么:
<many-to-many...>
做吗?