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]>
