開發j2ee應用一直用Jbuiler(兩個月前因工作關系開始用eclipse了),倉促開發了所謂數千萬的項目(政府的),在banq的指點下,才忽然發現petstore中有很多可借鑒的東西。
而Jbuiler下玩petstore不是件很輕易的事,本人在暑假期間花了三天時間解決了這個問題,愿與大家共享。本文只包括ejb部分。petstore的版本是bea提供的,因為我用的是weblogic,帶來的一個附加的優點是學習了ejb的繼續。
首先從以下地址下載petstore源碼。
FTP://edownload:BUY_ME@ftpna2.bea.com/pub/downloads/petstore_1.3.1_02_bea.zip
0.按JBuilder標準拷貝文件至src目錄
1.package com.sun.j2ee.bluePRints.waf.view.taglibs.smart;
開始位置在com.sun.j2ee.bluprints.taglibs.smart,改。
2.新建petstore Web App,自然引入原有的Web pacakage
3.配好pointbase數據源:Enterprise Setup--Database Poilet(URL中要注重去掉jdbc:)--JBuiler中配數據源(一直不能看到table,不知何原因。重啟后沒反應,刪除jndi-definations.xml后,又亂改了一下密碼,refresh才行。)
4.可以開始import ejb了,import所有帶ejb子目錄下的ejb。注重!primary key class手工寫為java.lang.String報錯:Error Parsing EJB file: Source file not found for class: null。是指的String類找不到!麻煩!而寫為com.sun.j2ee.blueprint.xxx.xXPK!也出錯:包不對:com.sun.j2ee.blueprint.xxx.String。改為:com.sun.j2ee.blueprint.xxx.WeblogicxxPK。又出錯!
"estore.jar": Unable to load a class specified in your ejb-jar.xml: Unable to load Primary Key class: 'String'. Possible causes: 1:
The Primary Key class is a Java Language Primitive;
this is not allowed. 2: If the Primary Key is a Compound Key,
the Compound Primary Key class is not in the JAR file being compiled.
3: The classpath is incorrect.
此問題最后手工改:petstore.ejbgrpx中的java.lang.String解決。
注重:WeblogicXXXEJB的Inheritence選項中指定EJB的父類。引完后必須手工選擇Table,Table Schema要把后綴EJB去掉,不然EJB-QL語句會出錯。手工選擇對應數據庫的column,不然會報錯:ejb-jar.xml中的cmp-field必須在weblogic-rdbms-jar中有對應元素。
另外,CustomerEJB中account, profile都選對應的field為account_primarykey, profile_primarykey而不是同名的field!
5.一路順利,但OPCAdminFacadeEJB報告名稱沖突。原因是建立了錯誤的EJB,找到那個打了叉的EJB視圖。
6.EJB-QL書寫。找到Primiry-key之外的方法,搜索ejb-jar.xml中包括EJB名稱的文件(有很多ejb-jar文件)。拷貝相應的ejb-ql語句。
7.ejbCreat方法必須返回primary-key類型的值。此問題的解決辦法是在Local Home Interface中定義主鍵時,使用(Object key),JBuiler有時會自動改,再改回來!
8.把WeblogicXXEJB的primarykey的Integer類型改為String類型,否則會說主鍵描述和定義的不一樣。不能改父類的定義,只能這么改了,不知有無副作用。
9.console-security-user中把admin等用戶的用戶名改為petstore,以便登錄
10.
(1)JMS stores
MyJMS File Store, JMSFileStore
MyJMS File Store Persist, P_JMSFileStore
(2)JMS Server
MyJMS Server
注重選擇Persistent Store, paging store
(3)Connection Factorys
jms/opc/QueueConnectionFactory jms/opc/QueueConnectionFactory n/a 4 0 0
jms/petstore/QueueConnectionFactory jms/petstore/QueueConnectionFactory n/a 4 0 0
jms/supplier/QueueConnectionFactory jms/supplier/QueueConnectionFactory n/a 4 0 0
jms/supplier/TopicConnectionFactory jms/supplier/TopicConnectionFactory n/a 4 0 0
Weblogic default connection factory:weblogic.jms.ConnectFactory
(4)JMS Server Destinction
//jms/opc/MailCompletedOrderQueue JMSQueue jms/opc/MailCompletedOrderQueue n/a default 0
//jms/opc/MailOrderApprovalQueue JMSQueue jms/opc/MailOrderApprovalQueue n/a default 0
//jms/opc/MailQueue JMSQueue jms/opc/MailQueue n/a default 0
//jms/opc/OrderApprovalQueue JMSQueue jms/opc/OrderApprovalQueue n/a default 0
jms/opc/OrderQueue JMSQueue jms/opc/OrderQueue n/a default 0
jms/petstore/AsyncSenderQueue JMSQueue jms/petstore/AsyncSenderQueue n/a default 0
//jms/supplier/PurchaSEOrderQueue JMSQueue jms/supplier/PurchaseOrderQueue n/a default 0
//jms/opc/InvoiceTopic JMSTopic jms/opc/InvoiceTopic n/a default 0
//jms/opc/MailInvoiceTopic JMSTopic jms/opc/MailInvoiceTopic n/a default 0
11.mdb
it's so strange:mailinvoicetopic and invoicetopic no correcpondding conncetion factory,
i use jms/supplier/TopicConnectionFactory
12.
[EJB:011031]The Entity EJB requires the table: MANAGEREJB to be accessible.
Please ensure that this table exists and is accessible.
更改weblogic-cmp-rdbms.jar中的所有table名,前面加上secame名:PETSTORE
13.假如數據庫中沒有對應field,則persistence選false即可。
WeblogicXXXEJB中的primaryKey field沒有值,參照源碼中的weblogic-cmp-rdbms.jar改為primaryKey。
新聞熱點
疑難解答