aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to map a tagged item? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to map a tagged item?" Watch "How to map a tagged item?" New topic
Author

How to map a tagged item?

Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
How can i map a tagged item? Suppose a new book is added to the system, and this book can be non-fictional and cookery related and poetic etc. So more than one tag is required for the added book. And the tags should be created if it does not already exists. And the tag should not be deleted as i delete the book, coz other books may already get associated with this tag.

How can i handle this situation with ORM?

Thanks in advance.


SCJP 1.4, Brainbench
LinkedIn - Blog
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you explain your data model? I've no idea what a tagged item is.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
What i meant by tagged item is like something similar we find on youtube.

ie as we upload a video, we can add search tags related to the uploaded video, like car,movie,comedy etc.

So as user search my tags he can find the item with ease.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So you mean some sort of category entity that the book entity has relationship with? Sounds like a fairly basic data model; books and tags have a many to many relationship, am I right?

So, what are you asking? Are you asking can an ORM tool handle this sort of relationship? Or are you asking what would be ER model look like? Or are you wondering what your object model would look like?
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
yes i am refering to books and tags that have a many to many relationship.

I want to know how this object model should look like, and the way to handle the same using any ORM tool. If anybody can point me any open source example, it will be really helpfull.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

My guess is you would have something like this:

Is this what you are after?
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
Yes i am having exactly similar situation
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So...is that your problem fixed, or am I still not understanding the question?

You did ask this:

and the way to handle the same using any ORM tool

Perhaps you could tell us which ORM tool you are using?
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
Actually i was trying to implement the same on Grails. And in grails, the domain class mapping is based on ideas got from hibernet. I tried hasmany attribute to establish many to many relationship. But i cant actually make things work by this.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, Grails is not an ORM technology per say. But it does use Hibernate, and you do map many-to-many relationships by defining a hasMany on either side of the relationship. Can you show us your code and explain what is going wrong?
[ March 07, 2007: Message edited by: Paul Sturrock ]
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
My domain classes are Book and Tag, which are shown below.



But i am unable to create a link between them. Even though we can add the other domain object from current domain, the link between them is missing.

I have created the controller and stuff, using the "generate-all" method of grails.
Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
Any idea guys?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to map a tagged item?
 
Similar Threads
StarUML - Adding tagged values in deployment diagram
wants to focusing on new added list item.. please help
Mapping a Set in Hibernate.
hashcode and equals question
How to store multiple items into a shopping cart?