0

I have a base class:

@MappedSuperclass
public abstract class SuperClass{
    @Id
    protected Long id;

    public Long getId() {
        return id;
    }
}

The @GeneratedValue is not used since the id is generated using a BackendSession

There are a lot of inheritance from this class so one can't change it!

my sub class: I tried to override the getId method

@Entity
@Table(name = "FTC_DATA")
@SequenceGenerator(name="sequence", sequenceName = "FTC_DATA_SEQ")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class SubClass extends SuperClass {

    @Override
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FTC_DATA_SEQ")
    public void getId(Long id) {
        this.id = id;
    }
}

But I fail on IdentifierGenerationException, what am I doing wrong?

2

1 Answer 1

0

Here's what worked for me. Remove getId() from SuperClass, remove the @Override from SubClass getId() and move the @Id annotation to the SubClass getId().

Sign up to request clarification or add additional context in comments.

5 Comments

It may solve the problem.However, if the id is used in other subclasses, by removing it from the superclass you break all other subclasses.
I have a total of 6 subclasses and this is not a problem.
Just to clarify. The ID attribute is not removed, just the getter.
Ah, OK. Should it work to move the @Id to the method in the super class?
I have @Id in the subclasses. If I remember correctly it didn't work when it was in the superclass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.