-->
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.  [ 3 posts ] 
Author Message
 Post subject: Multiple Mapping files
PostPosted: Tue Mar 30, 2004 4:43 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 5:22 pm
Posts: 35
I want create separate mapping files for each table, for example i want to separate the
following example into two files called Place.hbm.xml,Person.hbm.xml[each class has its own
mapping file]. Then how do i associate these two files for one-to-many relationship ?


Can some help ?

<hibernate-mapping>
<class name="com.peopleplacesmodel.model.Place" table="AUCTIONS">
<id name="ID" type="string" unsaved-value="null">
<column name="ID" sql-type="char(32)" not-null="true" />
<generator class="uuid.hex" />
</id>
------------------
------------------
------------------
------------------
<set name="person" lazy="true">
<key column="AUCTID" />
<one-to-many class="com.peopleplacesmodel.model.Person" />
</set>
</class>
<class name="com.peopleplacesmodel.model.Person" table="PRTDIRVIEW">
<composite-id name="personName" class="com.peopleplacesmodel.model.PersonPK">
<key-property name="AUCTID" />
<key-property name="PRTLNAME" />
<key-property name="PRTFNAME" />
</composite-id>
------------------
------------------
------------------
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 5:17 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Code:
   Configuration cfg = new Configuration();

   Properties props = new Properties();
   props.load( new FileInputStream(propFileName) );
   cfg.setProperties(props);

   Iterator it = filenames.iterator();
   while ( it.hasNext() ) {
      String filename = (String) it.next();
      cfg.addFile(filename);
   }
      
   sessions = cfg.buildSessionFactory();


Hibernate will not try and match up class names across mapping files until you do the cfg.buildSessionFactory().



Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 5:35 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 5:22 pm
Posts: 35
I understand that you are loading all the required mapping files.
Made a little change which is working fine.
Mapping directory has all the xml files per class.

private void prepareConfiguration() throws Exception
{
cfg = new Configuration().addDirectory(new File ("../src/com/peopleplacesmodel/mapping"));
sf = cfg.buildSessionFactory();
session = sf.openSession();
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.