Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to map a tagged item?

 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain your data model? I've no idea what a tagged item is.
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is you would have something like this:

Is this what you are after?
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i am having exactly similar situation
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea guys?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic