You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Malte Stien <ma...@stien.de> on 2003/06/10 04:30:36 UTC
Connection object was null when configured directly
Hi
does anybody know what's wrong here. When I startup torque, the connection
object seems to be null. I get a correspondig exception. That only happens if
I configure Torque during runtime. If I use the Torque.properties-file,
everything works fine.
java.lang.NullPointerException: Connection object was null. This could be due
to a misconfiguration of the DataSourceFactory. Check the logs and
Torque.properties to better determine the cause.
at org.apache.torque.util.Transaction.rollback(Transaction.java:179)
at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:1333)
at
au.com.softimp.project.model.BaseprojectUserPeer.doSelectVillageRecords(BaseprojectUserPeer.java:379)
at
au.com.softimp.project.model.BaseprojectUserPeer.doSelectVillageRecords(BaseprojectUserPeer.java:346)
at
au.com.softimp.project.model.BaseprojectUserPeer.doSelect(BaseprojectUserPeer.java:315)
at
au.com.softimp.project.model.projectUser.getprojectUser(projectUser.java:35)
at
au.com.softimp.project.model.access.UserSession.<init>(UserSession.java:111)
I configured torque during runtime with the following code:
try {
// If Torque has not been initialized yet, do so
if(!Torque.isInit()) {
BaseConfiguration torqueConfig = new BaseConfiguration();
String connectionString = "jdbc:" + databaseType + "://" + databaseHost +
":" + databasePort + "/project";
torqueConfig.addProperty("log4j.rootCategory", "DEBUG, default");
torqueConfig.addProperty("log4j.rootCategory", "WARNINGS, default");
torqueConfig.addProperty("log4j.appender.default",
"org.apache.log4j.FileAppender");
torqueConfig.addProperty("log4j.appender.default.file", "logs/torque.log");
torqueConfig.addProperty("log4j.appender.default.layout",
"org.apache.log4j.SimpleLayout");
torqueConfig.addProperty("torque.database.default", "project");
if(databaseType.equals("postgresql")) {
torqueConfig.addProperty("torque.database.default.adapter", "postgresql");
torqueConfig.addProperty("torque.dsfactory.default.connection.driver",
"org.postgresql.Driver");
}
else
throw new DatabaseNotSupportedException(databaseType);
System.out.println(connectionString);
torqueConfig.addProperty(
"torque.dsfactory.default.pool.defaultMaxConnections", "10");
torqueConfig.addProperty(
"torque.dsfactory.default.pool.maxExpiryTime", "3600");
torqueConfig.addProperty(
"torque.dsfactory.default.pool.connectionWaitTimeout", "10");
torqueConfig.addProperty("torque.dsfactory.default.factory",
"org.apache.torque.dsfactory.TorqueDataSourceFactory");
torqueConfig.addProperty(
"torque.dsfactory.default.connection.url", connectionString);
torqueConfig.addProperty("torque.dsfactory.default.connection.user",
"postgres");
torqueConfig.addProperty("torque.dsfactory.default.connection.password",
"");
Torque.init(torqueConfig);
assert(Torque.isInit());
}
}
If I initialize Torque with the Torque.properties-file everything works fine:
log4j.category.org.apache.torque = DEBUG, org.apache.torque
log4j.appender.org.apache.torque = org.apache.log4j.FileAppender
log4j.appender.org.apache.torque.file =
${torque.applicationRoot}/logs/torque.log
log4j.appender.org.apache.torque.layout = org.apache.log4j.PatternLayout
log4j.appender.org.apache.torque.layout.conversionPattern = %d [%t] %-5p %c -
%m%n
log4j.appender.org.apache.torque.append = false
log4j.rootCategory = DEBUG, default
log4j.appender.default = org.apache.log4j.FileAppender
log4j.appender.default.file = ./torque.log
log4j.appender.default.layout = org.apache.log4j.SimpleLayout
torque.database.project.adapter=postgresql
torque.dsfactory.project.factory=org.apache.torque.dsfactory.TorqueDataSourceFactory
torque.dsfactory.project.pool.defaultMaxConnections=10
torque.dsfactory.project.pool.maxExpiryTime=3600
torque.dsfactory.project.pool.connectionWaitTimeout=10
torque.dsfactory.project.connection.driver = org.postgresql.Driver
torque.dsfactory.project.connection.url =
jdbc:postgresql://localhost:5432/project
torque.dsfactory.project.connection.user = postgres
torque.dsfactory.project.connection.password =
Any ideas? Thank you for any help.
Malte.
Re: Connection object was null when configured directly
Posted by Eric Emminger <er...@ericemminger.com>.
Malte
Malte Stien wrote:
> If I initialize Torque with the Torque.properties-file everything works fine:
So it works when you use the properties file, but not with your runtime
config above? My guess is a problem in your runtime config.
Eric