I run sql statement "SELECT * FROM company" on oracle Thin 11 g and it returns 3 rows.
I have configured the data source correctly and tried Query as well Criteria as follows and all of them return nothing even if they should return 3 rows. //import org.hibernate.Criteria;
1. Criteria
Criteria criteria = session.createCriteria(Company.class);
criteria
.add(Restrictions.eq("companyName", companyName))
.add(Restrictions.eq("companyId", companyId));
List<Company> companyList = criteria.list();//**THIS RETURNS 0 ROWS**
2. QUERY
Query query=session.createQuery("from Company where companyName= :companyName and companyId= :companyId");
query.
setParameter("companyId",companyId).
setParameter("companyName", companyName);
List<Company> companyList = query.list();//**THIS RETURNS 0 ROWS**
3.SQL in Query
Query query=session.createSQLQuery("SELECT * FROM Company");
List<Company> CompanyList = query.list();//**THIS RETURNS 0 ROWS**
Here Company Entity
//javax.persistence.*;
@Entity
@Table(name = "COMPANY")
public class Company {
@Id
@GeneratedValue(strategy= GenerationType.SEQUENCE, generator="COMPANY_SEQ")
@SequenceGenerator(name="COMPANY_SEQ", sequenceName="COMPANY_SEQ", allocationSize=1)
@Column(name = "COMPANY_ID")
int CompanyId;
@Basic
@Column (name ="COMPANY_NAME")
private String companyName;
@Basic
@Column (name ="COMPANY_ID")
private Integer companyId;// The login id of user whose data is updated
@Basic
@Column (name ="UPDATED_BY")
private String updatedBy;
@Basic
@Column (name ="UPDATE_DATE")
private Date updateDate;
//Default no-arg constructor and another constructor with all the fields.
//default getters and Setters
}
What am I missing and why is not all the hibernate queries not returning the rows? I appreciate your help.
commit;in SQL developer to be sure.