JBoss-Ide 1.2.2 Introduction (Hibernate) 3
JBoss-IDE 1.2.2 Introduction (Hibernate) 3: Next, it is compute method:
/ **
* @Param Number
* @Return
*
* @ ejb.interface-method view-type = "remote"
* /
Public Double [] compute (int number) {
IF (Number <0) {
Throw New EjBexception ("argument shouth be posacy");
}
Double [] suite = new double [number 1];
Suite [0] = 0;
IF (Number == 0) {
Return suite;
}
// Hibernate Section
Try {
Session session = hibernateutil.currents;
Transaction tx = session.begintransaction ();
// Compare the Input and DB IS
Sam
e fruitt
INT MAX = ("" "" "Select Count (Num.Value) from tutorial.hibernate.num num"). Next ()) .intValue ();
IF (MAX == Number) {// Results Already in DB
Query Query = session.createQuery ("Select Num from Tutorial.Hibernate.Num Num ORDER BY NUM.VALUE ASC");
INT i = 1;
Iteerator it = query.Itemate (); it.hasnext ();) {
Num num = (num) IT.NEXT ();
Suite [I] = Num.getValue ();
i ;
}
}
Else {// Need to Calc Again
// Clear the Table First
Int r = session.delete ("from tutorial.hibernate.num");
Num n = new Num ();
Suite
[1]
= 1;
N.SetValue
Suite
[1]
);
Session.save (n);
For (int i = 2; i <= number; i ) {
N = new Num ();
Suite [i] = suite [i - 1] suite [i - 2];
N.SetValue (Suite [i]);
Session.save (n);
}
}
TX.comMit ();
Hibernateutil.closesis ();
}
Catch (HibernateException HE) {
HE.PrintStackTrace ();
}
Return suite;
}
After the completion, you should see this figure in Package Explorer.
Last Compile Project, right click Tutorial Project -> 'Build Project'
JBoss-IDE 1.2.2 Introduction (Hibernate) 4
JBoss-IDE 1.2.2 Introduction 4: 6. Now set xDoclet, first add a JBoss-Service-Custom.xdt file in the SRC / META-INF in the Tutorial project, as follows: < Depends> jboss.jca: service = localtxcm, name = mysqlds depends>
mbean>
server>
Tail 2 and tail three lines are outside
7. Now let's set the package. Right click on Tutorial Project, select 'Properties', and then select' Packaging Configuration ', because Hibernate wants to include .hbm.xml image file, we want to be on the right hand side in' fiboejb. The '/ jboss_ide_tutorial / bin' (ie tutorial / tutorial / bin) under Jar ', including the set of' tutorial / hibernate / *. HBM.XML, TUTORIAL / Hibernate / *. Class' in the tutorial / hibernate package, Right-click '/ JBoss_IDE_TUTORIAL / BIN' Choose 'Edit': The SAR service setting of JBoss is set, and the windows of the right hand are selected in the right hand, and the 'add archive' fills in 'Hibernatestartup.sar' Press 'OK'. Hibernatestartup.sar 'Choose' JBoss-Service.xml '' /JBoss_IDE_TUTORAL/SRC /META-INF/JBOSS-SERVICE.XML ', Prefix Fill in the Tutorial Meta-INF folder META-INF ', press' OK '. Because this setting is to be set before' FiboApp.ear ', you have to press the' file on 'file' on 'fiboApp.ear' by right hand:
In 'fiboApp.ear' package settings, we have to add this' hibernatestartup.sar ', right-click' FiboApp.ear 'Choose' add file 'fill in' /jboss_ide_tutorial/hibernatestartup.sar 'after filling in the project' OK '. Al remember to include the' jboss-app.xml 'file in JBoss SAR service, right-click' FiboApp.ear 'Choose' / jboss_IDE_TUTORIAL / SRC / META-INF / JBOSS -app.xml ', prefix fills in' meta-inf ', press' OK', then press' OK ':
The code of 'jboss-app.xml' is as follows:
XML Version = "1.0"?>
module>
jboss-app>
Packaging settings are finally completed, and now you can run. Right-click Tutorial project to select 'Run Packaging'. After success, you should add a 'Hibernatestartup.sar' file, as shown:
8. Now we can try it, first start JBoss -> deploy 'fiboApp.ear' to jboss, in Browser input 'http://127.0.0.1:8080/fibo', then enter '50', you can see To the following results, the examples in the JBoss-Ide tutorial are the same, but Hibernate is used inside.
postscript:
The shortcomings of this example is to generate bug in jboss-service.xml. Whenever the 'Run XDoclet' is completed, it is necessary to manually modify jboss-service.xml. Online seems to have FIX, but because it is too lazy to find. Finally, There may be many places to go wrong or missing, I hope everyone can correct and give more opinions, thank you!
Reference: