hibernate3:unexpected token: order near line 1, column 8
复制内容到剪贴板 程序代码
Session session = HibernateUtil.getSession();
tx = session.beginTransaction();
String hql = "delete KeyWordsVO where id=:NID";
Query query = session.createQuery(hql); //到了这里就异常
query.setInteger("NID", nId);
query.executeUpdate();
tx = session.beginTransaction();
String hql = "delete KeyWordsVO where id=:NID";
Query query = session.createQuery(hql); //到了这里就异常
query.setInteger("NID", nId);
query.executeUpdate();
今天把孙MM的<<精通Hibernate>>里第五章的代码跑了一遍,有一个方法怎么也过不去:
复制内容到剪贴板 程序代码
public void deleteAllObjects(String className) throws Exception{
// Ask for a session using the JDBC information we've configured
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.delete("from " +className);
// We're done; make our changes permanent
// Ask for a session using the JDBC information we've configured
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.delete("from " +className);
// We're done; make our changes permanent
Tags: hibernate3
在session.delete(参数)时有时会出现以下的错误:
org.hibernate.MappingException: Unknown entity: java.lang.String
是因为api中没有提供参数为String的方法
(1)void delete(Object object)
Remove a persistent instance from the datastore.
(2)void delete(String entityName, Object object)
Remove a persistent instance from the datastore.
org.hibernate.MappingException: Unknown entity: java.lang.String
是因为api中没有提供参数为String的方法
(1)void delete(Object object)
Remove a persistent instance from the datastore.
(2)void delete(String entityName, Object object)
Remove a persistent instance from the datastore.
关于load()和get()方式的最新认识,在hibernate3中load取出的值只是一个代理对象,那里除了id之外,没有任何值,比如说下面这段代码:
当使用get()方式时,正常.当使用load()方法时,抛出异常:
深入分析:
在Hibernate中通过主键id取得数据对象有两种方法:
1. get()方法
复制内容到剪贴板 程序代码
UserStatus status = s1.getStatus(Integer.parseInt(statId));
log.info("测试:"+status.getName());
log.info("测试:"+status.getName());
当使用get()方式时,正常.当使用load()方法时,抛出异常:
引用内容
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
深入分析:
在Hibernate中通过主键id取得数据对象有两种方法:
1. get()方法
Tags: hibernate3 load get
hibernate2与hibanete3在lazy的默认值上有区别:2中默认为lazy="false".而三中默认为proxy,我们可以把它看作是true.
异常:
原因:hibernate3 many-to-one的默认选项是 lazy = "proxy"
解决方法:<many-to-one> & <set> 中设置 lazy="false"
异常:
复制内容到剪贴板 程序代码
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
原因:hibernate3 many-to-one的默认选项是 lazy = "proxy"
解决方法:<many-to-one> & <set> 中设置 lazy="false"
Tags: hibernate3