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 Matt Reath <ma...@cciinc.us> on 2003/08/07 16:21:32 UTC

Problems with save() method with Peer class

I have a Customer table in a mysql database. The torque build process
creates the database, tables, and source code with no error. When I call
the customer class:

Customer customer = new Customer();
.
.
.
customer.save();

I get a java.lang.NullPointerException when I call the save method. I
narrowed it down to the getMapBuilder() method. I can create a
CustomerMapBuilder object and then call the getDatabaseMap() function
but it gives me java.lang.NullPointerException. I've been trying to hunt
the problem down but it seems to be in the torque code itself. I've
attached my config files.

If anybody could help me get this working that would be great.

Matthew Reath
Integration Engineer
Cable Constructors, Inc.
105 Kent Street
Iron Mountain, MI 49801
Phone: (906) 774-6621 x2134
Fax: (906) 774-9120
Email: matt.reath@cciinc.us 
Web: http://www.cciinc.us


hypersonic primarykey's

Posted by Ryan Christianson <ry...@echospace.com>.
I had some problems with primary keys with hypersonic. I fixed my issue, 
and I thought I would share. Maybe it will help someone else, or maybe 
I'm crazy.

In my schema xml file I have this:

        <column
            name="portal_setting_id"
            required="true"
            primaryKey="true"
            type="INTEGER"
            autoIncrement="true"
        />

Note, that I had to stick the autoIncrement="true" line in there, or 
else hypersonic did'nt reconize that this column was the primary key, 
and would give errors about passing NULL for a non null column.

Now, with the autoIncrement="true" and  primaryKey="true" then torque 
was generating the init tables sql code like this (for hypersonic):

CREATE TABLE portal_setting
(
    portal_setting_id integer IDENTITY,
    default_skin_id integer
    PRIMARY KEY( portal_setting_id ),
);

Hypersonic however didnt like that. When I would create the database in 
hypersonic, it would say that I was creating a second primary key. So I 
changed the template for outputing primary keys for hypersonic to this:

#if ($table.hasPrimaryKey())   
##    PRIMARY KEY($table.printPrimaryKey()),
#end

It all works fine. In fact, if I peek in the hypersonic database script 
file it shows that it is a primary key:

CREATE TABLE PORTAL_SETTING(PORTAL_SETTING_ID INTEGER NOT NULL IDENTITY 
PRIMARY KEY,DEFAULT_SKIN_ID INTEGER)

Maybe the templates for hypersonic should be updated?

Hope this helps someone.

Ryan Christianson





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


RE: Problems with save() method with Peer class

Posted by Patrick O'Brien <po...@chessys.com>.
Hi,

I'm a newbie and an at this point simply evaluating torque for possible use.
So far I have not been able to get it to work.

I plan to use torque in combo with struts and tomcat connecting to a ms sql
db.

I am able to generate the classes and scripts from the xml file.

However when I call the save() method I too get a null pointer.

I do notice that the init method (being called from a special
InitTorqueServlet)  never returns. No error no nothing it just hangs. For
sanity sake I have entered bogus connection data and I do get the correct
exception.

Furthermore I plan to use the tomcat realm class for authentication, and
entering the same criteria, I am able to make a connection with this db. The
db monitor I am using shows me the realmclasses connection, but the torque
connection is never made.

Has anyone used mssql with torque? Any other ideas why this connection is
never being made. Does torque only work with certain drivers?

Torque.properties follows
------------------------------
torque.database.default=cct
torque.database.cct.adapter=mssql

## Using torque's old pool
torque.dsfactory.cct.factory=org.apache.torque.dsfactory.TorqueDataSourceFac
tory
torque.dsfactory.cct.pool.defaultMaxConnections=10
torque.dsfactory.cct.pool.maxExpiryTime=3600
torque.dsfactory.cct.pool.connectionWaitTimeout=10
torque.dsfactory.cct.connection.driver=com.inet.tds.TdsDriver
torque.dsfactory.cct.connection.url=jdbc:inetdae7a:lisa?database=cct
torque.dsfactory.cct.connection.user=sa
torque.dsfactory.cct.connection.password=
------------------------------------------


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


RE: Problems with save() method with Peer class

Posted by Matt Reath <ma...@cciinc.us>.
I solved my problem. My Torque.properties files was wrong. I found a
message on some other mailing list (thanks Google) and now its working.

I appreciate all of your help.

-----Original Message-----
From: Matt Reath [mailto:matt.reath@cciinc.us] 
Sent: Thursday, August 07, 2003 10:26 AM
To: 'Apache Torque Users List'
Subject: RE: Problems with save() method with Peer class

I'm getting a TorqueException with I do Torque.init(propfile). It
doesn't give me anymore detail than that.

Matt

