You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Adam Jenkins <ma...@adamjenkins.net> on 2005/07/03 21:40:10 UTC
Re: 1.1 best practice question - bug?
Hi Tom,
Thanks for that example. I changed my code to almost exactly what you
have below and, while I got my unit tests to pass, I did experience some
odd behaviour. The example you gave only seems to work if I have a
jdbc-connection-descriptor declared in repository.xml with the same
alias as the PBKey. If I ommit the jdbc-connection-descriptor or give
it a different name, I get the npe discussed in previous posts (pasted
below for convenience). This is reproducable and was using the latest
from cvs. Just thought I'd let you know in case it's a bug. Let me
know if you need more information.
Cheers
Adam
---paste---
null
java.lang.NullPointerException
at
org.apache.ojb.broker.core.configuration.ComponentContainerBase.getAllTypes(Unknown Source)
at
org.apache.ojb.broker.core.configuration.ComponentContainerBase.setSingletonInstance(Unknown Source)
at org.apache.ojb.broker.PersistenceConfiguration.<init>(Unknown
Source)
at
org.apache.ojb.broker.OJB.createPersistenceConfiguration(Unknown Source)
at org.apache.ojb.broker.OJB.getConfiguration(Unknown Source)
at org.apache.ojb.broker.OJB.lookupBroker(Unknown Source)
---paste---
On Sun, 2005-07-03 at 12:23 +0200, Thomas Dudziak wrote:
> As I said, you should use the OJB class as an object. Something like
> this should work:
>
> OJB ojb = new OJB();
> PBKey key = new PBKey("default");
> JdbcConnectionDescriptor jcd = new JdbcConnectionDescriptor();
>
> jcd.setDefaultConnection(false);
> jcd.setJcdAlias(key.getAlias());
> jcd.setDbms("postgresql");
> jcd.setJdbcLevel(3.0);
> jcd.setDriver("org.postgresql.Driver");
> jcd.setProtocol("jdbc");
> jcd.setSubProtocol("postgresql");
> jcd.setDbAlias("test");
>
> DescriptorRepository model =
> ojb.getMetadataManager().readDescriptorRepository(new
> FileInputStream("repository.xml"));
> PersistenceConfigurationDescriptor newPCD = new
> PersistenceConfigurationDescriptor(key, model, jcd);
>
> ojb.getMetadataManager().addPersistenceConfiguration(newPCD);
>
> PersistenceConfiguration conf = ojb.getConfiguration(key);
> PersistenceBroker broker = conf.createPersistenceBroker();
>
>
> Note that it is no longer necessary to store the jcd manually in the
> connectionRepository because this is only maintained for backwards
> compatibility.
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: 1.1 best practice question - bug?
Posted by Thomas Dudziak <to...@gmail.com>.
On 7/3/05, Adam Jenkins <ma...@adamjenkins.net> wrote:
> No worries...will do it tonight (work becons). Probably my config, but
> I'll get you more info.
>
> If it's any help I debugged it to the line
> subContainer.setSingletonInstance(pcd.getJdbcConnectionDescriptor()); in
> PersistenceConfiguration constructor...pcd.getJdbcConnectionDescriptor()
> was returning null.
Can it be that you're requiring the jcd to be the default connection ?
My example did not provide that; for this to work you still have to
register the key at the metadata manager using the setDefaultPBKey()
method.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: 1.1 best practice question - bug?
Posted by Thomas Dudziak <to...@gmail.com>.
On 7/3/05, Adam Jenkins <ma...@adamjenkins.net> wrote:
> Thanks for that example. I changed my code to almost exactly what you
> have below and, while I got my unit tests to pass, I did experience some
> odd behaviour. The example you gave only seems to work if I have a
> jdbc-connection-descriptor declared in repository.xml with the same
> alias as the PBKey. If I ommit the jdbc-connection-descriptor or give
> it a different name, I get the npe discussed in previous posts (pasted
> below for convenience). This is reproducable and was using the latest
> from cvs. Just thought I'd let you know in case it's a bug. Let me
> know if you need more information.
That's strange, the very code that I posted works nicely for me with a
repository.xml containing only class-descriptors (current 1.1 CVS).
Could you perhaps build a debug version and repost the stacktrace with
line numbers ?
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org