-->
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: Plz Help on Map Multiple Tables to same POJO file
PostPosted: Wed Nov 05, 2008 1:58 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
I want to use same mapping file and POJO file for two tables report1 and report2. These two tables schema is same. but the names of the table only differ.

For that i just open hbm file and change only the table name by SAXBuilder and save into the same file. When i run this program it only retrieves data from report_1 table only.
But when i save the modified hbm file into another file, it works fine(the first block get data from report_1 and second from report_2).

Plz help me to solve this problem, our project on binding for this purpose.

it's my mapping file:
Report1.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.hcl.Report1" table="report_1" catalog="magnettelx">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>

My main coding
Code:
       Configuration config=new Configuration();
       config.configure("/hibernate.cfg.xml");
       config.addResource("Report1.hbm.xml");
       SessionFactory sf=config.buildSessionFactory();
       Session session=sf.openSession();
       Transaction trx=session.beginTransaction();
       System.out.println("Report1");
        while(results.hasNext())
          System.out.println(results.next().toString());
        File file=new File("Report1.hbm.xml");
        SAXBuilder builder = new SAXBuilder();
      Document doc = builder.build(file);
        Element docroot=doc.getRootElement();
      System.out.println("Root Elemet: "+ docroot.toString());
      System.out.println(docroot.getChild("class").getAttribute("table").setValue("report_2"));
      XMLOutputter xmlout=new XMLOutputter();
      xmlout.output(doc, new FileOutputStream(new File("Report1.hbm.xml")));
      trx.commit();
      session.flush();
      session.close();
     
       System.out.println("Report2");
       Configuration config1=new Configuration();
       config1.configure("/hibernate.cfg.xml");
       config1.addResource("Report2.hbm.xml");
       SessionFactory sf1=config1.buildSessionFactory();
       Session session1=sf1.openSession();
       Transaction trx1=session1.beginTransaction();
            results=session1.createQuery("select r.name from Report1 r").iterate();
              while(results.hasNext())
              System.out.println(results.next().toString());
      trx1.commit();
      
      session1.flush();
      session1.close();

_________________
If u feel it will help you, don't forget to rate me....


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.