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

unexpected token: order near line 1, column 8

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();

查看更多...

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

hibernate:Not supported for select queries

内置方法:
private void errorIfSelect() throws HibernateException {          
  if ( !sqlAst.needsExecutor() ) {
       throw new HibernateException( "Not supported for select queries" );            
   }                
}

查看更多...

Tags: hql hibernate

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

Hibernate3:Unknown entity: java.lang.String

今天把孙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

查看更多...

Tags: hibernate3

分类:Hibernate | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 1694
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 | 查看次数: 2196
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 | 查看次数: 830
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 | 查看次数: 1609