Hi Fred,
you can set the default connection only once in OJB lifetime. This will be done at startup or when read additional repository files and one jdbc-connection-descriptor has set 'default-connection' true.
Using of PersistenceBrokerFactory.setDefaultKey only succeed when the default key wasn't set before.
http://db.apache.org/ojb/repository.html#jdbc-connection-descriptor
And your exception says that jcdAlias "jake" was already set as default connection.
regards, Armin
Fred McCann wrote:
I'm having a problem setting the default key for PersistenceBrokerFactory. I have 2 connections defined in repository.xml::
<jdbc-connection-descriptor jcd-alias="live" default-connection="true" platform="Hsqldb" jdbc-level="2.0" driver="org.hsqldb.jdbcDriver"
...
</jdbc-connection-descriptor>
<jdbc-connection-descriptor jcd-alias="development" default-connection="false" platform="Hsqldb" jdbc-level="2.0" driver="org.hsqldb.jdbcDriver"
...
</jdbc-connection-descriptor>
I'm trying to use the "development" connection descriptor in JUnit tests. I'm using this statement in the setup method:
protected void setUp() throws Exception { super.setUp();
if ((PersistenceBrokerFactory.getDefaultKey() == null) ||
(!PersistenceBrokerFactory.getDefaultKey().getAlias().equals("development")) ) PersistenceBrokerFactory.setDefaultKey(new PBKey("development"));
}
This is not working in a big way:
[junit] Testcase: testLogin took 1.219 sec [junit] Caused an ERROR [junit] Default key is already set. Current key is org.apache.ojb.broker.PBKey: jcdAlias=jake, user=sa, password=***** [junit] org.apache.ojb.broker.metadata.MetadataException: Default key is already set. Current key is org.apache.ojb.broker.PBKey: jcdAlias=live, user=sa, password=***** [junit] at org.apache.ojb.broker.metadata.MetadataManager.setDefaultPBKey(MetadataManag er.java:541) [junit] at org.apache.ojb.broker.PersistenceBrokerFactory.setDefaultKey(PersistenceBrok erFactory.java:49) [junit] at com.alloy.hipe.business.HipeTestCase.setUp(Unknown Source) [junit] at com.alloy.hipe.business.TestAccountLogic.setUp(Unknown Source) [junit] Testcase: testLogin
Am I doing something obviously wrong? Is this the wrong way of going about this? Any feedback would be great. Thanks!
- Fred McCann
--------------------------------------------------------------------- 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]
