views:

10

answers:

0

One of the properties in my entity is mapped to bpchar (BLANK PADDED CHAR) string.

@NotNull
@Column(name = "property", columnDefinition = "bpchar")
private String property;

When I save entity and load back, then my property is padded with spaces, that is correct from the database point of view.

But I want to work in code with trimmed values.

Using @PostLoad annotation doesn't help because it is increases version of the entity.

@PostLoad
private void trimProperty(){
    property = property.trim();
}

Another solution is to use custom UserType, but it seems overkill for such simple requirement. Are there any other solutions then to implement custom UserType?