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 Daniel Rodriguez Millan <da...@esencialsistemas.com> on 2003/04/27 11:46:30 UTC

Error: Database insert attempted without anything specified to insert

Im getting the exception:
 
org.apache.torque.TorqueException:Database insert attempted without
anything specified to insert
 
with my first torque application
 
Could someone explain me why this exception may be raised?
 
My relevant data are:
 
Mysql db:
 
   
    <table name="loc" 
        javaName="Loc">
        <column 
            name="locId"       
            required="true"     
            primaryKey="true"   
            type="INTEGER"
            autoIncrement="true"
            javaName="locId"/>
        <column 
            name="locName"     
            required="true"    
             primaryKey="true"   
            type="VARCHAR"      
            size="100"
            javaName="locName"/>
    </table>
 
and my code raising the exception:
 
            try
                  {
                        Loc l=new Loc();
                        l.setlocId(0);
                        l.setlocName("loc");
                        LocPeer.doInsert(l);
                  }
                  catch (Exception e)
                  {
                  System.out.println("Error:"+e);
                  }     
 
i tried l.setlocName("loc") and then save, without the doInsert call and
not setting the autoincrement value, but the exception seems to be
thrown with all tables in my db :-(
 
 
any help?
 
 
 
Daniel rodriguez millan

[BUG] Torque3.0: Null pointer unchecked

Posted by Dongsheng Song <eg...@msn.com>.
Torque generate 5 java class for a table 'Group',

    BaseGroupPeer.java, GroupPeer.java, BaseGroup.java, Group.java, GroupMapBuilder.java

In GroupMapBuilder.doBuild, Torque hard code a line like 
    dbMap = Torque.getDatabaseMap("foresee");

But not check dbMap whether or not null !
I think it should be:

    dbMap = Torque.getDatabaseMap(GroupPeer.DATABASE_NAME);
    if (dbMap == null)
        throw new TorqueException("can't get database map for " + GroupPeer.DATABASE_NAME);




Torque hanging on queries

Posted by Karl Stenerud <ka...@webartjapan.com>.
Hi all,

I'm having some trouble with Torque when I run junit tests on my data model.

I have a contract data model that allows me to search for contracts based on 
certain criteria.
In my setup and teardown code for the junit test, I use this functionality to 
ensure that the test data I will be using is not present in mysql.

Unfortunately, when I run this test, it runs a few iterations for clearing the 
database and then hangs waiting for a connection object:
(Yes, I'm using ERROR for logging. sue me =P)


test:
[java] 618 [main] ERROR root  - Set up
[java] 633 [main] ERROR root  - Clean started
[java] 641 [main] ERROR root  - Searching for _addrem
[java] 1455 [main] ERROR root  - Returned searching for _addrem
[java] 1456 [main] ERROR root  - Searching for _adddup
[java] 1499 [main] ERROR root  - Returned searching for _adddup
[java] 1500 [main] ERROR root  - Searching for _find1
[java] 1560 [main] ERROR root  - Returned searching for _find1
[java] 1595 [main] ERROR root  - Searching for _find2
[java] 1680 [main] ERROR root  - Returned searching for _find2
[java] 1681 [main] ERROR root  - Searching for _changeo
[java] 1707 [main] ERROR root  - Returned searching for _changeo
[java] 1707 [main] ERROR root  - Searching for _changen
[java] 1916 [main] ERROR root  - Returned searching for _changen
[java] 1918 [main] ERROR root  - Clean finished
[java] 1932 [main] ERROR root  - testAddGetRemoveContract
[java] 1933 [main] ERROR root  - Tear down
[java] 1933 [main] ERROR root  - Clean started
[java] 1933 [main] ERROR root  - Searching for _addrem
[java] 1971 [main] ERROR root  - Returned searching for _addrem
[java] 1971 [main] ERROR root  - Searching for _adddup
[java] 2041 [main] ERROR root  - Returned searching for _adddup
[java] 2045 [main] ERROR root  - Searching for _find1
[java] 2092 [main] ERROR root  - Returned searching for _find1
[java] 2093 [main] ERROR root  - Searching for _find2
[java] 2139 [main] ERROR root  - Returned searching for _find2
[java] 2140 [main] ERROR root  - Searching for _changeo


At this point it hangs.  Interrupting it here shows it waiting for the object 
pool:

[java] "main" prio=1 tid=0x0x8052ab0 nid=0x1fac in Object.wait() 
[bfffc000..bfffc890]
[java]     at java.lang.Object.wait(Native Method)
[java]     - waiting on <0x4477da30> (a 
org.apache.commons.pool.impl.GenericKeyedObjectPool)
[java]     at 
org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(Unknown 
Source)
[java]     - locked <0x4477da30> (a 
org.apache.commons.pool.impl.GenericKeyedObjectPool)
[java]     at 
org.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource.getConnection(Jdbc2PoolDataSource.java:1096)
[java]     - locked <0x44751078> (a 
org.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource)
[java]     at 
org.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource.getConnection(Jdbc2PoolDataSource.java:1028)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:932)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:873)
[java]     at com.me.data.ContractDataModel.get(ContractDataModel.java:140)
[java]     at 
com.me.data.ContractDataModelTest.cleanDatabase(ContractDataModelTest.java:51)
[java]     at 
com.me.data.ContractDataModelTest.tearDown(ContractDataModelTest.java:73)
[java]     at junit.framework.TestCase.runBare(TestCase.java:130)
.. and more stack stuff from junit


