0

I need implement next logic:

I have entity:

@Data
@Entity
@Table(name = "USERS")
public class User {

    @Id
    @Column(name = "GUID")
    private String guid;

    @Column(name = "MESSAGE_ID")
    private String messageId;

    @Column(name = "SOME_VALUE")
    private String someValue;

And I need set to someValue generated value consisting of

"some prefix"+sequencefrom DB + "some suffix";

I can make select sequense from Db, generate vsomeValue and set it to entity, but maby Is there a way to make it easier? Because in my version I use two bases, and I have to write two native query for select a sequence and use the appropriate one depending on the profile.

I need somthig like this:

    @Column(name = "SOME_VALUE")
    @Value(MyGenerator.class)
    private String someValue;

and in MyGenerator.class implement logic for generate someValue from prefix, sequence and suffix.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ip696
  • 6,574
  • 12
  • 65
  • 128

2 Answers2

0

Instead of annotating the class members, annotate the getters and setters, and put your logic there.

Further reference in this question.

Tu.Ma.
  • 1,325
  • 10
  • 27
0

You are looking for Custom Sequence based ID generator.

This is a nice article on it which might help you.

Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78