I think this is probably something to do with threads. You must open the database on each thread; as it's an awt/swing app, i think the opening is happening on a different thread to the execution of the query (aren't there two threads, main and AWTEvent ?)
Cheers, Charles. >-----Original Message----- >From: Ujwal Oswal [mailto:[EMAIL PROTECTED]] >Sent: 09 September 2002 15:55 >To: 'OJB Users List' >Subject: RE: OJB- ODMG Help > > >I checked with tutorial2.html. >I have open the database connection in the constructor. If you see my >program below. > >ujwal > >-----Original Message----- >From: Mahler Thomas [mailto:[EMAIL PROTECTED]] >Sent: Monday, September 09, 2002 10:49 AM >To: 'OJB Users List' >Subject: AW: OJB- ODMG Help > > >Have a look at tutorial2.html. >You'll have to open a Database first in order to perform any >transactions ! > >> -----Urspr�ngliche Nachricht----- >> Von: Ujwal Oswal [mailto:[EMAIL PROTECTED]] >> Gesendet: Montag, 9. September 2002 16:42 >> An: '[EMAIL PROTECTED]' >> Betreff: OJB- ODMG Help >> >> >> Hello All, >> >> I am new to OJB and trying to evaluate OJB for our object >> persistence. To >> start with I have written small program using Persistence >> Broker API which >> worked well. I tried to implement the same program using >> ODMG API, it gave >> me Null Pointer Exception. I am connecting to a remote DB2 database. >> >> Here's the Exception I am getting. >> >> [BOOT] INFO: OJB.properties: >> file:/C:/eclipse/workspace/OJB/OJB.properties >> [org.apache.ojb.broker.ta.PersistenceBrokerFactoryDefaultImpl] >> INFO: Already >> created persistence broker instances: 0 >> [org.apache.ojb.broker.util.sequence.SequenceManagerFactory] >INFO: Use >> sequence manager class: class >> org.apache.ojb.broker.util.sequence.SequenceManagerHiLoImpl >> Now Running @@@@@@@@@@@ >> [org.apache.ojb.odmg.TransactionImpl] WARN: TransactionImpl >> created with >> null DatabaseImpl. >> java.lang.NullPointerException >> at org.apache.ojb.odmg.TransactionImpl.getBroker(Unknown Source) >> at org.apache.ojb.odmg.TransactionImpl.begin(Unknown Source) >> at test.odmg.TestOdmg.showUsers(TestOdmg.java:113) >> at test.odmg.TestOdmg.actionPerformed(TestOdmg.java:155) >> at java.awt.MenuItem.processActionEvent(Unknown Source) >> at java.awt.MenuItem.processEvent(Unknown Source) >> at java.awt.MenuComponent.dispatchEventImpl(Unknown Source) >> at java.awt.MenuComponent.dispatchEvent(Unknown Source) >> at java.awt.EventQueue.dispatchEvent(Unknown Source) >> at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown >> Source) >> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown >> Source) >> at java.awt.EventDispatchThread.pumpEvents(Unknown Source) >> at java.awt.EventDispatchThread.run(Unknown Source) >> >> >> I am getting this error when I begin a new transaction. >> >> Transaction tx = odmg.newTransaction(); >> tx.begin(); >> >> >> Can anyone help me with this. >> >> Here's my program below for details. >> >> public class TestOdmg extends Frame implements ActionListener >> { >> private Implementation odmg = null; >> private Vector useCases; >> private static String databaseName; >> private TextArea textarea; >> private Button exit; >> private MenuBar menubar = null; >> private Menu menu = null; >> private MenuItem newUser = null; >> private MenuItem showUser = null; >> private MenuItem exitApp = null; >> >> static >> { >> try >> { >> databaseName = >> ((PersistenceBrokerConfiguration) >> PersistenceBrokerFactory >> .getConfigurator() >> .getConfigurationFor(null)) >> .getRepositoryFilename(); >> } >> catch (ConfigurationException e) >> { >> databaseName = "repository.xml"; >> } >> >> } >> >> public TestOdmg() >> { >> textarea = new TextArea(); >> exit = new Button ("Exit"); >> exit.addActionListener(this); >> menubar = new MenuBar(); >> menu = new Menu("User"); >> newUser = new MenuItem ("New User"); >> newUser.addActionListener(this); >> showUser = new MenuItem ("Show User"); >> showUser.addActionListener(this); >> exitApp = new MenuItem ("Exit"); >> exitApp.addActionListener(this); >> >> odmg = OJB.getInstance(); >> Database db = odmg.newDatabase(); >> //open database >> try >> { >> db.open(databaseName, Database.OPEN_READ_WRITE); >> } >> catch (ODMGException ex) >> { >> ex.printStackTrace(); >> } >> >> menu.add(newUser); >> menu.add(showUser); >> menu.add(exitApp); >> menubar.add(menu); >> setMenuBar(menubar); >> add(textarea,"Center"); >> add(exit, "South"); >> >> setSize(400,400); >> this.show(); >> } >> >> public static void main(String[] args) >> { >> TestOdmg app = new TestOdmg(); >> } >> >> private void showUsers() >> { >> User user = null; >> System.out.println("Now Running @@@@@@@@@@@"); >> int total = 0; >> >> try >> { >> // 1. open a transaction >> Transaction tx = odmg.newTransaction(); >> tx.begin(); >> >> // 2. get an OQLQuery object from the ODMG facade >> OQLQuery query = odmg.newOQLQuery(); >> >> // 3. set the OQL select statement >> query.create("select allusers from " + >> User.class.getName()); >> >> // 4. perform the query and store the result in a >> persistent >> Collection >> DList allUsers = (DList) query.execute(); >> tx.commit(); >> >> // 5. now iterate over the result to print each product >> java.util.Iterator iter = allUsers.iterator(); >> >> while (iter.hasNext()) >> { >> total++; >> user = (User) iter.next(); >> textarea.appendText("User Id : >> "+user.getUserId()+ " User >> Name "+ user.getUserName ()); >> textarea.append("\n"); >> } >> >> textarea.appendText("Total Users : "+ total); >> } >> catch (Throwable t) >> { >> t.printStackTrace(); >> } >> } >> >> public void actionPerformed (ActionEvent ae) { >> if (ae.getSource() instanceof Button) { >> System.exit(0);; >> } >> else if (ae.getSource() instanceof MenuItem) { >> if ("New User".equals(ae.getActionCommand())) { >> System.out.println ("New User"); >> // AddUser adduser = new >> AddUser(this,broker); >> // adduser.show(); >> } >> else if ("Show >> User".equals(ae.getActionCommand())) >> { >> showUsers(); >> } >> else if ("Exit".equals(ae.getActionCommand())) { >> System.exit(0);; >> } >> } >> } >> } >> >> Ujwal >> >> > >-- >To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> This email and any attachments are strictly confidential and are intended solely for the addressee. If you are not the intended recipient you must not disclose, forward, copy or take any action in reliance on this message or its attachments. If you have received this email in error please notify the sender as soon as possible and delete it from your computer systems. Any views or opinions presented are solely those of the author and do not necessarily reflect those of HPD Software Limited or its affiliates. At present the integrity of email across the internet cannot be guaranteed and messages sent via this medium are potentially at risk. All liability is excluded to the extent permitted by law for any claims arising as a re- sult of the use of this medium to transmit information by or to HPD Software Limited or its affiliates. -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
