-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Unable to Insert into database
PostPosted: Thu Sep 18, 2008 7:43 am 
Newbie

Joined: Thu Sep 18, 2008 7:26 am
Posts: 2
Location: India
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 ??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 4:11 am 
Newbie

Joined: Thu Sep 18, 2008 7:26 am
Posts: 2
Location: India
I found the solution...


It was problem with the order i call session.save()...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.