Hi,
I have just started using Hibernate.
I have an application where in i am trying to do some batch updates..
The Hbm files i use are given below
Master.hbm.xml
Quote:
<hibernate-mapping>
<class name="persistence.Master" table="master" lazy="true">
<id name="masterId" type="string" length="32">
<generator class="uuid.hex"></generator>
</id>
<many-to-one name="publicName" class="persistence.Message">
<column name="publicNameId" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
Message.hbm.xml
Quote:
<hibernate-mapping>
<class name="persistence.Message" table="message" lazy="true">
<id name="messageId" type="string" length="32">
<generator class="uuid.hex"></generator>
</id>
<property name="name" not-null="true" type="string" length="30" unique="true">
</property>
<property name="description" type="string" length="255">
</property>
<map name="messageLanguages" inverse="false" lazy="true">
<meta attribute="field-description">
</meta>
<key column="messageId"/>
<index column="languageId" type="string"/>
<one-to-many class="persistence.MessageLanguage" />
</map>
</class>
</hibernate-mapping>
MessageLanguage.hbm.xml
Quote:
<hibernate-mapping>
<class name="persistence.MessageLanguage" table="messageLanguage" lazy="true">
<composite-id name="id" class="persistence.MessageLanguageId">
<key-many-to-one name="message" class="persistence.Message">
<column name="messageId" />
</key-many-to-one>
<key-many-to-one name="language" class="persistence.Language">
<column name="languageId" />
</key-many-to-one>
</composite-id>
<many-to-one name="status" class="persistence.PStatus">
<column name="statusId" />
</many-to-one>
<property name="longMessage" type="string" length="255">
</property>
<property name="shortMessage" not-null="true" type="string" length="255">
</property>
</class>
</hibernate-mapping>
And i execuet the following piece of code..
Code:
config = new Configuration();
factory = config.configure().buildSessionFactory();
session = factory.openSession();
trans = session.beginTransaction();
master = new Master();
master.setPublicName(createMessages("1. " , "This is message 1 ", "Value"));
private Message createMessages(String name, String description,
String shortMessage) {
Message message = new Message();
message.setName(name);
message.setDescription(description);
MessageLanguageId msglngID = new MessageLanguageId();
msglngID.setLanguage(language);//Language is fetched from database
msglngID.setMessage(message);
// Message Language
MessageLanguage messagelanguage = new MessageLanguage();
messagelanguage.setId(msglngID);
messagelanguage.setShortMessage(shortMessage);
messagelanguage.setLongMessage("unassigned");
Map<String, MessageLanguageId> mapmsglng = new HashMap<String, MessageLanguageId>();
mapmsglng.put(message.getMessageId(), msglngID);
message.setMessageLanguages(mapmsglng);
session.save(message);
return message;
}
This executes with out any error and both Master and Message tables are updated but not MessageLanguage table...
Can anyone tell me what i need to do ??