Reputation: 19
I m using hiberntate table per subclass inheritance concept. Here is my sample code
@Entity
@Table
@Inheritance(strategy = InheritanceType.JOINED)
public class Payment{
@Id
@Column
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column
private double amount;
}
@Entity
@Table
@PrimaryKeyJoinColumn(name = "payment_id")
public class CreditCard extends Payment{
@Column
private String CreditCardType;
}
Here while getting the Child class by it's parent id, i am getting the exception like Unknown column 'this_.id' in 'where clause'. My query is
List<CreditCard> creditCardList =
getSessionFactory().getCurrentSession().createCriteria(CreditCard.class,
"card").add(Restrictions.eq("card.id", id)).list();
Upvotes: 0
Views: 1147
Reputation: 1021
In your parent class the Identifier property is named as id
but in child class you are mapping the PrimaryKeyJoinColumn
with payment_id
. As per your comment I believe you have same names for properties and columns.
Change the column name to id
instead of payment_id
as below and it should work.
@PrimaryKeyJoinColumn(name = "id")
Upvotes: 1
Reputation: 13835
Change your child entity class as follows:
@Entity
@Table
@PrimaryKeyJoinColumn(name = "id")
public class CreditCard extends Payment{
@Column
private String CreditCardType;
}
Refer to following link for the same also: http://www.javatpoint.com/hibernate-table-per-subclass-using-annotation-tutorial-example
Upvotes: 0