You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Krzysztof <ya...@gmail.com> on 2009/03/12 15:50:35 UTC

Uinable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Hello,
I'm trying to get basic table function running without much success.
Either error is misleading or I missed some basic point, could you
please advise?

public class DerbyBlobTableFunction {

 //this works
  public static int returnSth()
    {
        return 1;
    }

//does not work, see error below
 public static ResultSet getTSValuesEmpty()  throws SQLException
    {
         List<double[]> results = new ArrayList<double[]>();
        results.add(new double[]{1.0,2.0,3.0});
         ResultSet rs = new ResultSetTemplate(results);
--//ResultSetTemplate implements ResultSet but same error with Derby
impl of ResultSet
        return rs;
    }

}


then


CALL SQLJ.install_jar
('/pathto/kn.jar', 'APP.kn', 0); -- OK

CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
('derby.database.classpath', 'APP.kn'); --OK


CREATE FUNCTION MYFUNC() returns int PARAMETER STYLE JAVA reads
sql data language JAVA EXTERNAL NAME
''gaia.cu7.dal.DerbyBlobTableFunction.returnSth'; --OK

values MYFUNC() ; --OK
returns:

1


CREATE FUNCTION getTSValuesEmpty()
RETURNS TABLE	
(	
  obs      double,
  val      double,	
  valError double
)
LANGUAGE JAVA
PARAMETER STYLE DERBY_JDBC_RESULT_SET
reads SQL data --  switching to no sql does not change
EXTERNAL NAME ''gaia.cu7.dal.DerbyBlobTableFunction.getTSValuesEmpty'
--OK

then:

select * from table ( getTSValuesEmpty() ) t;

gives:

An error occurred when executing the SQL command:
select * from table ( getTSValuesEmpty() ) t
The exception 'java.lang.ClassNotFoundException:
gaia.cu7.dal.DerbyBlobTableFunction' was thrown while evaluating an
expression. [SQL State=38000, DB Errorcode=20000]
Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
java.lang.ClassNotFoundException'. [SQL State=XJ001]

Execution time: 0.04s

1 statement(s) failed.


_but_

values getTSValuesEmpty();

gives:
1
gaia.cu7.dal.ResultSetTemplate@10fa2e17


MacOS,  Derby 10.4.2.0, embedded mode.


Could you please enlighten me what could be wrong? Seems error message
is plain wrong as 'values' returns the reference to resultset, and
regular function from the same class works as well as values call..

Best regards,
Krzysztof

Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Krzysztof N <ya...@gmail.com>.
Hello Rick,
Thank you for the response, below is the log for values  and then select
calls:

009-03-25 10:41:58.336 GMT Thread[SQL Execution Thread 1,6,main] (XID =
1819), (SESSIONID = 0), (DATABASE =data/surveys/db), (DRDAID = null), Begin
compiling pre
pared statement: values getTSValuesEmpty() :End prepared statement
2009-03-25 10:41:58.340 GMT Thread[SQL Execution Thread 1,6,main] (XID =
1819), (SESSIONID = 0), (DATABASE = data/surveys/db), (DRDAID = null), End
compiling prepa
red statement: values getTSValuesEmpty() :End prepared statement
2009-03-25 10:41:58.342 GMT Thread[SQL Execution Thread 1,6,main] (XID =
1819), (SESSIONID = 0), (DATABASE = data/surveys/db), (DRDAID = null),
Executing prepared 
statement: values getTSValuesEmpty() :End prepared statement
2009-03-25 10:41:58.344 GMT Thread[SQL Execution Thread 1,6,main] (XID =
1819), (SESSIONID = 0), values getTSValuesEmpty() ******* Row ResultSet:
Number of opens = 1
Rows returned = 1
        constructor time (milliseconds) = 0
        open time (milliseconds) = 0
        next time (milliseconds) = 0
        close time (milliseconds) = 0
        optimizer estimated row count:            1.00
        optimizer estimated cost:            0.00


And 
select * from table ( getTSValuesEmpty() ) t;
<log>
2009-03-25 10:43:57.568 GMT Thread[SQL Execution Thread 1,6,main] (XID =
1819), (SESSIONID = 0), (DATABASE = data/surveys/db), (DRDAID = null), Error
compiling prepared statement: select * from 
table ( getTSValuesEmpty() ) t :End prepared statement
2009-03-25 10:43:57.568 GMT Thread[SQL Execution Thread 1,6,main] (XID =
1819), (SESSIONID = 0), (DATABASE = data/surveys/db), (DRDAID = null),
Cleanup action starting
2009-03-25 10:43:57.568 GMT Thread[SQL Execution Thread 1,6,main] (XID =
1819), (SESSIONID = 0), (DATABASE = data/surveys/db), (DRDAID = null),
Failed Statement is: select * from table ( getTSValuesEmpty() ) t
ERROR 38000: The exception 'java.lang.ClassNotFoundException:
gaia.cu7.dal.DerbyBlobTableFunction' was thrown while evaluating an
expression.
        at
