-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Mapping Hell
PostPosted: Sat Aug 20, 2005 3:53 pm 
Beginner
Beginner

Joined: Sun Jun 05, 2005 9:45 am
Posts: 27
All, I am pulling my hair out over this one!

COMPANY <1--*> COMPANY_MODULE_ASSOC <*--*> MODULE <1--*> PAGE


COMPANY_MODULE_ASSOC is not just a join table, it has an extra field called "enabled".

I went with the recomendations located here:
http://www.hibernate.org/hib_docs/reference/en/html/components.html and created a CompanyModuleAssoc class and mapped the above relationship like this:

Code:
<set name="companyModuleAssociations" lazy="false" table="company_module_assoc">
    <key column="company_id"/>
    <composite-element class="CompanyModuleAssoc">
        <property name="enabled" type="boolean" not-null="true"/>
        <many-to-one name="module" class="Module" column="module_id" not-null="true"/>
    </composite-element>
</set>


Great. But now, a company can customize the content on one of the module pages. This means that there is a table named "CUSTOMIZED_PAGES" that is associated with the COMPANY_MODULE_ASSOC table.

How the heck do I do this in Hibernate? company_id, module_id and page_id would be a composite id in the CUSTOMIZED_PAGES table. Can I map a relationship to a composite?

Best Regards,

Joshua


Top
 Profile  
 
 Post subject: Looking for help
PostPosted: Sat Aug 20, 2005 8:39 pm 
Beginner
Beginner

Joined: Sun Jun 05, 2005 9:45 am
Posts: 27
All,

I am pretty stuck on this. This relationship is pretty out of the ordinary. Is there any other information that I can provide that would help?

Best Regards,

Joshua


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 20, 2005 8:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I have no idea what you are trying to do, but almost certainly you will have more success mapping the class as an entity, instead of as a composite-element.


Top
 Profile  
 
 Post subject: Let me try to explain this differently
PostPosted: Sat Aug 20, 2005 9:07 pm 
Beginner
Beginner

Joined: Sun Jun 05, 2005 9:45 am
Posts: 27
Gavin,

I will try to make this as clear as possible. I have included my table definitions below.

My application contains a number of MODULEs. Each MODULE has a number of PAGEs associated with it. A COMPANY can have MODULEs turned on using the MODULE table. This table is essentially a many-to-many table with an extra column, "enabled". I got this mapping to work by using a component (see my previous post in this thread).

Companies are able to customize the content of the PAGEs by specifying custom html in the CUSTOMIZED_PAGES table.

I have been unable to create a mapping between COMPANY_MODULE_ASSOC and the
CUSTOMIZED_PAGES table. As you can see below, CUSTOMIZED_PAGES also has a reference back to PAGE. Can you please help me with this?

Regards,

Joshua



Table Definitions:
Code:
MODULE
--------------------
module_id (PK)
module_name


PAGE
--------------------
page_id (PK)
module_id (FK)
page_name


COMPANY_MODULE_ASSOC
--------------------
company_id (PK,FK)
module_id  (PK,FK)
enabled


COMPANY
--------------------
company_id (PK)
company_name


CUSTOMIZED_PAGES
--------------------
company_id (PK,FK)
module_id  (PK,FK)
page_id    (PK,FK)
custom_html


Top
 Profile  
 
 Post subject: Map as an entity instead of a composite?
PostPosted: Sun Aug 21, 2005 10:06 am 
Beginner
Beginner

Joined: Sun Jun 05, 2005 9:45 am
Posts: 27
Can you map the many-to-many relationship as an entity when the many-to-many table has an extra column? Looking in the docs, I have always seen it mapped using a component.

I am really stuck on this. I would appreciate your help.

Joshua


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.