Hello all,

My first post to this forum and, as usual, I'm having problems with mail
robots! :-)

I saw this thread since I'm having the same problem, or rather had.

I used the criteria.addOrderByColumn() and got the same exception as Sorin
Scortan. Then I, like Sorin, followed Eric Dobbs' advice to use the
criteria.addAscendingOrderBy() instead and like Soring got the same
exception again!

Then I sat down to debug and debug and debug and this is what I found:

When Turbine initializes, it comes up with one database connection pool
named 'default'. My database is named 'ANALYSEN', though, in the
analysen-schema.xml file. Hence, I could never get the OM complex to work
at all. I run Torque/OM separated from Turbine.

Then i started getting DBConnections separately and then it worked until I
tried to get an instance of a related table, then I got exceptions (no
[database] connection) again.

Now, the code generated by Torque assumes that there should be a connection
pool named after the database and there isn't in my case. Turbine
initializes with a connection pool named 'default' which the OM classes
will never use!

After initialising Turbine  I now create a new database connection pool
named 'ANALYSEN' and now I can get instances of related objects from the
OM.

But I could not set the 'ORDER BY' clause, which I have to since I get rows
returned in reverse order from how they are stored in the database and
they're not even in the correct order in the database.

During the criteria.addAscendingOrderBy(), the database map is bult using
the database name of 'ANALYSEN' since that is how I named it. The criteria
instance, however, refers to the name 'default'.

When the query-string is put together, though, the name in the criteria
sent as an argument is used, and that is 'default'!

The exception occurs in class BasePeer extended by the <table-name>Peer
class in method createQueryString() at line 1039 where the call to
ColumnMap column = dbMap.getTable(table).getColumn( columnName ) causes a
null pointer exception.

More exactly, the problem lies beyond that call. The origin is found in
class DatabaseMap and method getTable() where that method attempts to
localize the table name sent as a parameter in a DatabaseMap instance
pointing at database 'default' and not 'ANALYSEN'.

Since the map for the database 'default' has not been built, there are no
tables in that map as seen in the 'tables' HashMap. Thus the HashMap.get()
call returns a null Object and getTable returns a null TableMap and there
we have the null pointer exception. See above? getColumn(columnName) is
called on the TableMap returned by getTable. Since getTable returned a null
pointer, getColumn will fail with an exception.

Now what do I do?

I can't find any entry in TurbineResources.properties and nothing really in
the documentation (but I haven't read every line) about naming the
database. Maybe I shouldn't name it in the XML-file the way I have?

As I said before, after initializing Turbine (I need the database
connectivity broker service) I create another database connection handle
pool named 'ANALYSEN' besides the one created automatically by Turbine
(named 'default').

But, it seems, I must also never forget to force the database name in each
and every criteria instance to the correct database name by calling
criteria.setDbName(String name).

The above solution works for me on both MYSQL and POSTGRESQL databases so
maybe it will work for you, Sorin, as well.

I have no idea if I have generated my OM classes in the wrong way. Reading
manuals isn't really my strongest side and the Torque/Turbine documentation
is sometimes a tad sketchy and incomplete...  ;-D

This  is a work-around, though! Hopefully not a solution to the problem.
There must be something I've missed in all this!

Regards
Per Sten
___________________________________________
Per Sten
Software Engineer
Integris Svenska AB
Karlsrov�gen 2D
PO Box 544
SE-182 15 Danderyd
Sweden
E-mail  : [EMAIL PROTECTED]
Phone : +46 8 622 42 76
Cellular: +46 70 921 42 76
Fax      : +46 8 622 42 23


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to