나는 최대 절전 모드를 배우고 있으며, 내 SQL에서 테이블을 읽는 간단한 프로그램을 만들었다.
테이블에 14 개의 레코드가 있어도 쿼리를 실행 한 결과 목록의 크기가 0입니다.
나는 SQL 로그를 볼 수 show_sql을했고 나는이 무엇입니까 :
Hibernate 질의 결과가 비어있다.
public class Insurance {
private long lngInsuranceId;
private String insuranceName;
private int investementAmount;
private Date investementDate;
public long getLngInsuranceId() {
return lngInsuranceId;
}
public void setLngInsuranceId(long lngInsuranceId) {
this.lngInsuranceId = lngInsuranceId;
}
public String getInsuranceName() {
return insuranceName;
}
public void setInsuranceName(String insuranceName) {
this.insuranceName = insuranceName;
}
public int getInvestementAmount() {
return investementAmount;
}
public void setInvestementAmount(int investementAmount) {
this.investementAmount = investementAmount;
}
public Date getInvestementDate() {
return investementDate;
}
public void setInvestementDate(Date investementDate) {
this.investementDate = investementDate;
}
: 나는 또한 참조
Session session = new Configuration().configure("Hibernate.cfg.xml").buildSessionFactory().openSession();
String SQL_QUERY ="from Insurance insurance";
Query query = session.createQuery(SQL_QUERY);
System.out.println("size of list is: "+query.list().size());
List resultList = query.list();
for (Iterator iterator = resultList.iterator(); iterator.hasNext();) {
Insurance object = (Insurance) iterator.next();
System.out.println("insurance name is: "+object.getInsuranceName());
System.out.println("insurance amount is: "+object.getInvestementAmount());
}
session.close();
엔티티 클래스를 코드를 부착하고
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select insurance0_.lngInsuranceId as col_0_0_ from insurance insurance0_
}
Ple 이 문제에서 제로가 될 수 없으므로 도움이 필요하십니까?
엔티티 클래스를 게시 할 수 있습니까? – invariant
올바른 데이터베이스를 가리키고 있습니까? –
올바른 DB를 가리키고 있는지 확인하십시오. 최대 절전 모드를 사용하여 새 레코드를 삽입했습니다. 그리고 올바르게 작동했습니다. –