org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
        at
org.apache.derby.iapi.error.StandardException.unexpectedUserException(Unknown
Source)
        at
org.apache.derby.impl.sql.compile.FromVTI.implementsDerbyStyleVTICosting(Unknown
Source)
        at org.apache.derby.impl.sql.compile.FromVTI.bindVTITables(Unknown
Source)
        at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown
Source)
        at
org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown
Source)
        at
org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown
Source)
        at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown
Source)
        at
org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
        at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown
Source)
        at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown
Source)
        at
org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown
Source)
        at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown
Source)
...
Caused by: java.lang.ClassNotFoundException:
gaia.cu7.dal.DerbyBlobTableFunction
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        ... 17 more
============= begin nested exception, level (1) ===========
java.lang.ClassNotFoundException: gaia.cu7.dal.DerbyBlobTableFunction
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at
org.apache.derby.impl.sql.compile.FromVTI.implementsDerbyStyleVTICosting(Unknown
Source)
        at org.apache.derby.impl.sql.compile.FromVTI.bindVTITables(Unknown
Source)
        at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown
Source)
        at
org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown
Source)
        at
org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown
Source)
        at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown
Source)
        at
org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
        at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown
Source)
        at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown
Source)
        at
org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown
Source)
        at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown
Source)
...
============= end nested exception, level (1) ===========
Cleanup action completed
</log>


plus in the log there are two lines when calling 'values' indicating both
missing classes are recognized:

Loaded gaia.cu7.dal.DerbyBlobTableFunction from database jar
"APP"."VariFramework"
...
Loaded gaia.cu7.dal.Cu7ResultSetTemplate from database jar
"APP"."VariFramework"
...

I attached my dummy implementation of ResultSet, dependencies are really
basic.

http://www.nabble.com/file/p22699329/Cu7ResultSetTemplate.java
Cu7ResultSetTemplate.java 

Best regards,
Krzysztof





Rick Hillegas-2 wrote:
> 
> Hi Krzysztof,
> 
> Is there a full stack trace in derby.log which you could include? The 
> SQL state 38000 appears when Derby wraps an exception originally thrown 
> by user-written code. Is it possible that the execution logic of your 
> ResultSet references a class which is not present in the jar file you 
> loaded?
> 
> I have verified your final experiment: Derby lets you invoke a table 
> function as a scalar function via the values clause. In this situation, 
> Derby just returns the ResultSet produced by the table function. This 
> looks odd to me. I don't think that you should be allowed to invoke a 
> table function as a scalar function. I will log a bug against this.
> 
> Thanks,
> -Rick
> 
> Krzysztof wrote:
>> Hello,
>> I'm trying to get basic table function running without much success.
>> Either error is misleading or I missed some basic point, could you
>> please advise?
>>
>> public class DerbyBlobTableFunction {
>>
>>  //this works
>>   public static int returnSth()
>>     {
>>         return 1;
>>     }
>>
>> //does not work, see error below
>>  public static ResultSet getTSValuesEmpty()  throws SQLException
>>     {
>>          List<double[]> results = new ArrayList<double[]>();
>>         results.add(new double[]{1.0,2.0,3.0});
>>          ResultSet rs = new ResultSetTemplate(results);
>> --//ResultSetTemplate implements ResultSet but same error with Derby
>> impl of ResultSet
>>         return rs;
>>     }
>>
>> }
>>
>>
>> then
>>
>>
>> CALL SQLJ.install_jar
>> ('/pathto/kn.jar', 'APP.kn', 0); -- OK
>>
>> CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
>> ('derby.database.classpath', 'APP.kn'); --OK
>>
>>
>> CREATE FUNCTION MYFUNC() returns int PARAMETER STYLE JAVA reads
>> sql data language JAVA EXTERNAL NAME
>> ''gaia.cu7.dal.DerbyBlobTableFunction.returnSth'; --OK
>>
>> values MYFUNC() ; --OK
>> returns:
>>
>> 1
>>
>>
>> CREATE FUNCTION getTSValuesEmpty()
>> RETURNS TABLE	
>> (	
>>   obs      double,
>>   val      double,	
>>   valError double
>> )
>> LANGUAGE JAVA
>> PARAMETER STYLE DERBY_JDBC_RESULT_SET
>> reads SQL data --  switching to no sql does not change
>> EXTERNAL NAME ''gaia.cu7.dal.DerbyBlobTableFunction.getTSValuesEmpty'
>> --OK
>>
>> then:
>>
>> select * from table ( getTSValuesEmpty() ) t;
>>
>> gives:
>>
>> An error occurred when executing the SQL command:
>> select * from table ( getTSValuesEmpty() ) t
>> The exception 'java.lang.ClassNotFoundException:
>> gaia.cu7.dal.DerbyBlobTableFunction' was thrown while evaluating an
>> expression. [SQL State=38000, DB Errorcode=20000]
>> Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
>> java.lang.ClassNotFoundException'. [SQL State=XJ001]
>>
>> Execution time: 0.04s
>>
>> 1 statement(s) failed.
>>
>>
>> _but_
>>
>> values getTSValuesEmpty();
>>
>> gives:
>> 1
>> gaia.cu7.dal.ResultSetTemplate@10fa2e17
>>
>>
>> MacOS,  Derby 10.4.2.0, embedded mode.
>>
>>
>> Could you please enlighten me what could be wrong? Seems error message
>> is plain wrong as 'values' returns the reference to resultset, and
>> regular function from the same class works as well as values call..
>>
>> Best regards,
>> Krzysztof
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Uinable-to-use-Table-function-due-to-java.lang.ClassNotFoundException--while-class-is-clearly-reachable..-tp22478383p22699329.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Uinable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Rick Hillegas <Ri...@Sun.COM>.
Hi Krzysztof,

