Hibernate Blob 操作問題!
資料庫是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 (?, ?)
對應的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 (?, ?)
相關文章
- hibernate中blob大2進位制檔案的問題?
- 操作hibernate多主鍵的問題?
- 操作hibernate多主鍵的問題?(2)
- Oracle資料庫中對BLOB資料的操作問題Oracle資料庫
- Azure Storage Blob ContentType 問題
- oracle對BLOB型別資料的操作與效能問題(轉載)Oracle型別
- hibernate初學問題
- Hibernate的session問題Session
- hibernate中Blob,Clob欄位類行,二級快取的問題,哪位老大來指點指點快取
- Python 操作 Azure Blob StoragePython
- hibernate中的no session問題Session
- hibernate批量查詢問題
- Hibernate,Weblogic整合問題Web
- 操作Blob型別的方法(zt)型別
- hibernate 1 + N 問題解決
- Hibernate的Criteria查詢問題。
- 請教hibernate 中session問題Session
- Hibernate 動態Update的問題
- Spring與hibernate的問題Spring
- hibernate二級快取問題!快取
- hibernate 的lazy載入問題
- Hibernate 多執行緒問題!執行緒
- 求助hibernate+eclipse問題Eclipse
- 關於oracle中blob欄位的錄入問題Oracle
- 用Hibernate訪問DB27.2的問題DB2
- 問一個關於hibernate的OracleDialect問題Oracle
- Hibernate 一對多配置 級聯操作(級聯失敗問題分析解決)
- JS操作二進位制方法 - blobJS
- Java mysql blob 資料讀寫操作JavaMySql
- 【原創】操作Blob型別的方法型別
- Hibernate中的Session快取問題Session快取
- hibernate對映合成模式的問題模式
- 關於 Hibernate快取的問題快取
- hibernate的hbm檔案生成問題
- Hibernate 資料同步問題請教
- hibernate中oracle的問題,,急啊?Oracle
- 關於Hibernate的查詢問題
- 使用Hibernate、JPA、Lombok遇到的有趣問題Lombok