-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping Design Question
PostPosted: Fri Jul 29, 2005 9:16 am 
Newbie

Joined: Mon Jul 18, 2005 6:57 am
Posts: 12
Hi,

I am fairly new to Hibernate but I've got a design question about how best to build a query.

I new to design a query that will return a list of Companies based on Location and Business Type

I have 3 classes for each thing

- Companies
- RegisteredLocation
- BusinessType

Each class has it's own table. There are also two further Link tables.

COMPANY_LOCATION
COMPANY_BUSINESS_TYPE

So my method that I will be calling is,

getCompaniess(long locationId, long businessTypeId);

I'm not sure about how best to design the Mapping files. Do I need to put everything into the Companies mapping file. How do I reference these other classes from that mapping file and how do I go about constructing the HQL query.

Any pointers will be greatly appreciated. Apologies for not having any mapping files. Haven't started them yet as I am trying to figure out what the best way to do this is.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 10:20 am 
Newbie

Joined: Wed Jul 27, 2005 2:34 pm
Posts: 3
Mapping for company class
<class name="Companies" table="Comapnies">
<id>
<!-- Assuming company_id is key identifier. -->
</id>



<!-- Associations -->

<!-- bi-directional one-to-many association to COMPANY_LOCATION -->
<set name="COMPANY_LOCATION" lazy="false" inverse="true" cascade="none">
<key>
<column name="company_id"/>
</key>

<one-to-many class="COMPANY_LOCATION " />
</set>

<!-- bi-directional one-to-many association to COMPANY_BUSINESS_TYPE-->
<set name="COMPANY_BUSINESS_TYPE" lazy="false" inverse="true" cascade="none">
<key>
<column name="company_id" />
</key>

<one-to-many class="COMPANY_BUSINESS_TYPE" />
</set>
</class>

Mapping for location class:

<class name="Location" table="Location">
<id>
<!-- Assuming location_id is key identifier. -->
...
...
</id>

<!-- Associations -->

<!-- bi-directional one-to-many association to COMPANY_LOCATION -->
<set name="COMPANY_LOCATION" lazy="false" inverse="true" cascade="none">
<key>
<column name="location_id"/>
</key>

Similar mapping file for business type class also. This way you can retrieve and store objects from any class. For example you can access company object from location objects. Depending on what you select a value for "cascade" attribute it will determine whether you can store the linked abjects or not.

Hope this helps and gets you started.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 6:40 pm 
Beginner
Beginner

Joined: Fri Jul 29, 2005 2:11 pm
Posts: 21
If I want to use a List instead of Set, do I need to use <bag> versus <set> for COMPANY_LOCATION?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 7:35 pm 
Newbie

Joined: Tue Jul 05, 2005 11:47 pm
Posts: 15
Location: Argentina
biguniverse wrote:
If I want to use a List instead of Set, do I need to use <bag> versus <set> for COMPANY_LOCATION?


As long as you don't need to retain the order, you can use a <bag>.

You can find information about the different mappings for collections in sectin 7.2 of the reference.


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