You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2007/02/14 15:05:33 UTC

Problem with DataPort & Tomcat

We've been using a modified DataPort w/Jetty for a while and never had
any problems.

However, today we tried running it under Tomcat and it failed.


Paraphrased from my source, I do the following:


SelectQuery select = new SelectQuery(entity);
select.setFetchingDataRows(true);
IteratedSelectObserver observer = new IteratedSelectObserver();
sourceNode.performQueries(Collections.singletonList(select), observer);
ResultIterator result = observer.getResultIterator();
if (result.hasNextRow())
{
// works fine w/jetty, but throws exception below w/Tomcat 5.5.20
	Map nextRow = result.nextDataRow();


The DataSource is configured in Tomcat as follows:

<Resource name="jdbc/qpbuser" auth="Container"
          type="javax.sql.DataSource"
          driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
          url="jdbc:derby:c:\workspace\qpbtapestry\testdb\demo_derby;create=true"
          username="" password="" maxActive="5" maxIdle="2"/>




In the Tomcat log I find the below:

56875 [http-8080-Processor25] INFO
org.objectstyle.cayenne.access.QueryLogger  - --- will run 1 query.
56875 [http-8080-Processor25] INFO
org.objectstyle.cayenne.access.QueryLogger  - SELECT
t0.TREATASPECR_ID, t0.TREATASPEC_ACTIVE, t0.TREATASPEC_CRITID,
t0.TREATASPEC_FIXEDCOST, t0.TREATASPEC_ID, t0.TREATASPEC_QTYPE,
t0.TREATASPEC_VC1, t0.TREATASPEC_VC2, t0.TREATASPEC_VC2CRITID,
t0.TREATASPEC_VC2FIXEDCOST, t0.TREATASPEC_VC2QTYPE, t0.TREATASPEC_VC3,
t0.TREATASPEC_VC3CRITID, t0.TREATASPEC_VC3FIXEDCOST,
t0.TREATASPEC_VC3QTYPE, t0.TREATASPEC_VC4, t0.TREATASPEC_VC4CRITID,
t0.TREATASPEC_VC4FIXEDCOST, t0.TREATASPEC_VC4QTYPE, t0.TREATASPEC_VC5,
t0.treataspec_rolehastoclose FROM TREAT_AREASPEC t0
org.objectstyle.cayenne.CayenneException: [v.1.2.1 August 30 2006]
Exception materializing column.
	at org.objectstyle.cayenne.access.jdbc.JDBCResultIterator.readDataRow(JDBCResultIterator.java:342)
	at org.objectstyle.cayenne.access.jdbc.JDBCResultIterator.nextDataRow(JDBCResultIterator.java:181)
	at com.zylin.payback.app.db.data.tools.DataPort.processInsert(DataPort.java:204)
	at com.zylin.payback.app.db.data.tools.DataPort.execute(DataPort.java:106)
	at com.zylin.payback.app.html.Backup.execute(Backup.java:162)
	at com.zylin.payback.app.html.Backup.backup(Backup.java:73)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.tapestry.listener.ListenerMap.invokeTargetMethod(ListenerMap.java:257)
	at org.apache.tapestry.listener.ListenerMap.access$100(ListenerMap.java:46)
	at org.apache.tapestry.listener.ListenerMap$SyntheticListener.invoke(ListenerMap.java:97)
	at org.apache.tapestry.listener.ListenerMap$SyntheticListener.actionTriggered(ListenerMap.java:102)
	at org.apache.tapestry.link.DirectLink.trigger(DirectLink.java:119)
	at org.apache.tapestry.engine.DirectService.service(DirectService.java:169)
	at org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:889)
	at org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:198)
	at org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java:159)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
	at com.zylin.payback.app.tapestry.SequentialSessionFilter.doFilter(SequentialSessionFilter.java:27)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
	at java.lang.Thread.run(Unknown Source)
