Existem diversos exemplos na distribuição do JOnAS debaixo de
%JONAS_ROOT%\example\src
. Destes, iremos usar o exemplo
que está no sub-diretório eb
para ilustrar o uso de
Entity beans.
Account
): um usa
persistência gerenciada pelo bean - BMP (persistência explicita), o outro usa
persistência gerenciada contêiner - CMP (persistência implícita).Para compilar o exemplo eb execute os seguintes passos:
cd %JONAS_ROOT%\examples\src\eb
).
ant -find build.xml install
).Aqui, novamente, dois processos são envolvidos:
Para executar este exemplo:
jonas start
Iniciar » Programas »
JOnAs - <nomeDoWebContaner>» Start JOnAS (Foreground)
.)Server Jonas >> Deployments >> Conteiners EJB (JAR).
jonas admin -a eb.jar
The JOnAS Server 'jonas' version-number is ready
and running on rmi
message-header : AccountExpl available
message-header : AccountImpl available
Então, execute os clientes java java em outra console Windows(DOS):
jclient eb.ClientAccount AccountImplHome
jclient eb.ClientAccount AccountExplHome
Se as seguintes saídas forem exibidas:
Getting a UserTransaction object from JNDI
Connecting to the AccountHome
Getting the list of existing accounts in
database
101 Antoine de St Exupery 200.0
102 alexandre dumas fils 400.0
103 conan doyle 500.0
104 alfred de musset 100.0
105 phileas lebegue 350.0
106 alphonse de lamartine 650.0
Creating a new Account in database
Finding an Account by its number in database
Starting a first transaction, that will be
committed
Starting a second transaction, that will be rolled
back
Getting the new list of accounts in database
101 Antoine de St Exupery 200.0
102 alexandre dumas fils 300.0
103 conan doyle 500.0
104 alfred de musset 100.0
105 phileas lebegue 350.0
106 alphonse de lamartine 650.0
109 John Smith 100.0
Removing Account previously created in
database
ClientAccount terminated
O exemplo eb foi executado com sucesso.
Ao terminar, assegure-se de parar o servidor JOnAS :
jonas stop