JiveJdon Community Forums
在线193人   首页   主题表   培训咨询   标签   精华   查搜   注册    登陆 RSS
首页 » 论坛 » J2EE/JavaEE/JEE/EJB/JSF等技术讨论
???en_US.forumThreadPrev.name??? 上一主题
google yahoo 365Key网摘 CSDN网摘 添加到百度搜藏 POCO网摘 新浪ViVi 天极网摘
???en_US.forumThreadNext.name??? 下一主题
Go 共有 6 回复 / 1
 发表新帖子   回复该主题贴
ax3536

悄悄话
发表文章: 21
注册时间: 2003年04月12日 20:18
Hibernate Blob 操作问题! 2003年08月25日 15:54 到本帖网址 加入本帖到收藏夹 回复该主题
标签
数据库是ORACLE8.15,现在现象是好像一切都正常,日志也正常,可是数据库中始终没有数据,大大帮帮忙阿!

对应的JAVA文件和HBM如下

package com.sunix;

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import java.sql.Blob;
/** @author Hibernate CodeGenerator */
public class Blobtest implements Serializable {

/** identifier field */
private String bid;

/** nullable persistent field */
private Blob bcontent;

/** full constructor */
public Blobtest(Blob bcontent) {
this.bcontent = bcontent;
}

/** default constructor */
public Blobtest() {
}

public java.lang.String getBid() {
return this.bid;
}

public void setBid(java.lang.String bid) {
this.bid = bid;
}

public Blob getBcontent() {
return this.bcontent;
}

public void setBcontent(Blob bcontent) {
this.bcontent = bcontent;
}

public String toString() {
return new ToStringBuilder(this)
.append("bid", getBid())
.toString();
}

public boolean equals(Object other) {
if ( !(other instanceof Blobtest) ) return false;
Blobtest castOther = (Blobtest) other;
return new EqualsBuilder()
.append(this.getBid(), castOther.getBid())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getBid())
.toHashCode();
}

}

<?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">
<hibernate-mapping>
<class name="com.sunix.Blobtest" schema="LIUXU" table="BLOBTEST">
<id column="BID" name="bid" type="string">
<generator class="uuid.string"/>
</id>
<property column="BCONTENT" name="bcontent" type="blob"/>
</class>
</hibernate-mapping>

管理SESSION的那个就不贴了,是从LIFERAY里COPY出来的
下面这个是用来写Blob的类
package com.sunix;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.*;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import com.sunix.Blobtest;
import com.sunix.hibernate.*;

public class testBlob {
private Session session=null;
public testBlob() {
}
public void add(String _content){
try{
session=hibernatesession.openSession();
Blobtest bt=new Blobtest();
//之所以这么写BLOB是因为我在Hibernate的TEST的原码中看到的
bt.setBcontent(Hibernate.createBlob(_content.getBytes()));
session.save(bt);
session.flush();
}catch(Exception ex){
ex.printStackTrace();
System.out.println(ex.getMessage());
}
finally {
Hibernatesession.closeSession(session);
}

}
}

日志:

2003-8-25 15:51:44 net.sf.hibernate.cfg.Environment <clinit>

信息: using java.io streams to persist binary types

2003-8-25 15:51:44 net.sf.hibernate.cfg.Environment <clinit>

信息: using CGLIB reflection optimizer

2003-8-25 15:51:44 net.sf.hibernate.cfg.Environment <clinit>

信息: JVM proxy support: true

2003-8-25 15:51:44 net.sf.hibernate.cfg.Configuration addClass

信息: Mapping resource: com/sunix/Blobtest.hbm.xml

2003-8-25 15:51:45 net.sf.hibernate.cfg.Binder bindRootClass

信息: Mapping class: com.sunix.Blobtest -> BLOBTEST

2003-8-25 15:51:46 net.sf.hibernate.cfg.Configuration secondPassCompile

信息: processing one-to-many association mappings

2003-8-25 15:51:46 net.sf.hibernate.cfg.Configuration secondPassCompile

信息: processing one-to-one association property references

2003-8-25 15:51:46 net.sf.hibernate.cfg.Configuration secondPassCompile

信息: processing foreign key constraints

2003-8-25 15:51:46 net.sf.hibernate.impl.SessionFactoryImpl <init>

信息: building session factory

2003-8-25 15:51:46 net.sf.hibernate.dialect.Dialect <init>

信息: Using dialect: net.sf.hibernate.dialect.OracleDialect

2003-8-25 15:51:46 net.sf.hibernate.cfg.SettingsFactory buildSettings

信息: Use outer join fetching: true

2003-8-25 15:51:46 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

信息: Hibernate connection pool size: 20

2003-8-25 15:51:47 net.sf.hibernate.cfg.SettingsFactory buildSettings

信息: Use scrollable result sets: true

2003-8-25 15:51:47 net.sf.hibernate.cfg.SettingsFactory buildSettings

信息: JDBC 2 max batch size: 15

2003-8-25 15:51:47 net.sf.hibernate.cfg.SettingsFactory buildSettings

信息: echoing all SQL to stdout

2003-8-25 15:51:47 net.sf.hibernate.cfg.SettingsFactory buildSettings

信息: Query language substitutions: {}

