Motivation
My app makes requests to some web service based on contents of table foo. I would like to log those requests (in a data base) as well as value of row of foo, which was used to make them. Still, as data in table foo can change over time, I need to log exact contents of row (rather then its id). I am using Hibernate so I thought, I could embed row of foo in entity representing request. To have clean class hierarchy I would like to have something like this:
class Foo
{
/*
* Here goes some properties of Foo, which specify columns names etc.
*/
}
@Embeddable
class EmbeddableFoo extends Foo
{
//EmbeddableFoo should have the same properties as Foo
}
@Entity
class EntityFoo extends Foo
{
@Id
Long getId() { //EntityFoo has some id }
//EntityFoo should have the same properties as Foo, except that
//it has id
}
Problem
This will not work, because EmbeddableFoo doesn't see properties of Foo. I can add @Inheritance annotation over Foo, so that EntityFoo *sees* properties of Foo, but it will not solve my problems with EmbeddableFoo
Question
Is there an easy (i.e. not requiring to write a lot of redundant code) way to have @Embeddable and @Entity* inherit from the same class?