-----Original Message-----
From: Matt Reath [mailto:matt.reath@cciinc.us] 
Sent: Thursday, August 07, 2003 10:10 AM
To: 'Apache Torque Users List'
Subject: RE: Problems with save() method with Peer class

Okay, I initialize torque and get a different error now:

java.lang.NullPointerException: There was no DataSourceFactory
configured for the connection ontrack

Matt

-----Original Message-----
From: Matt Reath [mailto:matt.reath@cciinc.us] 
Sent: Thursday, August 07, 2003 9:59 AM
To: 'Apache Torque Users List'
Subject: RE: Problems with save() method with Peer class

Well I've come to the conclusion that I'm an idiot and I wasn't calling
Torque.init(String filename);

Let me try this first.

-----Original Message-----
From: Andras Balogh [mailto:andras@reea.net] 
Sent: Thursday, August 07, 2003 9:48 AM
To: Apache Torque Users List
Subject: Re: Problems with save() method with Peer class


  ----- Original Message ----- 
  From: Matt Reath 
  To: 'Apache Torque Users List' 
  Sent: Thursday, August 07, 2003 5:39 PM
  Subject: RE: Problems with save() method with Peer class


  Andras,

  I've included my config files. I hope you can help. 



Hello Matt,

I just seen that you are using id_broker. I have never used it so i
don't know how it works.
BTW mysql supports autoincrement primary keys so you don't need
id_broker ..
you could use idMethod="native".
Probably you have a reason why you choosed id_broker, but i am on
foreign ground with it, sorry.


BW,

Andras.


---------------------------------------------------------------------
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


RE: Problems with save() method with Peer class

Posted by Matt Reath <ma...@cciinc.us>.
I'm getting a TorqueException with I do Torque.init(propfile). It
doesn't give me anymore detail than that.

Matt

-----Original Message-----
From: Matt Reath [mailto:matt.reath@cciinc.us] 
Sent: Thursday, August 07, 2003 10:10 AM
To: 'Apache Torque Users List'
Subject: RE: Problems with save() method with Peer class

Okay, I initialize torque and get a different error now:

java.lang.NullPointerException: There was no DataSourceFactory
configured for the connection ontrack

Matt

-----Original Message-----
From: Matt Reath [mailto:matt.reath@cciinc.us] 
Sent: Thursday, August 07, 2003 9:59 AM
To: 'Apache Torque Users List'
Subject: RE: Problems with save() method with Peer class

Well I've come to the conclusion that I'm an idiot and I wasn't calling
Torque.init(String filename);

Let me try this first.

-----Original Message-----
From: Andras Balogh [mailto:andras@reea.net] 
Sent: Thursday, August 07, 2003 9:48 AM
To: Apache Torque Users List
Subject: Re: Problems with save() method with Peer class


  ----- Original Message ----- 
  From: Matt Reath 
  To: 'Apache Torque Users List' 
  Sent: Thursday, August 07, 2003 5:39 PM
  Subject: RE: Problems with save() method with Peer class


  Andras,

  I've included my config files. I hope you can help. 



Hello Matt,

I just seen that you are using id_broker. I have never used it so i
don't know how it works.
BTW mysql supports autoincrement primary keys so you don't need
id_broker ..
you could use idMethod="native".
Probably you have a reason why you choosed id_broker, but i am on
foreign ground with it, sorry.


BW,

Andras.


---------------------------------------------------------------------
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


RE: Problems with save() method with Peer class

Posted by Matt Reath <ma...@cciinc.us>.
Okay, I initialize torque and get a different error now:

java.lang.NullPointerException: There was no DataSourceFactory
configured for the connection ontrack

Matt

-----Original Message-----
From: Matt Reath [mailto:matt.reath@cciinc.us] 
Sent: Thursday, August 07, 2003 9:59 AM
To: 'Apache Torque Users List'
Subject: RE: Problems with save() method with Peer class

Well I've come to the conclusion that I'm an idiot and I wasn't calling
Torque.init(String filename);

Let me try this first.

-----Original Message-----
From: Andras Balogh [mailto:andras@reea.net] 
Sent: Thursday, August 07, 2003 9:48 AM
To: Apache Torque Users List
Subject: Re: Problems with save() method with Peer class


  ----- Original Message ----- 
  From: Matt Reath 
  To: 'Apache Torque Users List' 
  Sent: Thursday, August 07, 2003 5:39 PM
  Subject: RE: Problems with save() method with Peer class


  Andras,

  I've included my config files. I hope you can help. 



Hello Matt,

I just seen that you are using id_broker. I have never used it so i
don't know how it works.
BTW mysql supports autoincrement primary keys so you don't need
id_broker ..
you could use idMethod="native".
Probably you have a reason why you choosed id_broker, but i am on
foreign ground with it, sorry.