Is there a full stack trace in derby.log which you could include? The 
SQL state 38000 appears when Derby wraps an exception originally thrown 
by user-written code. Is it possible that the execution logic of your 
ResultSet references a class which is not present in the jar file you 
loaded?

I have verified your final experiment: Derby lets you invoke a table 
function as a scalar function via the values clause. In this situation, 
Derby just returns the ResultSet produced by the table function. This 
looks odd to me. I don't think that you should be allowed to invoke a 
table function as a scalar function. I will log a bug against this.

Thanks,
-Rick

Krzysztof wrote:
> Hello,
> I'm trying to get basic table function running without much success.
> Either error is misleading or I missed some basic point, could you
> please advise?
>
> public class DerbyBlobTableFunction {
>
>  //this works
>   public static int returnSth()
>     {
>         return 1;
>     }
>
> //does not work, see error below
>  public static ResultSet getTSValuesEmpty()  throws SQLException
>     {
>          List<double[]> results = new ArrayList<double[]>();
>         results.add(new double[]{1.0,2.0,3.0});
>          ResultSet rs = new ResultSetTemplate(results);
> --//ResultSetTemplate implements ResultSet but same error with Derby
> impl of ResultSet
>         return rs;
>     }
>
> }
>
>
> then
>
>
> CALL SQLJ.install_jar
> ('/pathto/kn.jar', 'APP.kn', 0); -- OK
>
> CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
> ('derby.database.classpath', 'APP.kn'); --OK
>
>
> CREATE FUNCTION MYFUNC() returns int PARAMETER STYLE JAVA reads
> sql data language JAVA EXTERNAL NAME
> ''gaia.cu7.dal.DerbyBlobTableFunction.returnSth'; --OK
>
> values MYFUNC() ; --OK
> returns:
>
> 1
>
>
> CREATE FUNCTION getTSValuesEmpty()
> RETURNS TABLE	
> (	
>   obs      double,
>   val      double,	
>   valError double
> )
> LANGUAGE JAVA
> PARAMETER STYLE DERBY_JDBC_RESULT_SET
> reads SQL data --  switching to no sql does not change
> EXTERNAL NAME ''gaia.cu7.dal.DerbyBlobTableFunction.getTSValuesEmpty'
> --OK
>
> then:
>
> select * from table ( getTSValuesEmpty() ) t;
>
> gives:
>
> An error occurred when executing the SQL command:
> select * from table ( getTSValuesEmpty() ) t
> The exception 'java.lang.ClassNotFoundException:
> gaia.cu7.dal.DerbyBlobTableFunction' was thrown while evaluating an
> expression. [SQL State=38000, DB Errorcode=20000]
> Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
> java.lang.ClassNotFoundException'. [SQL State=XJ001]
>
> Execution time: 0.04s
>
> 1 statement(s) failed.
>
>
> _but_
>
> values getTSValuesEmpty();
>
> gives:
> 1
> gaia.cu7.dal.ResultSetTemplate@10fa2e17
>
>
> MacOS,  Derby 10.4.2.0, embedded mode.
>
>
> Could you please enlighten me what could be wrong? Seems error message
> is plain wrong as 'values' returns the reference to resultset, and
> regular function from the same class works as well as values call..
>
> Best regards,
> Krzysztof
>   


Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Rick Hillegas <Ri...@Sun.COM>.
Hi Krzysztof,

