2012-11-21 4 views
0

나는 최대 절전 모드를 배우고 있으며, 내 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 이 문제에서 제로가 될 수 없으므로 도움이 필요하십니까?

+1

엔티티 클래스를 게시 할 수 있습니까? – invariant

+0

올바른 데이터베이스를 가리키고 있습니까? –

+0

올바른 DB를 가리키고 있는지 확인하십시오. 최대 절전 모드를 사용하여 새 레코드를 삽입했습니다. 그리고 올바르게 작동했습니다. –

답변

2

동일한 문제가있었습니다. 쿼리를 작성하고 데이터를 인쇄 한 후 커밋하기 전에 트랜잭션을 시작하여 문제를 해결했습니다. 왜 데이터베이스를 쿼리하기 위해 트랜잭션이 필요한지 모르겠습니다.

+0

덕분에, 나는'session.beginTransaction(). commit()'을 추가하기 전에 쿼리를 만들고 그 문제를 해결했다. 나는 이유를 묻지 않는다, 나는 미래 프로젝트에서 더 이상 최대 절전 모드를 사용하지 않는 경향이있다. – benez

관련 문제