-->
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.  [ 1 post ] 
Author Message
 Post subject: Data transfer between different Database
PostPosted: Fri Jul 03, 2009 8:06 am 
Newbie

Joined: Sun Mar 01, 2009 11:11 pm
Posts: 9
Hi,


I need to copy some data from a remote DB and insert into a target DB. I have a DB Link created in my target DB for the remote DB

Now I want to run a native sql and type caste the result into my target DB Domain object and then call saveorupdate.


I am unable to do this,

What I have now is

Code:
<hibernate-mapping>
       <sql-query name="DealerProfile" flush-mode="auto">     
         select DLRM_CMPN_NO as  {dealerMaster.DLMST_CMPN_NO},
            DLRM_CORP_NO as  {dealerMaster.DLMST_CORP_NO},
            DLRM_DLR_NO   as  {dealerMaster.DLMST_DLR_NO},
             DLRM_SPR_DLR_NO as  {dealerMaster.DLMST_SPR_DLR_NO},
         DLRM_DLR_DSCTN  as  {dealerMaster.DLMST_DLR_DSCTN},
         DLRM_MAIN_DLR_YN  as  {dealerMaster.DLMST_MAIN_DLR_YN},
         DLRM_BRCH_SEQ_NO  as  {dealerMaster.DLMST_BRCH_SEQ_NO},
         DLRM_RGN_OFCE_NO  as  {dealerMaster.DLMST_RGN_OFCE_NO},
         DLRM_CRTE_EMP_NO  as  {dealerMaster.DLMST_CRTE_USR_NO},
         DLRM_UPDT_EMP_NO  as  {dealerMaster.DLMST_UPDT_USR_NO},
         DLRM_CRTE_DTIME  as  {dealerMaster.DLMST_CRTE_TIME},
         DLRM_UPDT_DTIME  as  {dealerMaster.DLMST_UPDT_TIME}
      from CADLRM_TB@servicelive
     
       <return alias="dealerMaster" class="hmil.com.dlr.model.Dealer"  />
   </sql-query>

</hibernate-mapping>


And in my Java Class I have

Code:
session.beginTransaction();
result = session.getNamedQuery("DealerProfile").list();
for (Iterator itr = result.iterator(); itr.hasNext();)
{
Dealer dealer = (Dealer) itr.next();     
session.saveorupdate(dealer);
}
session.getTransaction().commit();


And I also have the mapping for Dealer class
Code:
<hibernate-mapping>
   


   <class name="hmil.com.dlr.model.Dealer" table="CMDLMST_TB">
      <id name="DLMST_DLR_NO" column="DLMST_DLR_NO" type="java.lang.String">
         <generator class="assigned" />
      </id>   
      <property name="DLMST_CMPN_NO"       insert="false" update="false"   type="java.lang.String"/>
        <property name="DLMST_CORP_NO"      insert="false" update="false"   type="java.lang.String"/>
      <property name="DLMST_SPR_DLR_NO"   insert="false" update="false"   type="java.lang.String"/>
        <property name="DLMST_DLR_DSCTN"    insert="false" update="false"   type="java.lang.String"/>
        <property name="DLMST_MAIN_DLR_YN"  insert="false" update="false"   type="java.lang.String"/>
        <property name="DLMST_BRCH_SEQ_NO"  insert="false" update="false"   type="int"/>
        <property name="DLMST_RGN_OFCE_NO"  insert="false" update="false"   type="java.lang.String"/>
        <property name="DLMST_CRTE_USR_NO"  insert="false" update="false"   type="java.lang.String"/>
        <property name="DLMST_CRTE_TIME"    insert="false" update="false"   type="java.sql.Timestamp"/>
        <property name="DLMST_UPDT_USR_NO"  insert="false" update="false"   type="java.lang.String"/>
        <property name="DLMST_UPDT_TIME"    insert="false" update="false"   type="java.sql.Timestamp"/>
   </class>
</hibernate-mapping>


And also the getter setter class, but when I run this method to get the data and update in target DB,

It is getting the data and even I can print the values
but it does not update the value in to my target db ,

If I iterate and form a new object with same id and when I try to save, it throws that another object with same id exists.

But it does not update the targetDB.

So please help me.


I have a spring + Hibernate setup, and what is the best way to write some batch program (currently I am using Quartz to trigger the method call)to transfer data between different Data Base, with the help of hibernate. Or Is it best to use Plain Java and jdbc


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

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.