I am experimenting with torque and a mysql database running on NT on the
same machine (my labtop). I downloaded the stand-alone beta version.
Ik have succesfully generated the SQL and generated the access classes
(base- peer etc etc), succesfully created the database (with
project-insert-sql) . Both my application code and the generated code
are compiling fine.
I have a problem trying to write a very simple app which inserts en row
into a table. The problem is that Torque doesn't seem to be able to get
a connection to the database at runtime. I have seen several mails that
touch this subject, but untill no i did not find the solution.
Below I will provide the following information:
- Torque.properties file
- build.properties
- the schema file defining the database/tables
- sample code (only 4 lines)
- the error that is returned
- the logile which tells me that mysql does not support transaction.
It is kind of long, but i see no other way.
Your help is appreciated.
my Torque.properties file
=========================
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.default=VIRUS
torque.database.virus.driver = org.gjt.mm.mysql.Driver
torque.database.virus.url = jdbc:myql://127.0.0.1:3306/VIRUS
torque.database.virus.username = root
torque.database.virus.password = virus
build.properties (relevant part)
================
# -------------------------------------------------------------------
#
# T O R Q U E C O N F I G U R A T I O N F I L E
#
# -------------------------------------------------------------------
# -------------------------------------------------------------------
#
# T U R B I N E P R O J E C T
#
# -------------------------------------------------------------------
# This is the name of your Turbine project. Your generated sources
# will be named using the project name selected below. If your
# project=killerapp then you will have a generated:
#
# killerapp-schema.sql
#
# IMPORTANT!
# This means that your project schema MUST be named
# killerapp-schema.xml and it MUST be placed in the
# schema directory for Torque to work property.
#
# The object model sources generated are independent of
# the project name selected.
# -------------------------------------------------------------------
project = VIRUS
# -------------------------------------------------------------------
#
# T A R G E T D A T A B A S E
#
# -------------------------------------------------------------------
# This is the target database, only considered when generating
# the SQL for your Turbine project. Your possible choices are
#
# db2
# db2400
# hypersonic
# mysql
# oracle
# postgresql
# mssql
#
# Default: none
# -------------------------------------------------------------------
database = mysql
# -------------------------------------------------------------------
#
# O B J E C T M O D E L I N F O R M A T I O N
#
# -------------------------------------------------------------------
# These settings will allow you to customize the way your
# Peer-based object model is created.
# -------------------------------------------------------------------
# addSaveMethod=true adds tracking code to determine how to save objects
#
# addGetByNameMethod=true adds methods to get fields by name/position
#
# complexObjectModel=true generates an om with collection support
#
# addTimeStamp=true puts time stamps in generated files
#
# addIntakeRetrievable=implement Intake's Retrievable interface
# -------------------------------------------------------------------
targetPackage=virus.torque
basePrefix=Base
addSaveMethod=true
addGetByNameMethod=true
complexObjectModel=true
addTimeStamp=true
addIntakeRetrievable=false
# -------------------------------------------------------------------
# Generate Manager classes that use JCS for caching. This is still
# considered experimental.
# -------------------------------------------------------------------
useManagers=false
# -------------------------------------------------------------------
#
# D A T A B A S E S E T T I N G S
#
# -------------------------------------------------------------------
# JDBC connection settings. This is used by the JDBCToXML task that
# will create an XML database schema from JDBC metadata. These
# settings are also used by the SQL Ant task to initialize your
# Turbine system with the generated SQL.
# -------------------------------------------------------------------
createDatabaseUrl = jdbc:myql://127.0.0.1:3306/VIRUS
databaseUrl = jdbc:mysql://127.0.0.1:3306/VIRUS
databaseDriver = org.gjt.mm.mysql.Driver
databaseUser = root
databasePassword = virus
databaseHost = 127.0.0.1
# Tells JDBC task that javaName attribute for the tables and columns
# should be made same as SQL name.
sameJavaName=true
- my code (only 4 lines)
=======================
package virus.app;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import virus.torque.Project;
import virus.torque.ProjectPeer;
public class TestTorque {
public static void main (String[] args)
throws TorqueException, Exception {
Torque.init("d:\\torque\\Torque.properties");
Project project = new Project();
project.setCode("JMV001");
ProjectPeer.doInsert(project);
//i also tried project.save();
}
}
- the error that is returned
java.sql.SQLException: Connection object is null!
at
org.apache.torque.pool.DBConnection.getConnection(DBConnection.java:375)
at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:895)
at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:774)
at
virus.torque.BaseProjectPeer.doInsert(BaseProjectPeer.java:170)
at
virus.torque.BaseProjectPeer.doInsert(BaseProjectPeer.java:149)
at
virus.torque.BaseProjectPeer.doInsert(BaseProjectPeer.java:428)
at virus.app.TestTorque.main(TestTorque.java:20)
rethrown as org.apache.torque.TorqueException: Connection object is
null!
at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:901)
at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:774)
at
virus.torque.BaseProjectPeer.doInsert(BaseProjectPeer.java:170)
at
virus.torque.BaseProjectPeer.doInsert(BaseProjectPeer.java:149)
at
virus.torque.BaseProjectPeer.doInsert(BaseProjectPeer.java:428)
at virus.app.TestTorque.main(TestTorque.java:20)
Exception in thread "main" Process Exit...
- the logile which tells me that mysql does not support transaction.
INFO - Logging has been configured by Torque.
DEBUG - Using org.apache.torque.adapter.DBMM
INFO - IDBroker thread was started.
WARN - IDBroker is being used with db 'VIRUS', 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.
in the torque.properties file there was a typo because i tried to solve
it by fiddling around with this file.
torque.database.virus.url = jdbc:myql://127.0.0.1:3306/virus1
should be
torque.database.virus.url = jdbc:myql://127.0.0.1:3306/virus
which doesn't work either.
Below I added the build.properties file because this one does not have
any problems obtaining a connection:
cheers,
jm
==============================================================================
# -------------------------------------------------------------------
#
# T O R Q U E C O N F I G U R A T I O N F I L E
#
# -------------------------------------------------------------------
# -------------------------------------------------------------------
#
# T U R B I N E P R O J E C T
#
# -------------------------------------------------------------------
# This is the name of your Turbine project. Your generated sources
# will be named using the project name selected below. If your
# project=killerapp then you will have a generated:
#
# killerapp-schema.sql
#
# IMPORTANT!
# This means that your project schema MUST be named
# killerapp-schema.xml and it MUST be placed in the
# schema directory for Torque to work property.
#
# The object model sources generated are independent of
# the project name selected.
# -------------------------------------------------------------------
project = virus
# -------------------------------------------------------------------
#
# T A R G E T D A T A B A S E
#
# -------------------------------------------------------------------
# This is the target database, only considered when generating
# the SQL for your Turbine project. Your possible choices are
#
# db2
# db2400
# hypersonic
# mysql
# oracle
# postgresql
# mssql
#
# Default: none
# -------------------------------------------------------------------
database = mysql
# -------------------------------------------------------------------
#
# O B J E C T M O D E L I N F O R M A T I O N
#
# -------------------------------------------------------------------
# These settings will allow you to customize the way your
# Peer-based object model is created.
# -------------------------------------------------------------------
# addSaveMethod=true adds tracking code to determine how to save objects
#
# addGetByNameMethod=true adds methods to get fields by name/position
#
# complexObjectModel=true generates an om with collection support
#
# addTimeStamp=true puts time stamps in generated files
#
# addIntakeRetrievable=implement Intake's Retrievable interface
# -------------------------------------------------------------------
targetPackage=virus.torque
basePrefix=Base
addSaveMethod=true
addGetByNameMethod=true
complexObjectModel=true
addTimeStamp=true
addIntakeRetrievable=false
# -------------------------------------------------------------------
# Generate Manager classes that use JCS for caching. This is still
# considered experimental.
# -------------------------------------------------------------------
useManagers=false
# -------------------------------------------------------------------
#
# D A T A B A S E S E T T I N G S
#
# -------------------------------------------------------------------
# JDBC connection settings. This is used by the JDBCToXML task that
# will create an XML database schema from JDBC metadata. These
# settings are also used by the SQL Ant task to initialize your
# Turbine system with the generated SQL.
# -------------------------------------------------------------------
createDatabaseUrl = jdbc:myql://127.0.0.1:3306/virus
databaseUrl = jdbc:mysql://127.0.0.1:3306/virus
databaseDriver = org.gjt.mm.mysql.Driver
databaseUser = root
databasePassword = virus
databaseHost = 127.0.0.1
# Tells JDBC task that javaName attribute for the tables and columns
# should be made same as SQL name.
sameJavaName=false
# -------------------------------------------------------------------
#
# D O C U M E N T A T I O S E T T I N G S
#
# -------------------------------------------------------------------
# These settings will allow you to customize the way your schema
# documentation is created.
# Valid formats are: html, anakia (for use with jakarta-site2)
# -------------------------------------------------------------------
documentationFormat=html
# -------------------------------------------------------------------
# You should NOT have to edit anything below here.
# -------------------------------------------------------------------
# -------------------------------------------------------------------
#
# T E M P L A T E P A T H
#
# -------------------------------------------------------------------
templatePath = templates
# -------------------------------------------------------------------
#
# C O N T R O L T E M P L A T E S
#
# -------------------------------------------------------------------
SQLControlTemplate = sql/base/Control.vm
OMControlTemplate = om/Control.vm
idTableControlTemplate = sql/id-table/Control.vm
DataDTDControlTemplate = data/Control.vm
DataDumpControlTemplate = data/dump/Control.vm
DataSQLControlTemplate = sql/load/Control.vm
DocControlTemplate = doc/Control.vm
# -------------------------------------------------------------------
#
# O U T P U T D I R E C T O R Y
#
# -------------------------------------------------------------------
outputDirectory=src
# -------------------------------------------------------------------
#
# S C H E M A D I R E C T O R Y
#
# -------------------------------------------------------------------
schemaDirectory=schema
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>