It is interesting that you are getting ClassNotFoundException when 
executing the vti as a scalar function. Previously, that experiment 
succeeded for you. One thing I notice from your previous, successful 
resolution of the scalar function is that Derby loaded the class from 
your "VariFramework" jar. The following snippet comes from the piece of 
the Derby log which you posted on March 25:

    Loaded gaia.cu7.dal.DerbyBlobTableFunction from database jar 
"APP"."VariFramework"

But now your code is expecting to find the class in a different jar 
file, viz., "kn". Are you confident that the class is in the correct jar 
file and that the database classpath is correct? What happens when you 
invoke the MYFUNC scalar function which you have bound to 
gaia.cu7.dal.DerbyBlobTableFunction.returnSth?

Thanks,
-Rick



Krzysztof N wrote:
> Hello Rick,
> Thank you for fast response. Still have some issues though - I am using
> trunk version, repeated installation of jars - same way as before.
> Both scalar 'values' and table function call give ClassNotFoundException
> originating from ReflectClassesJava2:loadClassNotInDatabaseJar now:
>
> <log>
> ERROR 42X51: The class 'gaia.cu7.dal.DerbyBlobTableFunction' does not exist
> or is inaccessible. This can happen if the class is not public.
>         at
> org.apache.derby.iapi.error.StandardException.newException(StandardException.java:296)
>         at
> org.apache.derby.impl.sql.compile.QueryTreeNode.verifyClassExist(QueryTreeNode.java:1445)
>         at
> org.apache.derby.impl.sql.compile.StaticMethodCallNode.bindExpression(StaticMethodCallNode.java:256)
>         at
> org.apache.derby.impl.sql.compile.FromVTI.bindVTITables(FromVTI.java:541)
>         at
> org.apache.derby.impl.sql.compile.FromList.bindTables(FromList.java:322)
>         at
> org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(SelectNode.java:390)
>         at
> org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(DMLStatementNode.java:199)
>         at
> org.apache.derby.impl.sql.compile.DMLStatementNode.bind(DMLStatementNode.java:137)
>         at
> org.apache.derby.impl.sql.compile.CursorNode.bindStatement(CursorNode.java:245)
>         at
> org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:316)
>         at
> org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:88)
>         at
> org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:802)
>         at
> org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:606)
>         at
> org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(EmbedStatement.java:152)
> ...
> Caused by: java.lang.ClassNotFoundException:
> gaia.cu7.dal.DerbyBlobTableFunction
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:169)
>         at
> org.apache.derby.impl.services.reflect.ReflectClassesJava2.loadClassNotInDatabaseJar(ReflectClassesJava2.java:108)
>         at
> org.apache.derby.impl.services.reflect.DatabaseClasses.loadApplicationClass(DatabaseClasses.java:232)
>         at
> org.apache.derby.iapi.services.loader.ClassInspector.getClass(ClassInspector.java:832)
>         at
> org.apache.derby.iapi.services.loader.ClassInspector.accessible(ClassInspector.java:134)
>         at
> org.apache.derby.impl.sql.compile.QueryTreeNode.verifyClassExist(QueryTreeNode.java:1437)
>         ... 17 more
> ============= begin nested exception, level (1) ===========
> java.lang.ClassNotFoundException: gaia.cu7.dal.DerbyBlobTableFunction
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:169)
>         at
> org.apache.derby.impl.services.reflect.ReflectClassesJava2.loadClassNotInDatabaseJar(ReflectClassesJava2.java:108)
>         at
> org.apache.derby.impl.services.reflect.DatabaseClasses.loadApplicationClass(DatabaseClasses.java:232)
>         at
> org.apache.derby.iapi.services.loader.ClassInspector.getClass(ClassInspector.java:832)
>         at
> org.apache.derby.iapi.services.loader.ClassInspector.accessible(ClassInspector.java:134)
>         at
> org.apache.derby.impl.sql.compile.QueryTreeNode.verifyClassExist(QueryTreeNode.java:1437)
>         at
> org.apache.derby.impl.sql.compile.StaticMethodCallNode.bindExpression(StaticMethodCallNode.java:256)
>         at
> org.apache.derby.impl.sql.compile.FromVTI.bindVTITables(FromVTI.java:541)
>         at
> org.apache.derby.impl.sql.compile.FromList.bindTables(FromList.java:322)
>         at
> org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(SelectNode.java:390)
>         at
> org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(DMLStatementNode.java:199)
>         at
> org.apache.derby.impl.sql.compile.DMLStatementNode.bind(DMLStatementNode.java:137)
>         at
> org.apache.derby.impl.sql.compile.CursorNode.bindStatement(CursorNode.java:245)
>         at
> org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:316)
>         at
> org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:88)
>         at
> org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:802)
>         at
> org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:606)
>         at
> org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(EmbedStatement.java:152)
> ...
> ============= end nested exception, level (1) ===========
> </log>
>
> Seems internal classpath is set properly:
>
> <log>
> Executing prepared statement: CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
> ('derby.database.classpath', 'APP.kn') :End prepared statement
> Database Class Loader started - derby.database.classpath='APP.kn'
> 2009-03-31 11:03:39.148 GMT Thread[SQL Execution Thread 1,6,main] (XID =
> 194), (SESSIONID = 1), CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
> ('derby.database.classpath', 'APP.kn') ******* null
> </log>
>
> Best regards,
> Krzysztof
>   


Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Krzysztof N <ya...@gmail.com>.
Hello Rick,
Thanks for spotting this - I was creating small jar by hand and omitted
package path this time. 
It's working now! Big thanks for quick resolution.
Best regards,
Krzysztof


