Hello,
> It's difficult to apply the mixins concept to Java. Scala could help
> you to do that. But I'm not sure about the limitations of using scala
> mixins and JPA.
I wanted to avoid Scala because I don't know about the Eclipse support. So I was now looking further at a solution in Java, and seemingly what I need are polymorphic associations in some of my model classes. However, I couldn't find any documentation on how to create them using Hibernate, let alone JPA.
I'd be willing to accept a Hibernate dependency if that's what it takes, but right now I don't see any solution at all.
Basically what I need is this:
interface Taggable
addTag(Tag tag)
removeTag(Tag tag)
Document implements Taggable
@OneToMany
List<Tagging> taggings
addTag(Tag tag) {...}
removeTag(Tag tag) {...}
User implements Taggable
@OneToMany
List<Tagging> taggings
addTag(Tag tag) {...}
removeTag(Tag tag) {...}
Tagging
@ManyToOne
Tag tag
@ManyToOne
Taggable taggable
Tag
@OneToMany
List<Tagging> taggings
The Tagging.taggable @ManyToOne assoiciation is where I run into problems, as JPA seemingly can only create associations to @Entity classes.
Again, any pointers as to how to solve this would be greatly appreciated.
Thanks in advance
Leif
>> I'm thinking about the best way to add generic capabilities to model classes. For example, I might have model classes names "User" and "Bookmark". Now, I want both of these to be "taggable". Later, I might want to add the "likable" capability to one or both of them.
>>
>> I'm looking for a solution in Java that plays nice with JPA.
>>
>> The best solution I've found so far is having the domain classes implement a "Taggable" / "Likable" interface and providing "AbstractTaggable" / "AbstractLikable" skeleton classes that contain default implementations the domain classes can use.
>>
>> Still, in a domain class, I would need to manually create the interface methods and have them use the skeleton classes.
>>
>> Does anyone have a best practice to share that would match this use case?