I'll try!Sorry, I don't understand your problem (my fault). Could you please give me more information, a code example, ... What exactly does not work,...
I need to read objects from two separate MySQL databases. We would really like to use the ODMG api since it will allow us to enter OQL queries as text at runtime.
I can start up two separate DatabaseImpl objects as follows:
odmg = OJB.getInstance();
db = (DatabaseImpl)odmg.newDatabase();
db.open("repository.xml", Database.OPEN_READ_ONLY);
db_snp = (DatabaseImpl)odmg.newDatabase();
db_snp.open("repository_snp.xml", Database.OPEN_READ_ONLY);
The repository files start off as follows:
repository.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE descriptor-repository SYSTEM "repository.dtd">
<descriptor-repository version="0.9.6">
<jdbc-connection-descriptor
platform="MySQL"
jdbc-level="2.0"
driver="com.mysql.jdbc.Driver"
protocol="jdbc"
subprotocol="mysql"
dbalias="//holst/ensembl830"
username="mysql"
password="mysql"
/>
<class-descriptor .........
repostory_snp.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE descriptor-repository SYSTEM "repository.dtd">
<descriptor-repository version="0.9.6">
<jdbc-connection-descriptor
platform="MySQL"
jdbc-level="2.0"
driver="com.mysql.jdbc.Driver"
protocol="jdbc"
subprotocol="mysql"
dbalias="//holst/ensembl830_snp"
username="mysql"
password="mysql"
/>
<class-descriptor .........
Ok. Now if I try to load an object I know is in the second database with:
OQLQuery query = odmg.newOQLQuery();
String oql = "select hit from com.lsis.ensembl.snp.ContigHit where chr = $1 " +
"and end >= $2 and start <= $3";
query.create(oql);
...
I get the following exception:
org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: com.lsis.ensembl.snp.ContigHit not found in OJB Repository
at org.apache.ojb.broker.metadata.DescriptorRepository.getDescriptorFor(DescriptorRepository.java:322)
at org.apache.ojb.broker.metadata.DescriptorRepository.getDescriptorFor(DescriptorRepository.java:310)
at org.apache.ojb.broker.query.QueryFactory.newQuery(QueryFactory.java:115)
at org.apache.ojb.broker.query.QueryFactory.newQuery(QueryFactory.java:127)
at org.apache.ojb.odmg.oql.OQLParser.selectQuery(OQLParser.java:168)
at org.apache.ojb.odmg.oql.OQLParser.buildQuery(OQLParser.java:95)
at org.apache.ojb.odmg.oql.OQLQueryImpl.create(OQLQueryImpl.java:234)
at org.apache.ojb.odmg.oql.OQLQueryImpl.create(OQLQueryImpl.java:205)
The class in question is definately in the latter repository, but stepping through the code in the debugger the QueryFactory class always uses the default repository, hence the above error.
My workaround has been to put a static Map in DescriptorRepository that links classes to their correct DescriptorRepository as they are read from the XML file, plus a getInstance(Class) method to fetch the correct instance of DescriptorRepository depending on the class is question.
QueryFactory line 115 was then changed from:
criteria = addCriteriaForOjbConcreteClasses(DescriptorRepository.getDefaultInstance().getDescriptorFor(classToSearchFrom), criteria);
to
criteria = addCriteriaForOjbConcreteClasses(DescriptorRepository.getInstance(classToSearchFrom).getDescriptorFor(classToSearchFrom), criteria);
to use this method.
This workaround seems to work as now the correct repository is chosen for the query, as opposed to always going to the default one.
Hope this fleshes out the problem more fully. Have I misunderstood how this functionality should be used?
Thanks,
Richard.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>