If I use org.apache.torque.dsfactory.TorqueDataSourceFactory as torque's data 
source factory, it eventually comes back with an excepion:

[java] 1) 
testAddGetRemoveContract(com.me.data.ContractDataModelTest)com.me.data.DataException: 
org.apache.torque.TorqueException: Timed out waiting for pooled connection 
from 'null'
[java]     at com.me.data.ContractDataModel.get(ContractDataModel.java:161)
[java]     at 
com.me.data.ContractDataModelTest.cleanDatabase(ContractDataModelTest.java:51)
[java]     at 
com.me.data.ContractDataModelTest.tearDown(ContractDataModelTest.java:75)
[java]     at com.me.AllTests.main(AllTests.java:12)
[java] Caused by: org.apache.torque.TorqueException: Timed out waiting for 
pooled connection from 'null'
[java]     at org.apache.torque.Torque.getConnection(Torque.java:944)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:873)
[java]     at com.me.data.ContractDataModel.get(ContractDataModel.java:140)
[java]     ... 15 more
[java] Caused by: java.sql.SQLException: Timed out waiting for pooled 
connection from 'null'
[java]     at 
org.apache.torque.pool.ConnectionPool.getConnection(ConnectionPool.java:242)
[java]     at 
org.apache.torque.pool.TorqueClassicDataSource.getConnection(TorqueClassicDataSource.java:466)
[java]     at 
org.apache.torque.pool.TorqueClassicDataSource.getConnection(TorqueClassicDataSource.java:437)
[java]     at org.apache.torque.Torque.getConnection(Torque.java:932)
[java]     ... 17 more


If I use org.apache.torque.dsfactory.Jdbc2PoolDataSourceFactory, it never 
comes back at all.


This is the code that I'm running.  Not included is ContractSearchCriteria and 
ContractBDO which are just simple beans.


public class ContractDataModel {
...
    /**
     * Get contracts by some search criteria.
     * Data is retrieved by a simple AND query containing all criteria 
specified.
     *
     * @param criteria determins which parts of data to include in the query
     * @return a list of contracts.  This list may be empty.
     */
    public static Collection get(ContractSearchCriteria criteria)
      throws DataException {

        QueryDataSet qds = null;
        List list = new LinkedList();

        try {

            StringBuffer stmt = new StringBuffer();
            stmt.append(
            "select contract.*,"
            + "     IF((user.disabledDate is null) "
            + "     OR (user.disabledDate <= CURRENT_DATE),\"true\",\"false\") 
isActive"
            + " from "
            + "     contract,"
            + "     user"
            + " where" 
            + "     contract.contractUser = user.id"
            );

            if(!criteria.getShowInactive())
                stmt.append(" and disabledDate is null");
            if(criteria.getApplicationNumberPresent())
                stmt.append(" and applicationNumber like '" + 
criteria.getApplicationNumber() + "'");
            if(criteria.getNamePresent())
                stmt.append(" and name like '" + criteria.getName() + "'");
            if(criteria.getAddressPresent())
                stmt.append(" and address like '" + criteria.getAddress() + 
"'");
            if(criteria.getPhoneNumberPresent())
                stmt.append(" and phoneNumber like '" + 
criteria.getPhoneNumber() + "'");
            if(criteria.getUsernamePresent())
                stmt.append(" and username like '" + criteria.getUsername() + 
"'");

            ContractBDO contract;
            qds = new QueryDataSet ( Torque.getConnection(), stmt.toString() 
);
            qds.fetchRecords();
            for ( int i = 0; i < qds.size(); i++ )
            {
                contract = new ContractBDO();
                Record rec = qds.getRecord(i);
                contract.setContractId(rec.getValue("id").asInt());
                
contract.setApplicationNumber(rec.getValue("applicationNumber").asString());
                contract.setName(rec.getValue("name").asString());
                contract.setAddress(rec.getValue("address").asString());
                
contract.setPhoneNumber(rec.getValue("phoneNumber").asString());
                
contract.setContractUser(rec.getValue("contractUser").asInt());
                contract.setIsActive(rec.getValue("isActive").asBoolean());
                list.add(contract);
            }
        } catch(Exception exc) {
            throw new DataException(exc);
        } finally {
            try {
                if(qds != null)
                    qds.close();
            } catch(Exception exc) {
                throw new DataException(exc);
            }
        }
        return list;
    }
...
}


public class ContractDataModelTest extends TestCase {

	public static void main (String[] args) {
		junit.textui.TestRunner.run(suite());
	}

	public static Test suite() {
		return new TestSuite(ContractDataModelTest.class);
	}

