游离状态的实例可以通过调用save()、persist()或者saveOrUpdate()方法进行持久化。
持久化实例可以通过调用 delete()变成脱管状态。通过get()或load()方法得到的实例都是持久化状态的。
脱管状态的实例可以通过调用 update()、saveOrUpdate()、lock()或者replicate()进行持久化。
--------------------------------------
------------------------------save
Serializable save(Object object)
描述:
Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.) This operation cascades to(级联) associated instances if the association is mapped with cascade="save-update"
参数:
object - a transient instance of a persistent class
返回:
the generated identifier
-------------
------------------------------update
void update(Object object)
描述:
Update the persistent instance with the identifier of the given detached instance. If there is a persistent instance with the same identifier, an exception is thrown. This operation cascades to(级联) associated instances if the association is mapped with cascade="save-update"
参数:
object - a detached instance containing updated state
-------------
------------------------------flush
void flush()throws HibernateException
描述:
Force this session to flush. Must be called at the end of a unit of work, before committing the transaction and closing the session (depending on setFlushMode(FlushMode), Transaction.commit() calls this method). Flushing is the process of synchronizing the
underlying persistent store with persistable state held in memory.
抛出:
HibernateException - Indicates problems flushing the session or talking to the database.
--------------
------------------------------load
Object load(Class theClass,Serializable id)
描述:
Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed.
You should not use this method to determine if an instance exists (use get() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.
参数:
theClass - a persistent class
id - a valid identifier of an existing persistent instance of the class
返回:
the persistent instance or proxy
---------------
------------------------------merge
Object merge(Object object)
描述:
Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy
of and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge"
The semantics of this method are defined by JSR-220.
参数:
object - a detached instance with state to be copied
返回:
an updated persistent instance
---------------
------------------------------persist
void persist(Object object)
描述:
Make a transient instance persistent. This operation cascades to associated instances if the association is mapped with cascade="persist"
The semantics of this method are defined by JSR-220.
参数:
object - a transient instance to be made persistent
---------------
------------------------------delete
void delete(Object object)
描述:
Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving Session or a transient instance with an identifier associated with existing persistent state. This operation cascades to associated instances if the
association is mapped with cascade="delete"
参数:
object - the instance to be removed
实际应用中可能需要程序自动创建BDE别名
特试建 MSsql和paradox数据库别名
//单元代码
unit Unit11; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DBTables; type TForm11 = class(TForm) mmo1: TMemo; btn1: TButton; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form11: TForm11; implementation {$R *.dfm} procedure TForm11.btn1Click(Sender: TObject); var lst: TStringList; procedure DropALias(const AliasName : string); begin if lst.IndexOf(AliasName)<>-1 then begin Session.DeleteAlias(AliasName); Session.SaveConfigFile; mmo1.lines.add('Drop Alias[' + ALiasName + ']'); end; end; procedure AddParadox(const AliasName : string); begin DropALias(AliasName); try Session.AddStandardAlias(AliasName,'c:\instance1','Paradox'); Session.SaveConfigFile; //保存BDE配置文件 mmo1.lines.add('Save Alias[' + ALiasName + ']'); except on e : Exception do Application.MessageBox(PChar(e.message),'错误',MB_ICONERROR+mb_OK); end; end; procedure AddMSSql(const AliasName : string); const ServerStr = '.'; //服务器地址(本机) var AliasLst: TStringList; begin DropALias(AliasName); try Session.AddStandardAlias(AliasName,'','MSSQL'); Session.SaveConfigFile; AliasLst := TStringList.Create; try with AliasLst do begin Add('User name=sa'); Add('SQLQRYMODE=SERVER'); add('Server name='+ServerStr); add('DataBase name=test'); end; Session.ModifyAlias(AliasName, AliasLst); Session.SaveConfigFile; mmo1.lines.add('Save Alias[' + ALiasName + ']'); finally AliasLst.free; end; except on e : Exception do Application.MessageBox(PChar(e.message),'错误',MB_ICONERROR+mb_OK); end; end; begin lst:=TStringlist.Create; try Session.GetAliasNames(lst); //取得别名列表 //Paradox AddParadox('NewParadox'); //MSSq AddMSSql('NewSql'); finally lst.free; end; end; end.
1、简单阐述原理
WebService是对于Socket程序的封装。简单的实现客户端服务器的访问。也就是将下图的Socket程序封装了起来更加简单的实现。请看原理图:
2、准备条件:
A、准备JDK 1.6.20以上的版本(1.6.20之后被Oracle公司收购之后加入ws处理),并且加入系统高级变量Path中
B、切勿忘记@WebService的类注解
3、发布一个服务
A、在Eclipse中建立一个Java Project 目录结构如下图:
B、HelloWorld代码如下:(运行main方法启动服务)
import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService public class HelloWorld { //服务器端方法 public void SayHello(String name){ System.out.println("hello"+name); } public static void main(String[] args) { //Endpoint方法发布一个服务 //@Params address,new 服务类 Endpoint.publish("http://192.168.1.103:8888/hello", new HelloWorld()); System.out.println("发布了一个服务....."); } }
4、访问地址栏确认服务发布成功:
http://192.168.1.103:8888/hello?wsdl 注意后面的?wsdl不可少。成功之后的页面展示如下图:
5、运用wsimport命令(位于JAVAHOME/bin/)远程生成服务器端服务代码
开始-cmd进入doc环境:
d: //进入D盘
mkdir WsTest /建立WsTest目录
cd WsTest //进入WsTest目录
wsimport -s . http://192.168.1.103:8888/hello?wsdl //生成调用服务器端的代码
运行完成之后在该目录下会有和服务器端一样的包和程序
6、新建客户端类调用远程服务器端代码
A、在Eclipse新建一个Java Project 注意jre版本
B、之后将第5部生成的文件夹直接拷贝到src目录下。
C、新建一个Java文件调用生成的类文件。目录结构如下 :
D、GetWebService代码如下:
import cn.zhanglei.webservice.HelloWorld; import cn.zhanglei.webservice.HelloWorldService; public class GetWebService { public static void main(String[] args) { //得到调用服务器端类对象 HelloWorld hw = new HelloWorldService().getHelloWorldPort(); hw.sayHello("张磊"); } }