I've got the following piece of code:
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import java.io.Serializable;
@Data
@RequiredArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
@Id
@GeneratedValue
private final String id = null; // there's Long data type originally
@Version
private Long version;
}
If I run it, I get:
Caused by: org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String
If I remove a @GeneratedValue
annotation I still get:
Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()
The problem is that my object may contain string values under id
field so I want to change Long
to String
.