异常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>
异常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>
2、sqlserver 有这个命令 concat?
你加载数据时候 数据库中是否有id为1 的这个对象啊,如果没有可能有异常,对于load方法。
<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>
你没有说明对应的列