BW,

Andras.


---------------------------------------------------------------------
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


RE: Problems with save() method with Peer class

Posted by Matt Reath <ma...@cciinc.us>.
Well I've come to the conclusion that I'm an idiot and I wasn't calling
Torque.init(String filename);

Let me try this first.

-----Original Message-----
From: Andras Balogh [mailto:andras@reea.net] 
Sent: Thursday, August 07, 2003 9:48 AM
To: Apache Torque Users List
Subject: Re: Problems with save() method with Peer class


  ----- Original Message ----- 
  From: Matt Reath 
  To: 'Apache Torque Users List' 
  Sent: Thursday, August 07, 2003 5:39 PM
  Subject: RE: Problems with save() method with Peer class


  Andras,

  I've included my config files. I hope you can help. 



Hello Matt,

I just seen that you are using id_broker. I have never used it so i
don't know how it works.
BTW mysql supports autoincrement primary keys so you don't need
id_broker ..
you could use idMethod="native".
Probably you have a reason why you choosed id_broker, but i am on
foreign ground with it, sorry.


BW,

Andras.


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


RE: Problems with save() method with Peer class

Posted by Matt Reath <ma...@cciinc.us>.
Andras,
I'll try the native method. 

Caoilte,

I get this error now.

org.apache.torque.TorqueException: Torque was not initialized properly.

How do I initialize it properly? I'm using Torque standalone in unit
tests right now, it will go in a Swing application.

Matt

-----Original Message-----
From: Andras Balogh [mailto:andras@reea.net] 
Sent: Thursday, August 07, 2003 9:48 AM
To: Apache Torque Users List
Subject: Re: Problems with save() method with Peer class


  ----- Original Message ----- 
  From: Matt Reath 
  To: 'Apache Torque Users List' 
  Sent: Thursday, August 07, 2003 5:39 PM
  Subject: RE: Problems with save() method with Peer class


  Andras,

  I've included my config files. I hope you can help. 



Hello Matt,

I just seen that you are using id_broker. I have never used it so i
don't know how it works.
BTW mysql supports autoincrement primary keys so you don't need
id_broker ..
you could use idMethod="native".
Probably you have a reason why you choosed id_broker, but i am on
foreign ground with it, sorry.


BW,

Andras.


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


Re: Problems with save() method with Peer class

Posted by Andras Balogh <an...@reea.net>.
  ----- Original Message ----- 
  From: Matt Reath 
  To: 'Apache Torque Users List' 
  Sent: Thursday, August 07, 2003 5:39 PM
  Subject: RE: Problems with save() method with Peer class


  Andras,

  I've included my config files. I hope you can help. 



Hello Matt,

I just seen that you are using id_broker. I have never used it so i don't know how it works.
BTW mysql supports autoincrement primary keys so you don't need id_broker ..
you could use idMethod="native".
Probably you have a reason why you choosed id_broker, but i am on foreign ground with it, sorry.


BW,

Andras.

RE: Problems with save() method with Peer class

Posted by Matt Reath <ma...@cciinc.us>.
Andras,

I've included my config files. I hope you can help. 

--BEGIN build.properties ---

torque.project = ontrack
torque.database = mysql

torque.targetPackage = com.cci.ontrack.data

torque.addGetByNameMethod = true
torque.addIntakeRetrievable = false
torque.addSaveMethod = true
torque.addTimeStamp = true
torque.basePrefix = Base
torque.complexObjectModel = true
torque.useClasspath = false
torque.useManagers = false

torque.database.createUrl = jdbc:mysql://127.0.0.1/mysql
torque.database.buildUrl = jdbc:mysql://127.0.0.1/ontrack
torque.database.url = jdbc:mysql://127.0.0.1/ontrack
torque.database.driver = org.gjt.mm.mysql.Driver
torque.database.user = matt
torque.database.password = <took out password>
torque.database.host = 127.0.0.1

torque.sameJavaName = false

--END build.propertise--

--BEGIN Torque.properties--

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 = ontrack
torque.database.ontrack.adapter = mysql
torque.database.ontrack.driver = org.gjt.mm.mysql.Driver
torque.database.ontrack.url = jdbc:mysql://127.0.0.1/ontrack
torque.database.ontrack.username = matt
torque.database.ontrack.password = <took out password>


--END Torque.properties

My build-torque.xml file is vanilla. I haven't edited it at all.

--BEGIN ontrack-schema.xml--

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE database SYSTEM
 "http://db.apache.org/torque/dtd/database_3_1.dtd">

