How to override @GeneratedValue declared in a mapped superclass?

We have one @MappedSuperclass class Entitythat defines the default identifier and generator:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Override
public K getId() {
    return id;
}

I want to not use the generator at all in the subclass Foo, because I myself provided the primary key.

I have to extend Foofrom a base class Entity, because many, many functions depend on this base class. Annotation @AttributeOverridesdoes not seem to support cancellation @GeneratedValue.

+5
source share
1 answer

, Foo Entity . - . -, .

, Foo , Entity. @Id, , Id Foo , Id Entity.

.

Entity entity = new Foo();
if (entity instanceof Foo) {
  //we have a Foo object
} else if( entity instanceof ...) {
  //we have a ...
}

, . , , , @Embedded.

0

All Articles