I have an entity with the field called createTimestamp. This is created by the database when it is inserted. The getter looks like this:
@Column(name = "create_timestamp", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false)
public ZonedDateTime getCreateTimestamp() {
return createTimestamp;
}
However, when my service calls the dao (spring repository) to create the entity, the create timestamp is null.
My dao method to create:
@Override
public int insert(AntennaSpec antennaSpec) {
super.save(antennaSpec);
logger.info("Antenna Spec " + antennaSpec.getAntennaCode() + " created");
return antennaSpec.getAntennaSpecId();
}
My REST resource class calls the service to create the entity by calling the create method. The method returns the id of the newly created entity. In the resource, I then call my service to return the entity passing the id and yet the create timestamp is null. What i have done to get this to populate is in my resource, i've detached the entity and then fetch the entity again. That works but I don't like exposing detach
to my service or resource classes.
Any help would be appreciated.