-->
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: many-to-many problem with categories
PostPosted: Wed Mar 26, 2008 9:16 am 
Newbie

Joined: Wed Mar 26, 2008 9:04 am
Posts: 9
Location: Athens, Greece
Hello everybody,

I need a hint, I have the following objects (made up to show the problem)

class Document {
Long id
Set importantKeywords
Set lessImportantKeywords
Set unimportantKeywords
Set funnyKeywords
// other information
}

class Keyword {
Long id
String keyword
// other information ..
}

I was planning to have database tables like this

create table document (
document_id int primary key,
-- other information
);

create table keyword (
keyword_id int primary key,
keywords text,
-- other information
);

create table document_keywords (
document_id int references document,
keyword_id int references keyword,

-- one of 'important', 'unimportant', 'funny' etc.
link_type string
);

I think I can make a where clause in my mapping to get the right keywords in the right collections of the document. I can't figure out though how to tell hibernate to insert the right link_type on storing of my documents.

Any help appreciated ...


Arne


Top
 Profile  
 
 Post subject: Re: many-to-many problem with categories
PostPosted: Thu Mar 27, 2008 11:34 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
May be a custom update sql.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 6:33 am 
Newbie

Joined: Wed Mar 26, 2008 9:04 am
Posts: 9
Location: Athens, Greece
Hello farzad,

Thanks for taking the time to read through my problem. I think in terms
of workaround solution I could just make one linkage table for every
category of keywords. I would prefer that to custom update sql.

I was hoping to get a solution which works analogous to the Address example in the hibernate reference manual

Code:
<class name="Person">
    <id name="name"/>
    <one-to-one name="address"
            cascade="all">
        <formula>name</formula>
        <formula>'HOME'</formula>
    </one-to-one>
    <one-to-one name="mailingAddress"
            cascade="all">
        <formula>name</formula>
        <formula>'MAILING'</formula>
    </one-to-one>
</class>

<class name="Address" batch-size="2"
        check="addressType in ('MAILING', 'HOME', 'BUSINESS')">
    <composite-id>
        <key-many-to-one name="person"
                column="personName"/>
        <key-property name="type"
                column="addressType"/>
    </composite-id>
    <property name="street" type="text"/>
    <property name="state"/>
    <property name="zip"/>
</class>


Its very close, but I'm not sure how to modify it for a many-to-many linkage table.

Arne


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 2:22 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I don't think you can do much with that since formula works with primary keys and here the column in question is in a relation table that is not even mapped as an entity. What you could do is that you could define the relation table as an entity and then use formulas.

Farzad-


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.