I have two model classes in a Spring web application:
User.java:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class User implements Serializable {
@Id
private String username;
private String password;
private String email;
}
Client.java:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@IdClass(User.class)
public class Client {
@Id
@OneToOne
@JoinColumn(name = "username")
private User user;
private String firstName;
private String lastName;
private String phoneNumber;
private String address;
}
And a repository ClientRepository:
@Repository
public interface ClientRepository extends JpaRepository<Client, User> {}
When I run the application I get the following error:
This class [class com.example.auction.models.Client] does not define an IdClass
What is the reason for that? I used the IdClass annotation in Client class.
New contributor
Maorkale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.