Caused by: SQL Exception: ResultSet not open. Operation 'getXXX' not
permitted. Verify that autocommit is OFF.
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.checkIfClosed(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.getColumn(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
	at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:174)
	at org.objectstyle.cayenne.access.types.CharType.materializeObject(CharType.java:152)
	at org.objectstyle.cayenne.access.jdbc.JDBCResultIterator.readDataRow(JDBCResultIterator.java:327)
	... 37 more



This is the interesting part of our modified DataPort routine:



  /**
     * Reads source data from source, saving it to destination.
     */
    protected void processInsert(List entities) throws CayenneException {
        // Allow delegate to modify the list of entities
        // any way it wants. For instance delegate may filter
        // or sort the list (though it doesn't have to, and can simply
        // pass through the original list).

        if (entities == null || entities.isEmpty()) {
            return;
        }


        // process ordered list of entities one by one
        Iterator it = entities.iterator();
        while (it.hasNext()) {

            DbEntity entity = (DbEntity) it.next();

            // skip derived DbEntities...
            if (entity instanceof DerivedDbEntity) {
                continue;
            }

            try
			{
				SelectQuery select = new SelectQuery(entity);
				select.setFetchingDataRows(true);

		       // Using QueryResult as observer for the data insert.
		        // This allows to collect query statistics and pass it to
the delegate.
		        QueryResult insertObserver = new QueryResult();
	            insertObserver.clear();
	
		        // Create an observer for to get the iterated result
		        // instead of getting each table as a list
				// delegate is allowed to substitute query
		        IteratedSelectObserver observer = new IteratedSelectObserver();
				sourceNode.performQueries(Collections.singletonList(select), observer);
				ResultIterator result = observer.getResultIterator();
				try {

				    // Batch size 1.

				    while (result.hasNextRow())
					{
						// end of the batch detected... commit and start a new
						// insert query
						InsertBatchQuery insert = new InsertBatchQuery(entity,
								1);
						insertObserver.clear();

						Map nextRow = result.nextDataRow();
						insert.add(nextRow);
						try
						{
							destinationNode.performQueries(Collections
									.singletonList(insert), insertObserver);
						} catch (Exception e)
						{
							e.printStackTrace();
						}
					}
				}
				finally {
				    try {
				        // don't forget to close ResultIterator
				        result.close();
				    }
				    catch (CayenneException ex) {
				    }
				}
			} catch (CayenneException e)
			{
				/* Continue anyway */
				e.printStackTrace();
			}
        }
    }


-- 
Øyvind Harboe
http://www.zylin.com

matching row is missing error

Posted by Frank <fa...@hotmail.com>.
Hi Andrus,

I am not sure if this is a Click or Cayenne problem.

I have a two table relation defined and am getting an error when a matching
record is not found in the second table.
This works fine until I do a search that does not have a matching row.

Here is my query:

     DataContext context = DataContext.getThreadDataContext();
     Integer[] hspArray = {new Integer(1), new Integer(5)};
     Expression e = ExpressionFactory.inDbExp(Bsypemp.EMHSPPOUND_PK_COLUMN,
hspArray);
        e =
e.andExp(ExpressionFactory.likeIgnoreCaseExp(Bsypemp.EMYLNM_PROPERTY, lname
        +"%"));
        e =
e.andExp(ExpressionFactory.likeIgnoreCaseExp(Bsypemp.EMYFNM_PROPERTY, fname
                +"%"));

     SelectQuery query = new SelectQuery(Bsypemp.class,e);
     List records = context.performQuery(query);
     return records;


 column = new Column("departments.Pcldds");
        column.setHeaderTitle("Department");
        column.setWidth("15%;");
        column.setAttribute("align", "left");
        column.setSortable(true);
        table.addColumn(column);

Caused by: org.objectstyle.cayenne.FaultFailureException: [v.1.2.2 January
10 2007] Error resolving fault for ObjectId: <ObjectId:Bprppcp, PCDEP4=0,
PCHSP#=5> and state (transient). Possible cause - matching row is missing
from the database.


Thanks
Frank


Re: Cayenne doc link failure

Posted by Andrus Adamchik <an...@objectstyle.org>.
Thanks for pointing it out - that's an old link, I'll fix it.

Andrus


On Feb 14, 2007, at 11:49 AM, Frank wrote:

> Hello,
>
> I click on the documentation link
> Cayenne Documentation - v. 1.2 (STABLE)
> User Guide: General information on how to get started with Cayenne,  
> main Cayenne concepts, API details and deployment procedures.
>
> From here
>
> User guide
>  1.. Introduction
>  2.. Installation
>  3.. Quick Start
>  4.. Design
>  5.. DataContext
>  6.. Queries
>  7.. DataObjects
>  8.. Stored Procedures
>  9.. Expressions
>  10.. Performance Tuning
>  11.. Deployment
>  12.. Ant Tasks
>  13.. Customizing
>  14.. DataViews
> I click on DataObjects
>
> DataObjects (Cayenne persistent objects) are composed of attributes  
> and relationships. Attributes are the simplest object properties  
> (as in "java bean properties") that can be stored in the columns in  
> the database. Those are usually string, numeric, binary or date  
> values. Another type of properties is relationships. They represent  
> related DataObjects (to-one relationships) or collections of  
> DataObjects (to-many relationships). To read and modify attributes  
> and relationships, application code would simply invoke  
> corresponding get or set methods. In case of to-many relationships  
> represented by collections there are also add and remove methods.
>
> Again I click on DataObjects
>
> Not Found
> The requested URL /cayenne/doc12/api/cayenne/org/objectstyle/ 
> cayenne/DataObject.html was not found on this server.
>
> HTH
>
> Frank


Cayenne doc link failure

Posted by Frank <fa...@hotmail.com>.
Hello,

I click on the documentation link
Cayenne Documentation - v. 1.2 (STABLE)
User Guide: General information on how to get started with Cayenne, main 
Cayenne concepts, API details and deployment procedures.

>From here

User guide
  1.. Introduction
  2.. Installation
  3.. Quick Start
  4.. Design
  5.. DataContext
  6.. Queries
  7.. DataObjects
  8.. Stored Procedures
  9.. Expressions
  10.. Performance Tuning
  11.. Deployment
  12.. Ant Tasks
  13.. Customizing
  14.. DataViews
I click on DataObjects

DataObjects (Cayenne persistent objects) are composed of attributes and 
relationships. Attributes are the simplest object properties (as in "java 
bean properties") that can be stored in the columns in the database. Those 
are usually string, numeric, binary or date values. Another type of 
properties is relationships. They represent related DataObjects (to-one 
relationships) or collections of DataObjects (to-many relationships). To 
read and modify attributes and relationships, application code would simply 
invoke corresponding get or set methods. In case of to-many relationships 
represented by collections there are also add and remove methods.

Again I click on DataObjects

Not Found
The requested URL 
/cayenne/doc12/api/cayenne/org/objectstyle/cayenne/DataObject.html was not 
found on this server.

HTH

Frank

Re: Problem with DataPort & Tomcat

Posted by Øyvind Harboe <oy...@zylin.com>.
On 2/14/07, Andrus Adamchik <an...@objectstyle.org> wrote:
> Just a guess without digging through the code details - a different
> DataSource implementation in Tomcat (DBCP) does something
> differently. Try using the same DataSource you used in Jetty.

I changed my connection config in Tomcat as below and it worked. Thanks!

I blithely copied something I found while googling, I don't actually
know anything about org.objectstyle.cayenne.conn.ContainerPoolFactory,
or why Cayenne would implement such a thing in the first place.

I find this a bit spooky... Why would my code break with Tomcat
connection pooling???

I wrote connection configuration according to the examples in the Tomcat doc.

>From (fails):

  <Resource name="jdbc/qpb" auth="Container"
          type="javax.sql.DataSource"
          driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
          url="jdbc:derby:c:\workspace\qpbtapestry\testdb\demo_derby;create=true"
          username="" password="" maxActive="5" maxIdle="2"
          />

To (which works):

  <Resource name="jdbc/qpb" auth="Container"
          type="javax.sql.DataSource"
          driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
          url="jdbc:derby:c:\workspace\qpbtapestry\testdb\demo_derby;create=true"
          username="" password="" maxActive="5" maxIdle="2"
  factory="org.objectstyle.cayenne.conn.ContainerPoolFactory"
          />


-- 
Øyvind Harboe
http://www.zylin.com

Re: Problem with DataPort & Tomcat

Posted by Andrus Adamchik <an...@objectstyle.org>.
> Did I find a bug or is this expected behavior?

Don't know. Generally DBCP pool is very stable. So it is hard to say  
without actually getting to the cause of the problem.

Andrus


On Feb 15, 2007, at 1:57 PM, Øyvind Harboe wrote:

> On 2/14/07, Andrus Adamchik <an...@objectstyle.org> wrote:
>> Just a guess without digging through the code details - a different
>> DataSource implementation in Tomcat (DBCP) does something
>> differently. Try using the same DataSource you used in Jetty.
>
> Did I find a bug or is this expected behavior?
>
> Being ignorant about what's actually going on, I point my finger at
> DataPort. We're not experiencing any other problems with the database
> configured in this fashion....
>
> -- 
> Øyvind Harboe
> http://www.zylin.com
>


Re: Problem with DataPort & Tomcat

Posted by Øyvind Harboe <oy...@zylin.com>.
On 2/14/07, Andrus Adamchik <an...@objectstyle.org> wrote:
> Just a guess without digging through the code details - a different
> DataSource implementation in Tomcat (DBCP) does something
> differently. Try using the same DataSource you used in Jetty.

Did I find a bug or is this expected behavior?

Being ignorant about what's actually going on, I point my finger at
DataPort. We're not experiencing any other problems with the database
configured in this fashion....

-- 
Øyvind Harboe
http://www.zylin.com

Re: Problem with DataPort & Tomcat

Posted by Andrus Adamchik <an...@objectstyle.org>.
Just a guess without digging through the code details - a different  
DataSource implementation in Tomcat (DBCP) does something  
differently. Try using the same DataSource you used in Jetty.

Andrus


On Feb 14, 2007, at 9:05 AM, Øyvind Harboe wrote:

> We've been using a modified DataPort w/Jetty for a while and never had
> any problems.
>
> However, today we tried running it under Tomcat and it failed.