I have a problem using the PersistanceBroker API in ojb-1.0.rc4.
I tried to reduce the problem to a simple example as follows:
I'm using two different databases. From one database (db-source) I'm reading data, then I process it in some way before I store it in the second database (db-dest).
The data in db-source is stored in a table with the same name as in db-dest (example: person), but the format is different (example: birthday in db-source, but age in db-dest).
The person in db-source is mapped (see repository.xml below) to the class ojbtest.PersonSource and the person in db-dest is mapped to the class ojbtest.PersonDest. These classes are implemented as simple as it would be expected.
When I try to read one PersonDest from db-dest, ojb assembles an SQL command (see below) that tries to read also fields (A0.birthday) from PersonSource which are not defined in PersonDest.
My questions: - Is there a way that ojb allows the same table name in multiple different databases? - Is this an error in ojb or am I doing something wrong?
TIA julisys
This is the SQL command that is assembled by ojb: -------------------------------------------------------------------- SELECT A0.age,A0.name,A0.id,A0.birthday FROM person A0 WHERE A0.id = ? --------------------------------------------------------------------
Here comes the repository.xml: --------------------------------------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE descriptor-repository PUBLIC
"-//Apache Software Foundation//DTD OJB Repository//EN"
"repository.dtd"
[
<!ENTITY internal SYSTEM "repository_internal.xml">
]>
<descriptor-repository version="1.0" isolation-level="read-uncommitted"> <jdbc-connection-descriptor jcd-alias="db-source" default-connection="false" platform="Sapdb" jdbc-level="3.0" driver="com.sap.dbtech.jdbc.DriverSapDB" protocol="jdbc" subprotocol="sapdb" dbalias="//teapp/calendar" username="mm" password="mm" eager-release="false" batch-mode="false" useAutoCommit="1" ignoreAutoCommitExceptions="false"> <connection-pool maxActive="21" validationQuery="" /> </jdbc-connection-descriptor>
<jdbc-connection-descriptor jcd-alias="db-dest"
default-connection="true" platform="Sapdb" jdbc-level="3.0"
driver="com.sap.dbtech.jdbc.DriverSapDB"
protocol="jdbc" subprotocol="sapdb" dbalias="//teapp/newsdev"
username="news" password="news"
eager-release="false" batch-mode="false"
useAutoCommit="1" ignoreAutoCommitExceptions="false">
<connection-pool maxActive="21" validationQuery="" />
</jdbc-connection-descriptor>&internal;
<class-descriptor class="ojbtest.PersonSource" table="person">
<field-descriptor name="id" column="id" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor name="name" column="name" jdbc-type="INTEGER"/>
<field-descriptor name="birthday" column="birthday"
jdbc-type="DATE"/>
</class-descriptor> <class-descriptor class="ojbtest.PersonDest" table="person">
<field-descriptor name="id" column="id" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor name="name" column="name" jdbc-type="INTEGER"/>
<field-descriptor name="age" column="age" jdbc-type="INTEGER"/>
</class-descriptor>
</descriptor-repository>--------------------------------------------------------------------
And this is the code that reads a PersonSource from db-source: --------------------------------------------------------------------
package ojbtest;
import org.apache.ojb.broker.*; import org.apache.ojb.broker.query.*;
import java.util.Iterator;
public class OjbTest {
public static void main(String[] args) {
PBKey pbKey;
PersistenceBroker persistenceBroker;
Query query;
Iterator iterator;try {
pbKey = new PBKey("db-dest");
persistenceBroker = PersistenceBrokerFactory.createPersistenceBroker(pbKey);
Criteria criteria = new Criteria();
criteria.addEqualTo("id", new Integer(1));
query = new QueryByCriteria(PersonDest.class, criteria);
iterator = persistenceBroker.getIteratorByQuery(query);
if (iterator.hasNext()) {
PersonDest person = (PersonDest) iterator.next();
System.out.println(person);
}
persistenceBroker.close();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
}
--------------------------------------------------------------------
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
