本人有生以以来第一个blog文章,居然还是转贴,哈。
ava.sql.Blob and Clob support
The EJB 3.0 specification has support for Blob and Clob types. The specification allows you to map the following types to an entity property:
To use this feature just need to use the @javax.persistence.Lob annotation. The Lob annotation is an encapsulation of what type of lob you want. Below is an example of defining fields in an entity that are blobs or clobs.
@Entity
public class BlobEntity implements Serializable
{
private long id;
private Blob blobby;
private Clob clobby;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
@Lob @Basic(fetch = FetchType.EAGER)
public Blob getBlobby()
{
return blobby;
}
public void setBlobby(Blob blobby)
{
this.blobby = blobby;
}
@Lob @Basic(fetch = FetchType.EAGER)
public Clob getClobby()
{
return clobby;
}
public void setClobby(Clob clobby)
{
this.clobby = clobby;
}
}
Working with Blobs and Clobs
Open up
LobTesterBean and look for the
create() method. JBoss EJB3 is built on top of the Hibernate persistence engine. Hibernate has some helper methods for creating blobs and clobs that
LobTesterBean uses.
Blob Creation
org.hibernate.Hibernate.createBlob(byte[] bytes)
|
|
org.hibernate.Hibernate.createBlob(InputStream stream, int length)
|
|
org.hibernate.Hibernate.createBlob(InputStream stream)
|
|
Clob Creation
org.hibernate.Hibernate.createClob(String string)
|
|
org.hibernate.Hibernate.createClob(Reader reader, int length)
|
|
Blobs and clobs must only be accessed within a transaction. Blobs and clobs are also not serializable or detachable.
Mapping Strings/
byte[]
to Clob/Blob
This is pretty easy, just look at BlobEntity2.java
@Entity
public class BlobEntity2 implements Serializable
{
private long id;
private byte[] blobby;
private String clobby;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
@Lob @Basic(fetch = FetchType.EAGER)
public byte[] getBlobby()
{
return blobby;
}
public void setBlobby(byte[] blobby)
{
this.blobby = blobby;
}
@Lob @Basic(fetch = FetchType.EAGER)
public String getClobby()
{
return clobby;
}
public void setClobby(String clobby)
{
this.clobby = clobby;
}
}
Building and Running
To build and run the example, make sure you have
ejb3.deployer installed in JBoss 4.0.x and have JBoss running. See the reference manual on how to install EJB 3.0.
Unix: $ export JBOSS_HOME=<where your jboss 4.0 distribution is>
Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is>
$ ant
$ ant run
View the tables and rows
You can view the tables created by JBoss by going to the
Hypersonic SQL service, scrolling down to the
startDatabaseManager button and clicking it. A Hypersonic SQL window will be minimized, but you can open it up to look at the tables and do queries.
本人简写的例子:
写数据:
entity.setContent(Hibernate.createClob("clob的内容"));
读数据:
System.out.println(entity.getContent().getSubString(1,(int)bp.getContent().length()));
分享到:
相关推荐
EJB3的三本好书第二本,最好的介绍ejb3的书,看过之后,其他的书都送人了,而且附带的源代码,几乎包括了所有的主流应用服务器的例子,glassfish, jboss, weblogic, oracleAS 3本书分别是: 1. Beginning EJB3 ...
总共3个zip文件 请全部下载后再解压 7zip压缩 罗时飞精通EJB3.0.zip.001 罗时飞精通EJB3.0.zip.002 罗时飞精通EJB3.0.zip.003 《精通EJB3.0》共分为4个部分:第一部分对EJB编程基础进行介绍,概要性地对EJB进行...
总共3个zip文件 请全部下载后再解压 7zip压缩 罗时飞精通EJB3.0.zip.001 罗时飞精通EJB3.0.zip.002 罗时飞精通EJB3.0.zip.003 《精通EJB3.0》共分为4个部分:第一部分对EJB编程基础进行介绍,概要性地对EJB进行...
EJB3的三本好书之三,也很不错的一本ejb3的书籍,是英文版,附带源代码,这本书的好处是与Mastering EJB 3ed有一定的继承性,可以对比来看. 3本书的地址 1. Beginning EJB3 Application Development From Novice to ...
EJB连接Oracle数据库 EJB连接Oracle数据库 EJB连接Oracle数据库 EJB连接Oracle数据库
总共3个zip文件 请全部下载后再解压 7zip压缩 罗时飞精通EJB3.0.zip.001 罗时飞精通EJB3.0.zip.002 罗时飞精通EJB3.0.zip.003 《精通EJB3.0》共分为4个部分:第一部分对EJB编程基础进行介绍,概要性地对EJB进行...
EJB3的三本好书第一本,从glassfish的角度全面介绍EJB3 3本书分别是: 1. Beginning EJB3 Application Development From Novice to Professional联接http://download.csdn.net/source/1865607 2. EJB3 in Action 2007...
本系统主要实现火车查询...3.选择Oracle数据库通过SQL语句建立表,插入相关的测试数据等相关操作,完成数据库的建立。 4.本设计采用JSP+Servlet+EJB3.0+Oracle10g工具进行开发,最后通过JDBC进行与数据库的相关的链接。
ejb3中文版
他用的是DB2数据库,这台机器上没安,所以就改造一下用在Oracle10g上了,有多对多关系映射,EJB3比hibernate好,我的感觉,而且是正宗名门。 压缩包有三个工程文件,导入RSA7.5中就可以了,别忘了先建数据库再在RSA...
Weblogic10 + EJB3入门教程,喜欢oracle公司产品的同仁共享
EJB的B-S C-S结构编写实例,
EJB3(中文版)EJB3(中文版)EJB3(中文版)EJB3(中文版)EJB3(中文版)EJB3(中文版)EJB3(中文版)
ejb3_structs ejb and jboss
Mastering+EJB3 EJB3+IN+ACTION Beginning+EJB3+Application+Development
经典Java EE企业应用实战:基于WebLogic/JBoss的JSF+EJB 3+JPA整合开发 part3
EJB3开发Entity EJB3开发Entity
(3)企业信息管理系统案例 emis01(EJB+MySQL).zip //09.服务端——EJB+MySQL架构实现 emis02(Struts2+Spring+EJB).zip //10.客户端——Struts2+Spring+EJB架构实现 emis03(EJB+MySQL+JTA).zip //11.事务——为...
本书是公认的EJB 3权威著作,详细介绍了使用EJB 3进行企业级开发的方方面面,包括EJB 3基础、使用EJB 3构造业务逻辑、Java持久化API、EJB 3的实际应用、移植性和互操作性等等。