What am I doing wrong? Not able to persist a 1:M relationship. SourceCode included...
I have the following two class files: package com.gilbert; import java.util.Collection; public class Applications { private int _id; private String name; private String description; private Collection events; // To hold many event objects public void set_id(int _id) { this._id = _id; } public int get_id() { return _id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description=description; } public Collection getEvents() { return events; } public void setEvents(Collection events) { events = events; } public Applications() { } } package com.gilbert; public class Event { protected int _id; protected event; protected int application_id; public void set_id(int _id) { this._id = _id; } public int get_id() { return _id; } public String getEvent() { return Event; } public void setEvent(String event) { this.event = event; } public int getApplication_id() { return application_id; } public void setApplication_id(int application_id) { this.application_id = application_id; } public Event() { } } I have the following user defined mappings: class-descriptor class=com.gilbert.Event table=Event field-descriptor name=_id column=ID jdbc-type=INTEGER primarykey=true autoincrement=true / field-descriptor name=event column=EVENT jdbc-type=VARCHAR / field-descriptor name=application_id column=APPLICATION_ID jdbc-type=INTEGER indexed=true / /reference-descriptor /class-descriptor class-descriptor class=com.gilbert.Applications table=Applications field-descriptor name=_id column=ID jdbc-type=INTEGER primarykey=true autoincrement=true / field-descriptor name=name column=NAME jdbc-type=VARCHAR / field-descriptor name=description column=DESCRIPTION jdbc-type=VARCHAR / collection-descriptor name=events element-class-ref=com.gilbert.Event orderby=_id sort=DESC inverse-foreignkey field-ref=application_id/ /collection-descriptor /class-descriptor Now I use the following code in my program but nothing seems to persist. //Create new application object. Application application = new Application(); application.setName(test1); application.setDescription(This is a test); //Create new event object. Event newEvent = new Event(); newEvent.setEvent(test123); //Load new event object in vector Vector e = new Vector(); e.add(newEvent); //Add Vector that contains event into application object. application.setEvents(e); // now perform persistence operations try { broker.beginTransaction(); broker.store(application); broker.commitTransaction(); } catch (PersistenceBrokerException pbe) { broker.abortTransaction(); } What am I doing wrong? Do I need to persist the event object before I persist the application object? Is my user defined mapping file okay? Thanks in advance, Jeff - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OJB 0.9.9 mysql: Database User password form repository not used?
Here is what I use for fetching a PersistenceBroker in my code: PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(new PBKey(default,sa,)); Where sa equals a user id and is the password. Hope this info helps, Jeff On Saturday 01 March 2003 06:19 pm, you wrote: Hello List, I am using the following Connection descriptor: jdbc-connection-descriptor jcd-alias=default default-connection=true platform=MySQL jdbc-level=2.0 driver=org.gjt.mm.mysql.Driver protocol=jdbc subprotocol=mysql dbalias=//localhost:3306/fldb?autoReconnect=true username=root password=x batch-mode=false When creating a Persistence Broker, I am reciving the follwoing Exception : General error: Access denied for user: '@localhost' to database 'fldb' java.sql.SQLException: General error: Access denied for user: '@localhost' to database 'fldb' at org.gjt.mm.mysql.MysqlIO.sendCommand(MysqlIO.java:497) at org.gjt.mm.mysql.Connection.connectionInit(Connection.java:264) at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89) at org.gjt.mm.mysql.Driver.connect(Driver.java:167) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:193) at org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newConnecti o nFromDriverManager(Unknown Source) at org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl$ConPoolFactor y .makeObject(Unknown Source) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPo o l.java:710) at org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl.getConnection F romPool(Unknown Source) at org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.lookupConne c tion(Unknown Source) at org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.getConnection(Unkno w n Source) at org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.localBegin(Unknown Source) at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.beginTransaction(Unkno w n Source) at org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.beginTransaction ( Unknown Source) at com.ckeller.flweb.application.FLApp.login(Unknown Source) ... When Creating a the first PersistenceBroker. Why is OJB using the Databese and and url defined in the repository but not the username and password? I just updated from OJB 0.9.7 to 0.9.9, in 0.9.7 my database setup worked well. What am I doing wrong now? Thanks in Advance for your Time - Cornelius -- Cornelius Keller Stud. Inf. Humbold Universität Berlin --- crewmeber of space station C-Base - culture communication carbonite in berlin visit: http://www.c-base.org/ --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How does one CRUD a M:N relationship. Any solid examples of CRUD! CRUD! CRUD! CRUD!
Update. I think I have this figured out. The problem I encountered was caused by forgotten to add in code to initialize my Vector upon creation and was receiving a nullPointerException during use. Dah! Jeff On Thursday 27 February 2003 01:41 pm, you wrote: Hi, I've setup a non-decomposed M:N relationship in my datastore so now how do I CRUD (create, read, update and delete) records that participate in this relationship? An example provided by the OJB website for adding records to datastore does exist but doesn't reflect any type of advanced relationship between tables. How would one modify this example to reflect a M:N relationship? What I'm really looking for CRUD!!! I want CRUD! Yummy CRUD! Okay, I'm being silly... Any help would be appreciated. *** Simple example CUT FROM PersistenceBroker API documentation *** public void apply() { // this will be our new object Product newProduct = new Product(); // now read in all relevant information and fill the new object: System.out.println(please enter a new product); String in = readLineWithMessage(enter name:); newProduct.setName(in); in = readLineWithMessage(enter price:); newProduct.setPrice(Double.parseDouble(in)); in = readLineWithMessage(enter available stock:); newProduct.setStock(Integer.parseInt(in)); // now perform persistence operations try { // 1. open transaction broker.beginTransaction(); // 2. make the new object persistent broker.store(newProduct); broker.commitTransaction(); } catch (PersistenceBrokerException ex) { // if something went wrong: rollback broker.abortTransaction(); System.out.println(ex.getMessage()); ex.printStackTrace(); } } Thanks in advance, Jeff - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How does one CRUD a M:N relationship. Any solid examples of CRUD! CRUD! CRUD! CRUD!
Hi, I've setup a non-decomposed M:N relationship in my datastore so now how do I CRUD (create, read, update and delete) records that participate in this relationship? An example provided by the OJB website for adding records to datastore does exist but doesn't reflect any type of advanced relationship between tables. How would one modify this example to reflect a M:N relationship? What I'm really looking for CRUD!!! I want CRUD! Yummy CRUD! Okay, I'm being silly... Any help would be appreciated. *** Simple example CUT FROM PersistenceBroker API documentation *** public void apply() { // this will be our new object Product newProduct = new Product(); // now read in all relevant information and fill the new object: System.out.println(please enter a new product); String in = readLineWithMessage(enter name:); newProduct.setName(in); in = readLineWithMessage(enter price:); newProduct.setPrice(Double.parseDouble(in)); in = readLineWithMessage(enter available stock:); newProduct.setStock(Integer.parseInt(in)); // now perform persistence operations try { // 1. open transaction broker.beginTransaction(); // 2. make the new object persistent broker.store(newProduct); broker.commitTransaction(); } catch (PersistenceBrokerException ex) { // if something went wrong: rollback broker.abortTransaction(); System.out.println(ex.getMessage()); ex.printStackTrace(); } } Thanks in advance, Jeff - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]