I have two entity class Category and Events.I need to join both the tables and fetch all records which matching the given condition
Hibernate is about mapping objects and the relations, however you are mapping simple id fields.
In your Events
class you have the followingL
@Entity
@Table(name = "events")
public class Events implements Serializable {
@Column(name = "category_i")
private Integer categoryI;
}
However it should be a Category
instead of an Integer
.
@Entity
@Table(name = "events")
public class Events implements Serializable {
@ManyToOne
@Column(name = "category_i")
private Category category;
}
Then in your Category
you should add the mappedBy
field to the @ManyToOne
on the events
field and remove the @JoinColumn
.
@Entity
@Table(name = "category")
public class Category implements Serializable {
@OneToMany(mappedBy="category")
private Events events;
}
The same applies to the parentCategoryId
of the Category
class.
Now that you have your mapping corrected you should be able to write the query as you wanted to.