分类: Hibernate预览模式: 普通 | 列表
08-06
02

org.hibernate.MappingException: Unknown entity: java.lang.String

在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.

查看更多...

Tags: Exception Unknown

分类:Hibernate | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2193
08-06
02

Hibernate3中通过主键id取得数据对象

关于load()和get()方式的最新认识,在hibernate3中load取出的值只是一个代理对象,那里除了id之外,没有任何值,比如说下面这段代码:
UserStatus status = s1.getStatus(Integer.parseInt(statId));
log.info("测试:"+status.getName());

当使用get()方式时,正常.当使用load()方法时,抛出异常:
引用内容 引用内容
org.hibernate.LazyInitializationException: could not initialize proxy - no Session


深入分析:
在Hibernate中通过主键id取得数据对象有两种方法:
1. get()方法

查看更多...

Tags: hibernate3 load get

分类:Hibernate | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 828
08-06
02

could not initialize proxy - no Session

hibernate2与hibanete3在lazy的默认值上有区别:2中默认为lazy="false".而三中默认为proxy,我们可以把它看作是true.
异常:
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)


原因:hibernate3 many-to-one的默认选项是 lazy = "proxy"
解决方法:<many-to-one>  & <set> 中设置 lazy="false"

查看更多...

Tags: hibernate3

分类:Hibernate | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 1606
08-06
02

hibernate版本升级问题小节

把程序从hibernate2升级为hibernate3时,遇到的错误.在这里做一小节:
一: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">
开头。
需要修改为:
<?xml version="1.0" encoding="utf-8"?>

查看更多...

Tags: hibernate3

分类:Hibernate | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 1130
08-05
08

hibernate中使用多数据库

public   class   HibernateSessionFactory   {  
          private   static   SessionFactory   sessionFactory;  
    
          public   synchronized   static   Session   openSession_db1()   throws   HibernateException   {  
                  if   (sessionFactory   ==   null)   {  
                          init_db1();  
                  }  
                  return   sessionFactory.openSession();  
          }  

查看更多...

Tags: 多数据库

分类:Hibernate | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 616
08-03
26

SQL insert, update or delete failed (row not found) 新解

这种错误多数在update时出现,在这里如果user的主建为空的时候,就insert,如果有主键的时候才update,不然没有主键,Hibernate没有依据来更新

Tags: row not found failed update

分类:Hibernate | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 946