Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

java - How to use spring Repository without @Id?

I'm using spring CrudRepository throughout my application. Now I want to also create one for an @Entity that does not have an @Id. Is that possible at all?

//probably ID is always required?
public interface Repository<T, ID extends Serializable>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

JPA requires that every entity has an ID. So no, entity w/o an ID is not allowed.

Every JPA entity must have a primary key.

from JPA spec

You may want to read more about how JPA handles a case when there's no id on the DB side from here (see 'No Primary Key').


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...