2003-8-25 15:51:47 net.sf.hibernate.ps.PreparedStatementCache <init>

信息: prepared statement cache size: 6

2003-8-25 15:51:48 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance

信息: no JNDI name configured

Hibernate: insert into ll.BLOBTEST (BCONTENT, BID) values (?, ?)

ax3536

悄悄话
发表文章: 21
注册时间: 2003年04月12日 20:18
Re: Hibernate Blob 操作问题! 2003年08月25日 15:56 到本帖网址 加入本帖到收藏夹 回复该主题
为什么看不到XML?再贴:
<class name="com.sunix.Blobtest" schema="LIUXU" table="BLOBTEST">
<id column="BID" name="bid" type="string">
<generator class="uuid.string"/>
</id>
<property column="BCONTENT" name="bcontent" type="blob"/>
</class>
ax3536

悄悄话
发表文章: 21
注册时间: 2003年04月12日 20:18
Re: Hibernate Blob 操作问题! 2003年08月25日 15:56 到本帖网址 加入本帖到收藏夹 回复该主题
为什么看不到XML?再贴:
<class name="com.sunix.Blobtest" schema="ll" table="BLOBTEST">
<id column="BID" name="bid" type="string">
<generator class="uuid.string"/>
</id>
<property column="BCONTENT" name="bcontent" type="blob"/>
</class>
ax3536

悄悄话
发表文章: 21
注册时间: 2003年04月12日 20:18
Re: Hibernate Blob 操作问题! 2003年08月25日 15:58 到本帖网址 加入本帖到收藏夹 回复该主题
<property column="BCONTENT" name="bcontent" type="blob"/>
其他不管了,这个是关键部分,看看能显示不?
ax3536

悄悄话
发表文章: 21
注册时间: 2003年04月12日 20:18
Re: Hibernate Blob 操作问题! 2003年08月25日 15:59 到本帖网址 加入本帖到收藏夹 回复该主题
我555~什么论坛阿,又不能编辑,又不能删除,XML贴上来怎么也看不到
robbin

悄悄话
发表文章: 589
注册时间: 2003年06月18日 09:32
Re: Hibernate Blob 操作问题! 2003年08月25日 16:34 到本帖网址 加入本帖到收藏夹 回复该主题
http://hibernate.bluemars.net/56.html
ax3536

悄悄话
发表文章: 21
注册时间: 2003年04月12日 20:18
Re: Hibernate Blob 操作问题! 2003年08月25日 17:07 到本帖网址 加入本帖到收藏夹 回复该主题
我真弱阿,其实到了Hibernate里面,操作ORACLE的BLOB和CLOB应该是跟JDBC一样的步骤,
1。建立一个新的空记录;
2.加入内容

可是你看他TEST里的例子
public void testBlobClob() throws Exception {

if ( dialect instanceof MySQLDialect || dialect instanceof PostgreSQLDialect || dialect instanceof HSQLDialect ) return;

Session s = sessions.openSession();
Blobber b = new Blobber();
b.setBlob( Hibernate.createBlob( "foo/bar/baz".getBytes() ) );
b.setClob( Hibernate.createClob("foo/bar/baz") );
s.save(b);
//s.refresh(b);
//assertTrue( b.getClob() instanceof ClobImpl );
s.flush();
s.refresh(b);
//b.getBlob().setBytes( 2, "abc".getBytes() );
b.getClob().getSubString(2, 3);
//b.getClob().setString(2, "abc");
s.flush();
s.connection().commit();
s.close();

s = sessions.openSession();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
Blobber b2 = new Blobber();
s.save(b2);
b2.setBlob( b.getBlob() );
b.setBlob(null);
//assertTrue( b.getClob().getSubString(1, 3).equals("fab") );
b.getClob().getSubString(1, 6);
//b.getClob().setString(1, "qwerty");
s.flush();
s.connection().commit();
s.close();

s = sessions.openSession();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
b.setClob( Hibernate.createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") );
s.flush();
s.connection().commit();
s.close();

s = sessions.openSession();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
assertTrue( b.getClob().getSubString(1, 7).equals("xcvfxvc") );
//b.getClob().setString(5, "1234567890");
s.flush();
s.connection().commit();
s.close();

这就不太一样了。原以为用Hibernate后,至少能同一对不同数据库BLOB字段的操作方式,看来还是不行
标签
共有 6 回复 / 1Go
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表    返回页首返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG:
正在读取,请等待...
查询本论坛内 回复超过的热门帖子
标题
 
粗体: [b]文本[/b] 斜体: [i]文本[/i] 下划线 [u]文本[/u] 插入图片 [img]http://wwww.xxxx.com/img.ext[/img] 插入代码 [code]程序代码[/code]  插入url链接 [url]http://url[/url] / [url=http://url]URL加下滑线[/url] 插入附件 插入word文档 Txt等文件
内容
  提交时自动拷贝以上内容到剪贴板 Ctrl-V可取出;提问题前先查询标签列表

RSS 手机阅读 add to google add to yahoo
解惑之道在J道 ,打造中国最具影响力的的企业软件社区 推荐Chrome快速浏览本站
OpenSource JIVEJDON v3.5 Powered by JdonFramework Code © 2002-09 jdon.com

anti spam