异常1   org.hibernate.exception.SQLGrammarException: could not load an entity: [lee.News#1]
异常2   com.microsoft.sqlserver.jdbc.SQLServerException: 'concat' 不是可以识别的 内置函数名称。
存入数据的时候没有问题。但是读取数据的时候就有问题了
public class NewsManager {
public static void main(String[] args)throws Exception{
Configuration conf=new Configuration().configure();
SessionFactory sf=conf.buildSessionFactory();
Session sess=sf.openSession();
Transaction tx=sess.beginTransaction();
/*
News n=new News();
n.setTitle("疯狂的斤斤计较");
n.setContent("焦点房金额");
sess.save(n);
*/
News n2=(News)sess.get(News.class, 1);
System.out.println(n2.getFullContent());
tx.commit();
sess.close();
}
下面是配置文件
<class name="News" table="news_table">
<id name="id" unsaved-value="null">
<generator class="identity"></generator>
</id>
<property name="title" not-null="true"></property>
<property name="content"></property>
<property name="fullContent" formula="(select concat(nt.title,nt.content) from new_table nt where nt.id=id)"></property> </class>

解决方案 »

  1.   

    1、检测一下配置看下
    2、sqlserver  有这个命令 concat?
      

  2.   

    可能是我用Hibernate的时间短,不过在配置文件里写SQL语句我还是第一次看见。
      

  3.   

    关注中,
    你加载数据时候 数据库中是否有id为1 的这个对象啊,如果没有可能有异常,对于load方法。
      

  4.   

    我突然想到作者好像用的是mysql但是formula="(select concat(nt.title,nt.content) from new_table nt where nt.id=id)"这个应该是hsql语句吧。。应该没有影响吧。但是异常好像有说不支持这个函数。。那么sql中相对concat的函数到底是什么呢
      

  5.   

    你的配置文件应该不对,声明类的名称的时候也要声明相对应的列名
          <property name="sync_sign" lazy="false">
             <column name="sync_sign" length="1"/>
          </property>
          <property name="sync_error_desc" lazy="false">
             <column name="sync_error_desc" length="1000"/>
          </property>
    你没有说明对应的列