在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
把程序从hibernate2升级为hibernate3时,遇到的错误.在这里做一小节:
一:INFO [STDOUT] 03:30:37,640 ERROR [DTDEntityResolver] Don't use old DTDs, read the Hibernate 3.x Migration Guide!
程序里原来的映射文件(.hbm.xml)原来以:
开头。
需要修改为:
一:INFO [STDOUT] 03:30:37,640 ERROR [DTDEntityResolver] Don't use old DTDs, read the Hibernate 3.x Migration Guide!
程序里原来的映射文件(.hbm.xml)原来以:
复制内容到剪贴板 程序代码
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
需要修改为:
复制内容到剪贴板 程序代码
<?xml version="1.0" encoding="utf-8"?>
Tags: hibernate3
public class HibernateSessionFactory {
private static SessionFactory sessionFactory;
public synchronized static Session openSession_db1() throws HibernateException {
if (sessionFactory == null) {
init_db1();
}
return sessionFactory.openSession();
}
private static SessionFactory sessionFactory;
public synchronized static Session openSession_db1() throws HibernateException {
if (sessionFactory == null) {
init_db1();
}
return sessionFactory.openSession();
}
Tags: 多数据库