I want to create many-one mapping between two tables, Expense (ID, NAME, CATEGORY) and Category (ID, NAME). In my class, I created the Category Category field and its setters and getters. I made them by seeing some things from the Internet. What changes should I make in my Category.java class. So far it looks
public class Category{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int catId;
private String catName;
public Category() {
}
public int getCatId() {
return this.catId;
}
public void setCatId(int catId) {
this.catId = catId;
}
public String getCatName() {
return this.catName;
}
public void setCatName(String catName) {
this.catName = catName;
}
}
I do not want to make comparisons with xml config. I think annotations are good for a newbie like me.
And my old one! The SQL query looks like this:
SELECT EXPENSES.EXPNS_ID, EXPENSES.CAT_ID, EXPENSES.NAME, CATEGORY.CAT_NAME FROM EXPENSES INNER JOIN CATEGORY ON EXPENSES.CAT_ID = CATEGORY.CAT_ID WHERE USER_NAME="+currentUserName
How to use internal join in hibernate?
Any suggestions!!
Thank!
Update
Thanks to all the defendants, I tried what you said and returns an empty list.
, 'userName = Tamil', .
, Hibernate, ,
select expens0_.expnsId as expnsId1_, expens0_.catId as catId1_, expens0_.category_catId as category7_1_, expens0_.userName as userName1_ from Expens expens0_ inner join Category category1_ on expens0_.category_catId=category1_.catId where expens0_.userName=?
, JPQL, catName Category[catId, catName] . catId Expens[expnsId, catId, userName].
Expens.java, catName Expens.
@ManyToOne
private Category category
. , , . , , .
pascal: Query query = hSession.createQuery("SELECT e FROM Expens e JOIN e.category c WHERE e.userName = :userName").setParameter("userName", userName);
, , , SQl. .