Reputation: 3899
i would use a ModelBase with an ID and a Timestamp for every class/entity. But when i user the Long
type for the Primary Key in the JPARepository<>
interface i get the message
Not an entity: class java.lang.Long
Code:
@MappedSuperclass
public class ModelBase implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false, columnDefinition = "datetime")
private Date lastModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
@PreUpdate
@PrePersist
public void updateLastModified() {
lastModified = new Date();
}
}
Modelclass inheritanced from Modelbase
@Entity
@Table(name = "Name")
public class Name extends ModelBase implements Serializable {}
Repo
public interface NameRepository extends JpaRepository<Long, Name>{}
what am i doing wrong?
thanks
Upvotes: 0
Views: 370
Reputation: 8582
It's backwards:
JpaRepository<Name, Long>
First the entity, then the ID. Check JPARepository javadoc.
Upvotes: 3