db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: doDelete problem, null dbMap
Date Tue, 15 Mar 2005 07:40:14 GMT





Jim,

Sorry, I should have read your mail more cautiously; I was again
mistaken...
But nonetheless, I am still confused.

There should be code in the generated xxxBasePeer class which looks like

    public static MapBuilder getMapBuilder(String name)
    {
        try
        {
            MapBuilder mb = (MapBuilder) mapBuilders.get(name);
            // Use the 'double-check pattern' for syncing
            //  caching of the MapBuilder.
            if (mb == null)
            {
                synchronized (mapBuilders)
                {
                    mb = (MapBuilder) mapBuilders.get(name);
                    if (mb == null)
                    {
                        mb = (MapBuilder)
Class.forName(name).newInstance();
                        // Cache the MapBuilder before it is built.
                        mapBuilders.put(name, mb);
                    }
                }
           }
      ....

This should cache the map builder in the dbMap. The method is called from
the static initializer of the xxxBasePeer class, which should be called at
the latest when you call xxxPeer.DoDelete(). If you have the possibility to
debug your code, you might want to put a breakpoint in there and see
whether and when it it called.

There are two reasons I can think of why the Table does not appear in the
dbMap (there might be more)
1) Torque is not initialized or it is initialized more than once
2) For some obscure reason, the xxxBasePeer class is not loaded while you
execute the doDelete().

To exclude 2), you can force the classLoader to load the xxxBasePeer class
by issuing
class.ForName("fully.qualified.name.of.xxxBasePeer");
before the delete. But ") is very improbable, as the Java Language
specification explicitly states that a class is loaded immediately before
you execute one of its static methods....

JLS 2.0 §12.4.1--
"A class or interface type T will be initialized immediately before the
first occurrence of any one of the following:
. T is a class and an instance of T is created.
. T is a class and a static method declared by T is invoked.
. A static field declared by T is assigned.
. A static field declared by T is used and the reference to the field is
not a compile-time constant (§15.28). References to compile-time constants
must be resolved at compile time to a copy of the compile-time constant
value, so uses of such a field never cause initialization."

If you can solve this, I (and probably some more people on the list) would
be very interested to know how this problem could originate.

      Thomas




jcaserta@chubb.com schrieb am 14.03.2005 19:49:22:

>
> Tom,
>
> Yes it does. In the tables MapBulder class it has the following:
>
> dbMap = Torque.getDatabaseMap("default");
> dbMap.addTable("PMTEM021_POLOFFR");
> TableMap tMap = dbMap.getTable("PMTEM021_POLOFFR");
> tMap.setPrimaryKeyMethod("none");
> tMap.addPrimaryKey("PMTEM021_POLOFFR.OFFRG_N", new String());
>
>

>

>  Jim Caserta

>

>  Whitehouse Station CCI - PM&M Systems

>

>  Office: (908) 572-4788

>

>  Mail Stop: WHB2S-15

>

>  jcaserta@chubb.com

>

>
>
>
>
>
>

>              Thomas Fischer

>              <fischer@seitenba

>              u.net>
To
>                                        "Apache Torque Users List"

>              03/14/2005 10:44          <torque-user@db.apache.org>

>              AM
cc
>

>
Subject
>              Please respond to         RE: doDelete problem, null dbMap

>               "Apache Torque

>                 Users List"

>              <torque-user@db.a

>                 pache.org>

>

>

>
>
>
>
>
>
>
>
> Jim,
>
> if the db map is not null, but the column is not mapped, then I was
> mistaken about the cause of the error, and class.forName() is of no use.
>
> Can you look at the map package (${target.package}.map), locate the Map
> class for the Table, and see if it has got an entry for the column
OFFRG_N
> ?
>
>    Thomas
>
>
> jcaserta@chubb.com schrieb am 11.03.2005 20:51:27:
>
> > Thomas,
> >
> > This is exactly (well.. almost) what I have in my code
> >
> > //Get a connection
> > dbConn = Torque.getConnection(getProperty("db2.environment"));
> > dbConn.setAutoCommit(true);
> >
> > \\db2Schema  is the High level qualifier for the table
> > String db2Schema = MixApplication.getProperty("db2schema");
> >
> > BaseTableNamePeer.executeStatement("SET CURRENT SQLID = '" + db2Schema
+
> > "'", dbConn);
> > BasePeer.executeStatement("SET CURRENT SQLID = '" + db2Schema + "'",
> dbConn
> > );
> >
> > Criteria criteria = new Criteria();
> > criteria.add(TableNamePeerPeer.OFFRG_N, primaryKey);
> > TableNamePeer.doDelete(criteria, dbConn);
> >
> > By the way, the dbMap was not null, dbMap.getTable(tab) is null.. my
> > mistake.
> > ColumnMap[] columnMaps = dbMap.getTable(tab).getColumns();
> >
> > How are you are suggesting I should use the forName()?
> >
> > Thanks again!
> > Jim
> >
> >
> >
> >
> >
> > John,
> >
> > My first guess would be that the Peer class is not loaded by the
> > classloader before you execute the query. See
> > http://issues.apache.org/scarab/issues/id/TRQS228
> > In Torque 3.1.1, the problem should be resolved. Alternatively, you can
> > force the classloader to load the class before you execute the
statement,
> > e.g. by class.forName();
> >
> > By the way, what is TableNamePeer.PRIMARY ? Never seen that before; I
> > normally would use
> > TableNamePeer.doDelete(criteria, dbConn);
> >
> >   Thomas
> >
> > jcaserta@chubb.com schrieb am 11.03.2005 16:35:13:
> >
> > > I recently moved over to version 3.1 for Java, I have the selects
> working
> > > fine now (Thanks). The issue is on a doDelete, the dbMap is null. The
> > error
> > > is occurring on this line:
> > > ColumnMap[] columnMaps = dbMap.getTable(tab).getColumns(); in the
> > doDelete.
> > >
> > > My Criteria is setup as follows:
> > > Criteria criteria = new Criteria();
> > > criteria.add(TableNamePeer.PRIMARY_KEY, primaryKey);
> > > TableNamePeer.PRIMARY.doDelete(criteria, dbConn);
> > >
> > > This is the main DB2 table and there are many beneath it. Our system
> will
> > > automatically handle the cascading of the delete. This worked fine in
> > 3.0.
> > >
> > > Thank you in advance!
> > > Jim
> >
> >
>
> >
>
> >  Jim Caserta
>
> >
>
> >  Whitehouse Station CCI - PM&M Systems
>
> >
>
> >  Office: (908) 572-4788
>
> >
>
> >  Mail Stop: WHB2S-15
>
> >
>
> >  jcaserta@chubb.com
>
> >
>
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-user-help@db.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message