Reputation: 347
With the query Select c from Card c join User u on c.userId=u.userId where u.username=':u'
, I am trying to grab a list of Cards for the User based on the username available in User the table. However, I am running into the antlr.SemanticException: could not resolve property: userId of: com.abc.SheridanSportsWAR.entity.Card
exception when I run it. How do I reference the UserId
column in my Card
entity?
Card.java
@Entity
public class Card {
@Id
@Column(name="CardId")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer cardId;
@Column(name="CardNumber")
private String cardNumber;
@Column(name="CardType")
private String cardType;
@Column(name="ExpiryMonth")
private String expiryMonth;
@Column(name="ExpiryYear")
private String expiryYear;
@Column(name="CardHolder")
private String cardHolder;
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST, CascadeType.REFRESH})
@JoinColumn(name = "UserId")
private User userJ;
@OneToMany(mappedBy = "cardJ")
private List<Purchase> purchases;
User.java
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="UserId")
private Integer userId;
@Column(name="FirstName")
private String firstName;
@Column(name="LastName")
private String lastName;
@Column(name="Email")
private String email;
@Column(name="Username")
private String username;
@Column(name="Password")
private String password;
@Column(name="RoleName")
private String roleName;
@OneToMany(mappedBy="userJ", cascade= CascadeType.ALL)
private List<Card> cards;
Upvotes: 0
Views: 1346
Reputation: 7230
AFAIK, the problem seems to be that there's no userId
column in the card
table.
Upvotes: 0
Reputation: 26026
The error message is pretty clear. There is no field userId
in your Card
entity. Create one like that:
@Column(name = "UserId", insertable=false, updatable=false)
private Integer userId;
Upvotes: 3