I can't think of a good workaround
other than what you have already mentioned, that is, defining the
id on each subclass.
Another solution and perhaps a good
suggestion for the JPA expert group would be to allow this through
an @AttributeOverride, e.g.
@AttributeOverride(
name="id",
generatedValue=@GeneratedValue(strategy
= GenerationType.SEQUENCE, generator = "SEQ_STORE_PROJECT")
)
@SequenceGenerator(name = "SEQ_STORE_PROJECT", sequenceName = "project_id_seq", allocationSize = 1)
class Project extends AbstractDomainObject
@AttributeOverride(
name="id",
generatedValue=@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "SEQ_STORE_USER")
)
@SequenceGenerator(name
= "SEQ_STORE_USER",
sequenceName =
"user_id_seq",
allocationSize
= 1)
class
User extends
AbstractDomainObject
This
maitains the unique
naming
across
the
persistence
unit and
leverages the
existing
attribute override
functionality.
Please enter a
bug against
EclipseLink
though.
Similarly to
Hibernate
which provided
a
feature above
and beyond the
spec, EclipseLink
could do the
same.
Cheers,
Guy
On 05/07/2013 8:39 AM, Andreas Joseph
Krogh wrote:
The exception
refers to
no.officenet.example.rpm.support.domain.model.entities.User. Is
there a SequenceGenerator defined there?
Yes, that's the point; All my Entities inherit from
AbstractDomainObject and define their own SequenceGenerator. I'd
like to be able to have all my Entities inherit from a
@MappedSuperclass (which defines the @Id column with a
@GeneratedValue) and where each child provide provide their own
sequence-name, by using the SequenceGenerator annotation. This
schema works in Hibernate but seems to be against the standard,
which states that the SequenceGenerator's name must be unique
across the PU.
Is there a workaround I can use which lets me use
@GeneratedValue in the @MappedSuperclass and where each child
provide their own sequence-name?
LIke this:
@MappedSuperclass
abstract class AbstractDomainObject {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
var id: java.lang.Long = null
}
@Entity
@Table(name = "project")
@SequenceGenerator(name = "SEQ_STORE", sequenceName = "project_id_seq", allocationSize = 1)
class Project extends AbstractDomainObject
@Entity
@Table(name = "user")
@SequenceGenerator(name = "SEQ_STORE", sequenceName = "user_id_seq", allocationSize = 1)
class User extends AbstractDomainObject
Having to define @Id in each sub-class just to acomplish this
seems unnecessary and is what I'm hoping to avoid.
Thanks.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--

Guy Pelletier
ORACLE Canada,
45 O'Connor Street
Suite 400
Ottawa, Ontario
Canada K1P 1A4
Oracle is committed to developing practices
and products that help protect the environment
|