1

Below is an example of how I am defining my JPA entity. I am a bit confused on how to have both the object and the foreign key specified for ApplicationUser. I initially just had the ApplicationUser user property, but then realized I want to be able to query on the applicationUserId by defining a method in the ProductRepository such as findByApplicationUserId(long applicationUserId) and the repo keeps saying field does not exist. This is why I tried adding an applicationUserId property to the class and now there appears to be interference when running the application.

@Entity
public class Product{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    private String name;
    private long applicationUserId;

    @ManyToOne
    @JoinColumn(name = "application_user_id")
    private ApplicationUser user;
}
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231

0 Answers0