Krzysztof N wrote:
> 
> Forgot to add error codes from the driver:
> select * from table ( getTSValuesEmpty() ) t
> The class 'gaia.cu7.dal.DerbyBlobTableFunction' does not exist or is
> inaccessible. This can happen if the class is not public. [SQL
> State=42X51, DB Errorcode=20000] 
> Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
> java.lang.ClassNotFoundException'. [SQL State=XJ001] 
> 
> Cheers,
> Krzysztof
> 

-- 
View this message in context: http://www.nabble.com/Uinable-to-use-Table-function-due-to-java.lang.ClassNotFoundException--while-class-is-clearly-reachable..-tp22478383p22805223.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Krzysztof N <ya...@gmail.com>.
Forgot to add error codes from the driver:
select * from table ( getTSValuesEmpty() ) t
The class 'gaia.cu7.dal.DerbyBlobTableFunction' does not exist or is
inaccessible. This can happen if the class is not public. [SQL State=42X51,
DB Errorcode=20000] 
Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
java.lang.ClassNotFoundException'. [SQL State=XJ001] 

Cheers,
Krzysztof
-- 
View this message in context: http://www.nabble.com/Uinable-to-use-Table-function-due-to-java.lang.ClassNotFoundException--while-class-is-clearly-reachable..-tp22478383p22802935.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Krzysztof N <ya...@gmail.com>.

Hello Rick,
Thank you for fast response. Still have some issues though - I am using
trunk version, repeated installation of jars - same way as before.
Both scalar 'values' and table function call give ClassNotFoundException
originating from ReflectClassesJava2:loadClassNotInDatabaseJar now:

<log>
ERROR 42X51: The class 'gaia.cu7.dal.DerbyBlobTableFunction' does not exist
or is inaccessible. This can happen if the class is not public.
        at
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:296)
        at
org.apache.derby.impl.sql.compile.QueryTreeNode.verifyClassExist(QueryTreeNode.java:1445)
        at
org.apache.derby.impl.sql.compile.StaticMethodCallNode.bindExpression(StaticMethodCallNode.java:256)
        at
org.apache.derby.impl.sql.compile.FromVTI.bindVTITables(FromVTI.java:541)
        at
org.apache.derby.impl.sql.compile.FromList.bindTables(FromList.java:322)
        at
org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(SelectNode.java:390)
        at
org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(DMLStatementNode.java:199)
        at
org.apache.derby.impl.sql.compile.DMLStatementNode.bind(DMLStatementNode.java:137)
        at
org.apache.derby.impl.sql.compile.CursorNode.bindStatement(CursorNode.java:245)
        at
org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:316)
        at
org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:88)
        at
org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:802)
        at
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:606)
        at
org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(EmbedStatement.java:152)
...
Caused by: java.lang.ClassNotFoundException:
gaia.cu7.dal.DerbyBlobTableFunction
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at
org.apache.derby.impl.services.reflect.ReflectClassesJava2.loadClassNotInDatabaseJar(ReflectClassesJava2.java:108)
        at
org.apache.derby.impl.services.reflect.DatabaseClasses.loadApplicationClass(DatabaseClasses.java:232)
        at
