日期:2014-05-19  浏览次数:20645 次

Unknown column 'story0_.hero_id' in 'field list'
总是出现这种状况求大神指导
public class Story {
private Hero hero;
private String id;
private String story;
private int status;
private User user;
}
public class Hero {
  private String id;
private String name;
private int status;
private User user;
private String times;
}
Dao层函数[code=Java][/code]public List<Story> findByHero(String heroName) {
System.out.println(heroName);
// TODO Auto-generated method stub
String queryString="from Story as st where st.hero.name='"+heroName+"'";
List<Story> storyList=hibernateTemplate.find(queryString);
if(storyList!=null&&storyList.size()>0){
System.out.print(storyList.get(0).getStory());
return storyList;
}
else{
return null;
}
}
Action层
  public String showStory(){
  storyList=storyService.showStory(heroName);
  if(storyList.size()>0&&storyList!=null){
  return SUCCESS;
  }
  else{
  return ERROR;
  }
  }
Struts Problem Report
Struts has detected an unhandled exception: 

Messages: Unknown column 'story0_.hero_id' in 'field list' 
could not execute query 
could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query  


------解决方案--------------------
检查一下数据库中是否有'story0_.hero_id'这个字段,还是映射文件中写错了!
------解决方案--------------------
你映射文件中写错了,
hero_id 没有这个字段
------解决方案--------------------
那就是注解的地方写错了呗
------解决方案--------------------
String queryString="from Story as st where st.hero.name='"+heroName+"'";

我真的很难看出来你上面的STORY和HERO有什么关系,如果你STORY表中的HERO是HERO表中的ID那就应该是这样啊
SQL code
SELECT * FROM STORY A LEFT JOIN HERO B ON A.HERO = B.ID WHERE B.NAME = '"+heroName+"'";