Reputation: 3
Is there any way I could generate a four digit number from the AutoGenerated Id that the entity creates? For example: Person has a unique #1. And I would like to create another number that looks like 1001. Person #130 would be 1130. I don't think my table is going to be over 9999.
Any help would be greatly appreciated. Thanks in advance, Nick
Upvotes: 0
Views: 95
Reputation: 8362
You can create another method inside the entity class that uses the generated Hibernate id, like:
public String getNumber() {
return "#" + Integer.toString(1000 + this.id);
}
The only problem is that you have to save the object first, before this method returns a meaningful value.
Upvotes: 0