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.
Instead of annotating the class members, annotate the getters and setters, and put your logic there.
Further reference in this question .
You are looking for Custom Sequence based ID generator .
This is a nice article on it which might help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.