org.apache.derby.iapi.services.loader.ClassInspector.getClass(ClassInspector.java:832)
        at
org.apache.derby.iapi.services.loader.ClassInspector.accessible(ClassInspector.java:134)
        at
org.apache.derby.impl.sql.compile.QueryTreeNode.verifyClassExist(QueryTreeNode.java:1437)
        ... 17 more
============= begin nested exception, level (1) ===========
java.lang.ClassNotFoundException: gaia.cu7.dal.DerbyBlobTableFunction
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at
org.apache.derby.impl.services.reflect.ReflectClassesJava2.loadClassNotInDatabaseJar(ReflectClassesJava2.java:108)
        at
org.apache.derby.impl.services.reflect.DatabaseClasses.loadApplicationClass(DatabaseClasses.java:232)
        at
org.apache.derby.iapi.services.loader.ClassInspector.getClass(ClassInspector.java:832)
        at
org.apache.derby.iapi.services.loader.ClassInspector.accessible(ClassInspector.java:134)
        at
org.apache.derby.impl.sql.compile.QueryTreeNode.verifyClassExist(QueryTreeNode.java:1437)
        at
org.apache.derby.impl.sql.compile.StaticMethodCallNode.bindExpression(StaticMethodCallNode.java:256)
        at
org.apache.derby.impl.sql.compile.FromVTI.bindVTITables(FromVTI.java:541)
        at
org.apache.derby.impl.sql.compile.FromList.bindTables(FromList.java:322)
        at
org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(SelectNode.java:390)
        at
org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(DMLStatementNode.java:199)
        at
org.apache.derby.impl.sql.compile.DMLStatementNode.bind(DMLStatementNode.java:137)
        at
org.apache.derby.impl.sql.compile.CursorNode.bindStatement(CursorNode.java:245)
        at
org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:316)
        at
org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:88)
        at
org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:802)
        at
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:606)
        at
org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(EmbedStatement.java:152)
...
============= end nested exception, level (1) ===========
</log>

Seems internal classpath is set properly:

<log>
Executing prepared statement: CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
('derby.database.classpath', 'APP.kn') :End prepared statement
Database Class Loader started - derby.database.classpath='APP.kn'
2009-03-31 11:03:39.148 GMT Thread[SQL Execution Thread 1,6,main] (XID =
194), (SESSIONID = 1), CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
('derby.database.classpath', 'APP.kn') ******* null
</log>

Best regards,
Krzysztof
-- 
View this message in context: http://www.nabble.com/Uinable-to-use-Table-function-due-to-java.lang.ClassNotFoundException--while-class-is-clearly-reachable..-tp22478383p22802900.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Rick Hillegas <Ri...@Sun.COM>.
Hi Krzysztof,

The bug you reported has been fixed in the trunk and the fix has been 
ported to the 10.5 and 10.4 branches. I believe that Myrna plans to spin 
another 10.5 release candidate, so you should see this fix in 10.5.

Thanks again for reporting this bug.

-Rick

