You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Simon Roberts <si...@fifthweb.net> on 2002/12/10 23:43:21 UTC

Toque and multiple DB with the same schema.

We have what seems like a simple problem that has us stumped - I want to
apply the same schema to multiple databases configured at runtime.
Eventually, it looks like we can just call SomeThing.save("dbname") - but
I've got some problems before then.

If I omit the name=XXX attribute on "database", it just seems to presume
name=default, and a warning about IDBroker being used with db 'default':

11:35:25 [WARN ] main IDBroker.<init>: IDBroker is being used with db
'default', which does not support transactions. IDBroker attempts to use
transactions to limit the possibility of duplicate key generation.  Without
transactions, duplicate key generation is possible if multiple JVMs are used
or other means are used to write to the database.

I don't want IDBroker at all! Why does it think I do? (DB "default" doesn't
even exist)

Anyway, the problem seems to continue, even when doing the most trivial of
operations:

<database defaultIdMethod="native">
    <table name="publisher" idMethod="native">
        <column name="publisher_id" required="true" primaryKey="true"
type="INTEGER"/>
        <column name="name" required="true" type="VARCHAR" size="128" />
    </table>
</database>

With a Torque.init from a file containing:

torque.database.node2.adapter=mysql
torque.dsfactory.node2.factory=org.apache.torque.dsfactory.Jdbc2PoolDataSour
ceFactory
torque.dsfactory.node2.pool.defaultMaxActive=10
torque.dsfactory.node2.pool.testOnBorrow=true
torque.dsfactory.node2.pool.validationQuery=SELECT 1
torque.dsfactory.node2.connection.driver = org.gjt.mm.mysql.Driver
torque.dsfactory.node2.connection.url = jdbc:mysql://localhost:3306/node2
torque.dsfactory.node2.connection.user = root
torque.dsfactory.node2.connection.password =

Then when I try and do:

        Author author = new Author();
        author.setFirstName("Jack");
        author.setFirstName("Daniels");
        author.save("node2");

It complains about

1)
testAddAuthor(fifthweb.jag.server.store.torque.test.TestBookstore)org.apache
.torque.TorqueException: IdGenerator for table 'author' is null
 at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:690)
 at
fifthweb.jag.server.store.torque.BaseAuthorPeer.doInsert(BaseAuthorPeer.java
:216)
 at
fifthweb.jag.server.store.torque.BaseAuthorPeer.doInsert(BaseAuthorPeer.java
:565)
 at fifthweb.jag.server.store.torque.BaseAuthor.save(BaseAuthor.java:508)
 at fifthweb.jag.server.store.torque.BaseAuthor.save(BaseAuthor.java:470)
 at
fifthweb.jag.server.store.torque.test.TestBookstore.testAddAuthor(TestBookst
ore.java:63)

Part of the problem seems to be that BaseAuthorPeer.doInsert(Author obj,
Connection con)

    public static void doInsert( Author obj, Connection con )
            throws TorqueException
    {
        obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
        obj.setNew(false);
        obj.setModified(false);
    }

calls

    public static Criteria buildCriteria( Author obj )
    {
        Criteria criteria = new Criteria(DATABASE_NAME);
        if (!obj.isNew())
            criteria.add(AUTHOR_ID, obj.getAuthorId());
        criteria.add(FIRST_NAME, obj.getFirstName());
        criteria.add(LAST_NAME, obj.getLastName());
        return criteria;
    }

Which is just putting DATABASE_NAME into the Criteria! But it shouldn't be
using that database!

That looks like a bug, right?  Shouldn't the dbname be propagated along with
the object?

Cheers, Simon





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>