<database
  name="ontrack"
  defaultIdMethod="idbroker">

  <table name="customer" description="Customer Table">
    <column
      name="customer_id"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="Customer Id"/>
    <column
      name="name"
      required="true"
      type="VARCHAR"
      size="255"
      description="Customer Name"/>
    <column
      name="address1"
      required="true"
      type="VARCHAR"
      size="255"
      description="Address"/>
    <column
      name="address2"
      required="true"
      type="VARCHAR"
      size="255"
      description="Address"/>
    <column
      name="city"
      required="true"
      type="VARCHAR"
      size="255"
      description="City"/>
    <column
      name="state"
      required="true"
      type="VARCHAR"
      size="2"
      description="State"/>
    <column
      name="zip"
      required="true"
      type="VARCHAR"
      size="15"
      description="Zip Code"/>
    <column
      name="country"
      required="true"
      type="VARCHAR"
      size="100"
      description="Country"/>
    <column
      name="phone"
      required="true"
      type="VARCHAR"
      size="15"
      description="Phone Number"/>
    <column
      name="fax"
      required="true"
      type="VARCHAR"
      size="15"
      description="Fax Number"/>
    <column
      name="website"
      required="true"
      type="VARCHAR"
      size="255"
      description="Web Address"/>
    <column
      name="email"
      required="true"
      type="VARCHAR"
      size="255"
      description="Email Address"/>
    
  </table>
  
 </database>

--END ontrack-schema.xml--

--BEGIN id-table-schema.xml--

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE database SYSTEM
"http://db.apache.org/torque/dtd/database_3_0_1.dtd">

<database name="ontrack">
  <table name="ID_TABLE" idMethod="idbroker">
    <column name="ID_TABLE_ID" required="true" primaryKey="true"
type="INTEGER"/>
    <column name="TABLE_NAME" required="true" size="255"
type="VARCHAR"/>
    <column name="NEXT_ID" type="INTEGER"/>
    <column name="QUANTITY" type="INTEGER"/>
    
    <unique>
      <unique-column name="TABLE_NAME"/>
    </unique>        
    
  </table>
</database>  

--END id-table-schema.xml--


-----Original Message-----
From: Andras Balogh [mailto:andras@reea.net] 
Sent: Thursday, August 07, 2003 9:28 AM
To: Apache Torque Users List
Subject: Re: Problems with save() method with Peer class

Hi,

This usually happens if you didn't configured correctly the
torque.properties file.
Make sure you have this line in your file:

torque.database.default=your_db_name
torque.database.your_db_name.adapter=mysql

Best wishes,

Andras.


---------------------------------------------------------------------
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


Re: Problems with save() method with Peer class

Posted by Andras Balogh <an...@reea.net>.
Hi,

This usually happens if you didn't configured correctly the
torque.properties file.
Make sure you have this line in your file:

torque.database.default=your_db_name
torque.database.your_db_name.adapter=mysql

Best wishes,

Andras.


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


Re: Problems with save() method with Peer class

Posted by Caoilte O'Connor <me...@caoilte.org>.
probably just a configuration problem, but worth noting I've 
had that problem (or something very similar) ever since I 
started using torque. 

I've never been able to find out from anyone official what's 
causing it, but I suspect its a problem (for me) that 
sneaks in when my torque setup is serialized during a 
tomcat restart/ schema change. (I use postgresql)

If there isn't just something stupid wrong with your 
Torque.properties file I solved it by doing this just after 
I initialised Torque,

CustomerMapBuilder customerBuilder = 
	new CustomerMapBuilder();
customerBuilder.doBuild();

ie rebuild the offending map.

i also did this in my copy of Torque.java initialize(c) 
function and recompiled,

if (mapBuilders == null) 
  mapBuilders = 
    Collections.synchronizedList(new ArrayList());

I'd love to know if there's a better solution / official 
reason. 

I'm using 3.0.2 and torque standalone with struts,

c


On Thursday 07 August 2003 15:21, Matt Reath wrote:
> I have a Customer table in a mysql database. The torque
> build process creates the database, tables, and source
> code with no error. When I call the customer class:
>
> Customer customer = new Customer();
> .
> .
> .
> customer.save();
>
> I get a java.lang.NullPointerException when I call the
> save method. I narrowed it down to the getMapBuilder()
> method. I can create a CustomerMapBuilder object and then
> call the getDatabaseMap() function but it gives me
> java.lang.NullPointerException. I've been trying to hunt
> the problem down but it seems to be in the torque code
> itself. I've attached my config files.
>
> If anybody could help me get this working that would be
> great.
>
> Matthew Reath
> Integration Engineer
> Cable Constructors, Inc.
> 105 Kent Street
> Iron Mountain, MI 49801
> Phone: (906) 774-6621 x2134
> Fax: (906) 774-9120
> Email: matt.reath@cciinc.us
> Web: http://www.cciinc.us


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