Rick Hillegas wrote:
> Thanks for finding this bug, Krzysztof. Derby is using the wrong 
> classloader to look up optimizer overrides for table functions and 
> this raises the ClassNotFoundException which you are seeing. I have 
> logged the following issue to track the problem: 
> http://issues.apache.org/jira/browse/DERBY-4126
>
> Thanks,
> -Rick
>
> Krzysztof N wrote:
>> Futhermore, I'm able to stop on breakpoint while debugging this table
>> function and  select'ing does not even have a chance to call it, 
>> obviously.
>> Best Regards
>>
>>
>>
>> Krzysztof N wrote:
>>  
>>> Hello,
>>> I'm trying to get basic table function running without much success.
>>> Either error is misleading or I missed some basic point, could you
>>> please advise?
>>>
>>> public class DerbyBlobTableFunction {
>>>
>>>  //this works
>>>   public static int returnSth()
>>>     {
>>>         return 1;
>>>     }
>>>
>>> //does not work, see error below
>>>  public static ResultSet getTSValuesEmpty()  throws SQLException
>>>     {
>>>          List<double[]> results = new ArrayList<double[]>();
>>>         results.add(new double[]{1.0,2.0,3.0});
>>>          ResultSet rs = new ResultSetTemplate(results);
>>> --//ResultSetTemplate implements ResultSet but same error with Derby
>>> impl of ResultSet
>>>         return rs;
>>>     }
>>>
>>> }
>>>
>>>
>>> then
>>>
>>>
>>> CALL SQLJ.install_jar
>>> ('/pathto/kn.jar', 'APP.kn', 0); -- OK
>>>
>>> CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
>>> ('derby.database.classpath', 'APP.kn'); --OK
>>>
>>>
>>> CREATE FUNCTION MYFUNC() returns int PARAMETER STYLE JAVA reads
>>> sql data language JAVA EXTERNAL NAME
>>> ''gaia.cu7.dal.DerbyBlobTableFunction.returnSth'; --OK
>>>
>>> values MYFUNC() ; --OK
>>> returns:
>>>
>>> 1
>>>
>>>
>>> CREATE FUNCTION getTSValuesEmpty()
>>> RETURNS TABLE   
>>> (   
>>>   obs      double,
>>>   val      double,   
>>>   valError double
>>> )
>>> LANGUAGE JAVA
>>> PARAMETER STYLE DERBY_JDBC_RESULT_SET
>>> reads SQL data --  switching to no sql does not change
>>> EXTERNAL NAME ''gaia.cu7.dal.DerbyBlobTableFunction.getTSValuesEmpty'
>>> --OK
>>>
>>> then:
>>>
>>> select * from table ( getTSValuesEmpty() ) t;
>>>
>>> gives:
>>>
>>> An error occurred when executing the SQL command:
>>> select * from table ( getTSValuesEmpty() ) t
>>> The exception 'java.lang.ClassNotFoundException:
>>> gaia.cu7.dal.DerbyBlobTableFunction' was thrown while evaluating an
>>> expression. [SQL State=38000, DB Errorcode=20000]
>>> Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
>>> java.lang.ClassNotFoundException'. [SQL State=XJ001]
>>>
>>> Execution time: 0.04s
>>>
>>> 1 statement(s) failed.
>>>
>>>
>>> _but_
>>>
>>> values getTSValuesEmpty();
>>>
>>> gives:
>>> 1
>>> gaia.cu7.dal.ResultSetTemplate@10fa2e17
>>>
>>>
>>> MacOS,  Derby 10.4.2.0, embedded mode.
>>>
>>>
>>> Could you please enlighten me what could be wrong? Seems error message
>>> is plain wrong as 'values' returns the reference to resultset, and
>>> regular function from the same class works as well as values call..
>>>
>>> Best regards,
>>> Krzysztof
>>>
>>>
>>>     
>>
>>   
>


Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Rick Hillegas <Ri...@Sun.COM>.
Thanks for finding this bug, Krzysztof. Derby is using the wrong 
classloader to look up optimizer overrides for table functions and this 
raises the ClassNotFoundException which you are seeing. I have logged 
the following issue to track the problem: 
http://issues.apache.org/jira/browse/DERBY-4126

Thanks,
-Rick

Krzysztof N wrote:
> Futhermore, I'm able to stop on breakpoint while debugging this table
> function and  select'ing does not even have a chance to call it, obviously.
> Best Regards
>
>
>
> Krzysztof N wrote:
>   
>> Hello,
>> I'm trying to get basic table function running without much success.
>> Either error is misleading or I missed some basic point, could you
>> please advise?
>>
>> public class DerbyBlobTableFunction {
>>
>>  //this works
>>   public static int returnSth()
>>     {
>>         return 1;
>>     }
>>
>> //does not work, see error below
>>  public static ResultSet getTSValuesEmpty()  throws SQLException
>>     {
>>          List<double[]> results = new ArrayList<double[]>();
>>         results.add(new double[]{1.0,2.0,3.0});
>>          ResultSet rs = new ResultSetTemplate(results);
>> --//ResultSetTemplate implements ResultSet but same error with Derby
>> impl of ResultSet
>>         return rs;
>>     }
>>
>> }
>>
>>
>> then
>>
>>
>> CALL SQLJ.install_jar
>> ('/pathto/kn.jar', 'APP.kn', 0); -- OK
>>
>> CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
>> ('derby.database.classpath', 'APP.kn'); --OK
>>
>>
>> CREATE FUNCTION MYFUNC() returns int PARAMETER STYLE JAVA reads
>> sql data language JAVA EXTERNAL NAME
>> ''gaia.cu7.dal.DerbyBlobTableFunction.returnSth'; --OK
>>
>> values MYFUNC() ; --OK
>> returns:
>>
>> 1
>>
>>
>> CREATE FUNCTION getTSValuesEmpty()
>> RETURNS TABLE	
>> (	
>>   obs      double,
>>   val      double,	
>>   valError double
>> )
>> LANGUAGE JAVA
>> PARAMETER STYLE DERBY_JDBC_RESULT_SET
>> reads SQL data --  switching to no sql does not change
>> EXTERNAL NAME ''gaia.cu7.dal.DerbyBlobTableFunction.getTSValuesEmpty'
>> --OK
>>
>> then:
>>
>> select * from table ( getTSValuesEmpty() ) t;
>>
>> gives:
>>
>> An error occurred when executing the SQL command:
>> select * from table ( getTSValuesEmpty() ) t
>> The exception 'java.lang.ClassNotFoundException:
>> gaia.cu7.dal.DerbyBlobTableFunction' was thrown while evaluating an
>> expression. [SQL State=38000, DB Errorcode=20000]
>> Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
>> java.lang.ClassNotFoundException'. [SQL State=XJ001]
>>
>> Execution time: 0.04s
>>
>> 1 statement(s) failed.
>>
>>
>> _but_
>>
>> values getTSValuesEmpty();
>>
>> gives:
>> 1
>> gaia.cu7.dal.ResultSetTemplate@10fa2e17
>>
>>
>> MacOS,  Derby 10.4.2.0, embedded mode.
>>
>>
>> Could you please enlighten me what could be wrong? Seems error message
>> is plain wrong as 'values' returns the reference to resultset, and
>> regular function from the same class works as well as values call..
>>
>> Best regards,
>> Krzysztof
>>
>>
>>     
>
>   


