本文介绍了基本Hibernate选择所有语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用hibernate从数据库检索数据,但它仍然引发异常

I am trying to retrieve data from my database with hibernate but it keeps throwing an exception



@Override
public List<Trade> requestPeriod() {
    List<Trade> trades = null;
    EntityManager manager = emf.createEntityManager();
    Query query = manager.createQuery("from trade"); 
    try{
        trades = query.getResultList();
    }
    catch(PersistenceException e){
        logger.error("there was an error " + e);
    }
    catch(SQLGrammarException e){
        logger.error("there was an error " + e);
    }
    return trades;
}



我猜我使用的语法 select

I am guessing the syntax I am using for select all is incorrect but after looking around I can not see an alternative?

感谢

推荐答案

应该是来自Trade(大写T),因为Trade是映射类的名称。

It should be "from Trade" (uppercase T) as Trade is the name of the mapped class.

这篇关于基本Hibernate选择所有语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 03:20