hibernate本来就支持 原sql 调用执行sql的方法就行了 调用方法的时候注意看所需的参数
@Autowired
private SessionFactory sessionFactory;
sessionFactory.getCurrentSession().createSQLQuery(sql);
这样就可以了
不要配什么的。
就session.createSQLQuery(sql)就可以。。
错误是报的hql解析问题。
hql不是sql,你搞混了。
hibernate中的hql是以对象的形式来写的,你直接的sql肯定是不行的。
hql中,from不是表或者数据集,是用类或集合。
好好去看看hql应该怎么写。
不需要什么配置了,hibernate中有原生sql查询
Session session =null;
try{
session = hibernator.getSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
}catch(Exception e){
e.printStackTrace();
session.getTransaction().rollback();
}finally{
hibernator.closeSession(session);
}
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....