    private static final String NAME_ADD_GET_REMOVE = "_addrem";
    private static final String NAME_ADD_DUPLICATE = "_adddup";
    private static final String NAME_FIND_1 = "_find1";
    private static final String NAME_FIND_2 = "_find2";
    private static final String NAME_CHANGE_OLD = "_changeo";
    private static final String NAME_CHANGE_NEW = "_changen";

    private static final List nameList;
    
    static {
        List list = new LinkedList();
        list.add(NAME_ADD_GET_REMOVE);
        list.add(NAME_ADD_DUPLICATE);
        list.add(NAME_FIND_1);
        list.add(NAME_FIND_2);
        list.add(NAME_CHANGE_OLD);
        list.add(NAME_CHANGE_NEW);
        nameList = new LinkedList(list);
    }

    private void cleanDatabase() 
      throws Exception {
         org.apache.log4j.Logger.getRootLogger().error("Clean started");
         // Clear test data from database
        Collection coll;
        ContractSearchCriteria crit = new ContractSearchCriteria();
        ContractBDO data = new ContractBDO();

        for(Iterator iter=nameList.iterator();iter.hasNext();) {
            crit.setName((String)iter.next());
            org.apache.log4j.Logger.getRootLogger().error("Searching for " + 
crit.getName());
            coll = ContractDataModel.get(crit);
            org.apache.log4j.Logger.getRootLogger().error("Returned searching 
for " + crit.getName());
            if(!coll.isEmpty()) {
                org.apache.log4j.Logger.getRootLogger().error("Removing " + 
crit.getName());
                
ContractDataModel.remove(((ContractBDO)coll.iterator().next()).getContractId());
            }
        }
        org.apache.log4j.Logger.getRootLogger().error("Clean finished");
    }
    
    protected void setUp() 
      throws Exception {
        // Set up torque
        com.me.TestHelper.usingDatabase();

        org.apache.log4j.Logger.getRootLogger().error("Set up");
        cleanDatabase();
    }

    protected void tearDown()
      throws Exception {
        org.apache.log4j.Logger.getRootLogger().error("Tear down");
        cleanDatabase();
    }

    public void testAddGetRemoveContract() {
        
org.apache.log4j.Logger.getRootLogger().error("testAddGetRemoveContract");
    }
}


The Torque JDBC2 Pool Howto mentions using commons-dbcp that is newer than 
1.0-dev (the one shipped with torque 3.0 is commons-dbcp-1.0-dev-20020806), 
so I've tried it with the non-dev 1.0 release as well as with the CVS 
snapshot from yesterday.
Is there anything else I'm missing that would cause this behavior?


RE: Error: Database insert attempted without anything specified to insert

Posted by Daniel Rodriguez Millan <da...@esencialsistemas.com>.
Problem solved, thanks a lot, Bill

The db was set to idbroker, i had to unset the primarykeys and then set
unique-columns on my unique fields





Re: Error: Database insert attempted without anything specified to insert

Posted by Bill Schneider <bs...@vecna.com>.
Daniel,

First you need to set idMethod="native" or idMethod="idbroker" at the
<database> level, in order for autoIncrement="true" to have any effect.

Second, you only want locId (the autoIncrement column) to be your primary
key.  locName should not also be a primary key.  You should specify
unique/not-null constraints and indexes for locName separately, if
appropriate.

I recall that Torque will try to auto-increment any column that is
designated "primaryKey" regardless of the "autoIncrement" attribute.  So
there could be problems if Torque was trying to auto-increment your locName
column.  (Not sure if that's still the case.)

-- Bill

----- Original Message -----
From: "Daniel Rodriguez Millan" <da...@esencialsistemas.com>
To: <to...@db.apache.org>
Sent: Sunday, April 27, 2003 5:46 AM
Subject: Error: Database insert attempted without anything specified to
insert


> Im getting the exception:
>
> org.apache.torque.TorqueException:Database insert attempted without
> anything specified to insert
>
> with my first torque application
>
> Could someone explain me why this exception may be raised?
>
> My relevant data are:
>
> Mysql db:
>
>
>     <table name="loc"
>         javaName="Loc">
>         <column
>             name="locId"
>             required="true"
>             primaryKey="true"
>             type="INTEGER"
>             autoIncrement="true"
>             javaName="locId"/>
>         <column
>             name="locName"
>             required="true"
>              primaryKey="true"
>             type="VARCHAR"
>             size="100"
>             javaName="locName"/>
>     </table>
>
> and my code raising the exception:
>
>             try
>                   {
>                         Loc l=new Loc();
>                         l.setlocId(0);
>                         l.setlocName("loc");
>                         LocPeer.doInsert(l);
>                   }
>                   catch (Exception e)
>                   {
>                   System.out.println("Error:"+e);
>                   }
>
> i tried l.setlocName("loc") and then save, without the doInsert call and
> not setting the autoincrement value, but the exception seems to be
> thrown with all tables in my db :-(
>
>
> any help?
>
>
>
> Daniel rodriguez millan
>