Merging data from two data bases

Längerich, Bernd <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi,

given is a master data base and a backup data base. All entries are stored to the master data base and  to the backup.
If anything fails (computer crashes) at startup I want to merge the data from the backup with the data of the master database.

The code I tried is like this:

      masterbroker = PersistenceBrokerFactory.defaultPersistenceBroker();
      ReportQueryByCriteria masterquery = QueryFactory.newReportQuery(Transaction.class,new Criteria());
      masterquery.setAttributes(new String[] {"id"});
      masterquery.setDistinct(true);
      Collection taids = masterbroker.getCollectionByQuery(masterquery);
      log.info("Master DB has "+taids.size()+" transactions");
      Criteria crit = new Criteria();
      crit.addNotIn("id",taids);
      backupbroker = PersistenceBrokerFactory.createPersistenceBroker(new PBKey(jcdalias));
      Query query = QueryFactory.newQuery(Transaction.class,crit);
      Collection tas = backupbroker.getCollectionByQuery(query);
      if (tas.size()>0) {
        log.warn("Backup DB has "+tas.size()+" transactions not stored in the master DB");
      }
      for (Iterator iter = tas.iterator(); iter.hasNext();) ...

The problem is when I reach the line

      Collection taids = masterbroker.getCollectionByQuery(masterquery);

I get a strange exception:

org.apache.ojb.broker.PersistenceBrokerException: Unexpected error while try to read 'ojbConcretClass' field from result set using column name CLASS_NAME main class was de.actosoft.accept.process.Transaction
	at org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.extractOjbConcreteClass(Unknown Source)
	at org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readObjectArrayFrom(Unknown Source)
	at org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unknown Source)
	at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown Source)
	at org.apache.ojb.broker.accesslayer.ChainingIterator.next(Unknown Source)
	at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
	at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
	at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
	at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source)
	at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source)
	at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source)
[...]

The strange thing is the 'ojbConcretClass' where the repository_user.xml says:

<class-descriptor
    class="de.actosoft.accept.process.NullTransaction"
    table="ACC_TA"
>
    <field-descriptor
        name="ojbConcreteClass"
        column="CLASS_NAME"
        jdbc-type="VARCHAR"
        length="255"
    >
    </field-descriptor>
    <field-descriptor
        name="id"
        column="ACC_TAID"
        jdbc-type="INTEGER"
        primarykey="true"
        autoincrement="true"
    >
[...]

The SQL generated and executed looks fine (except that it contains redundant where clause parts):

1165921756841|-1||resultset|SELECT DISTINCT A0.ACC_TAID FROM ACC_TA A0 WHERE ( A0.CLASS_NAME IN (...)) AND  (A0.CLASS_NAME IN (...)|ACC_TAID = 1

If I remove the line 
      masterquery.setAttributes(new String[] {"id"});
everything works fine but I get all object instances instead of just a collection of ids.

Any hints? Is there any way to do what I want? I used db-ojb-1.0.4.jar and MS-SQL 2000.

Mit freundlichen Grüßen

i.A. Bernd Längerich
Softwareentwicklung

act'o-soft GmbH Payment Systems
World Wide Business Center
Habichtstrasse 41
22305 Hamburg

Phone: 00 49 40 61135432
Fax:     00 49 40 61135429
Mobile: -
eMail:   [email protected]
www.actosoft-payment-systems.de
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.