-->
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.  [ 1 post ] 
Author Message
 Post subject: Suggestions for implementing a comment feature
PostPosted: Fri Oct 30, 2009 9:42 am 
Newbie

Joined: Fri Oct 30, 2009 9:21 am
Posts: 2
Hi,
I want to add the ability to attach comments to any entity in my system and I'd like to try and do it in a generic way. My initial thought was to create an entity comment table with these columns

-UserId //user id
-EntityId //entity id
-EntityType // in case entity id not unique for everything
-Comment //text comment
-Timestamp //comment timestamp

The table has no PK and the lifecycle of a comment is defined by its owning entity, so I would declare the collection of comments on my entity base class using

Code:
@CollectionOfElements
@JoinTable(name="`EntityComment`", joinColumns = @JoinColumn(name="`EntityId`"))
private List<EntityComment> comments=new ArrayList<EntityComment>();


This works but (not suprisingly) doesn't include the EntityType column during the join.

Most of my entities have unique ids across the entire DB but I'd rather not require it (hence the addition of the 'EntityType' column). It is easy enough to manage the values in the 'EntityType' column as comments are created, but how can I get hibernate to include 'EntityType' in the join when it retrieves the comment list for an entity. I looked at using @Where(..) but I don't know the entity type at compile time since I'm declaring the collection using an annotcation in my entity base class. Is there a special keyword I can use in the @Where clause to refer to this entities type? Something like @Where(clause="`EntityType`=this.class")?

I have a feeling I may be SOL here, so I'd appreciate other suggestions for implementing this mechanism as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.