当我在抽象类中使用它时,忽略@Converter()

时间:2016-12-10 17:27:28

标签: spring jpa converter

我有问题,当我在抽象类中使用@Converter()时会忽略它。

@Entity
@Table(name = "CHALLENGE")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractChallenge implements SecretChallenge {
    ...
    @Convert(converter = InstantConverter.class)
    Instant creationTime;
    ...
}

如果我在标准JPA中使用它,它会按预期工作。

@Entity
public class PasswordResetTokenJPA {
    ...

    @Convert(converter = InstantConverter.class)
    private Instant issuedAt;

    ...
}

这是我的转换器:

@Converter(autoApply = true)
public class InstantConverter implements AttributeConverter<Instant, Timestamp> {

    @Override
    public Timestamp convertToDatabaseColumn(Instant instant) {
        if (instant == null) return null;
        return new Timestamp(instant.toEpochMilli());
    }

    @Override
    public Instant convertToEntityAttribute(Timestamp value) {
        if (value == null) return null;
        return value.toInstant();
    }

}

0 个答案:

没有答案