Re: Unable to use Table function due to java.lang.ClassNotFoundException while class is clearly reachable..

Posted by Krzysztof N <ya...@gmail.com>.
Futhermore, I'm able to stop on breakpoint while debugging this table
function and  select'ing does not even have a chance to call it, obviously.
Best Regards



Krzysztof N wrote:
> 
> Hello,
> I'm trying to get basic table function running without much success.
> Either error is misleading or I missed some basic point, could you
> please advise?
> 
> public class DerbyBlobTableFunction {
> 
>  //this works
>   public static int returnSth()
>     {
>         return 1;
>     }
> 
> //does not work, see error below
>  public static ResultSet getTSValuesEmpty()  throws SQLException
>     {
>          List<double[]> results = new ArrayList<double[]>();
>         results.add(new double[]{1.0,2.0,3.0});
>          ResultSet rs = new ResultSetTemplate(results);
> --//ResultSetTemplate implements ResultSet but same error with Derby
> impl of ResultSet
>         return rs;
>     }
> 
> }
> 
> 
> then
> 
> 
> CALL SQLJ.install_jar
> ('/pathto/kn.jar', 'APP.kn', 0); -- OK
> 
> CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY
> ('derby.database.classpath', 'APP.kn'); --OK
> 
> 
> CREATE FUNCTION MYFUNC() returns int PARAMETER STYLE JAVA reads
> sql data language JAVA EXTERNAL NAME
> ''gaia.cu7.dal.DerbyBlobTableFunction.returnSth'; --OK
> 
> values MYFUNC() ; --OK
> returns:
> 
> 1
> 
> 
> CREATE FUNCTION getTSValuesEmpty()
> RETURNS TABLE	
> (	
>   obs      double,
>   val      double,	
>   valError double
> )
> LANGUAGE JAVA
> PARAMETER STYLE DERBY_JDBC_RESULT_SET
> reads SQL data --  switching to no sql does not change
> EXTERNAL NAME ''gaia.cu7.dal.DerbyBlobTableFunction.getTSValuesEmpty'
> --OK
> 
> then:
> 
> select * from table ( getTSValuesEmpty() ) t;
> 
> gives:
> 
> An error occurred when executing the SQL command:
> select * from table ( getTSValuesEmpty() ) t
> The exception 'java.lang.ClassNotFoundException:
> gaia.cu7.dal.DerbyBlobTableFunction' was thrown while evaluating an
> expression. [SQL State=38000, DB Errorcode=20000]
> Next: Java exception: 'gaia.cu7.dal.DerbyBlobTableFunction:
> java.lang.ClassNotFoundException'. [SQL State=XJ001]
> 
> Execution time: 0.04s
> 
> 1 statement(s) failed.
> 
> 
> _but_
> 
> values getTSValuesEmpty();
> 
> gives:
> 1
> gaia.cu7.dal.ResultSetTemplate@10fa2e17
> 
> 
> MacOS,  Derby 10.4.2.0, embedded mode.
> 
> 
> Could you please enlighten me what could be wrong? Seems error message
> is plain wrong as 'values' returns the reference to resultset, and
> regular function from the same class works as well as values call..
> 
> Best regards,
> Krzysztof
> 
> 

-- 
View this message in context: http://www.nabble.com/Uinable-to-use-Table-function-due-to-java.lang.ClassNotFoundException--while-class-is-clearly-reachable..-tp22478383p22699492.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.