ClassCastException ArrayDescriptor SructDescriptor
Hi,
I have problem with calling stored procedure in oracle.
One of the IN parameters of the procedure is Array, and when I try to call this procedure I get error:
java.lang.ClassCastException: oracle.sql.StructDescriptor cannot be cast to oracle.sql.ArrayDescriptor
Code in PL/SQL:
CREATE OR REPLACE
type A_TYPE as OBJECT (
firstName varchar2(100),
surname varchar2(100)
CREATE OR REPLACE
type A_TYPE_ARRAY is table of A_TYPE;
Code in java:
String function ="xxxxxxxxxx";
OracleCallableStatement cstmt = (OracleCallableStatement)conn.prepareCall(funkcion);
OracleConnection conn = (OracleConnection)DriverManager.getConnection
("jdbc:oracle:thin:@xxxx:1521:xxxxx", "xxx", "xxx");
Object[] atr = new Object[];
StructDescriptor structdesc = StructDescriptor.createDescriptor("A_TYPE", conn);
STRUCT struct = new STRUCT(structdesc, conn, atr);
ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor("A_TYPE_ARRAY", conn);
ARRAY array = new ARRAY(arrayDesc, conn, struct);
cstmt.setArray(1, array);
cstmt.execute();
In line where I trying to make arrayDesc I get error:
Exception occurred during event dispatching:
java.lang.ClassCastException: oracle.sql.StructDescriptor cannot be cast to oracle.sql.ArrayDescriptor
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:112)
Can some tell me what causes this problem?
Thanks.
Hi,
I have problem with calling stored procedure in oracle.
One of the IN parameters of the procedure is Array, and when I try to call this procedure I get error:
java.lang.ClassCastException: oracle.sql.StructDescriptor cannot be cast to oracle.sql.ArrayDescriptor
Code in PL/SQL:
CREATE OR REPLACE
type A_TYPE as OBJECT (
firstName varchar2(100),
surname varchar2(100)
CREATE OR REPLACE
type A_TYPE_ARRAY is table of A_TYPE;
Code in java:
String function ="xxxxxxxxxx";
OracleCallableStatement cstmt = (OracleCallableStatement)conn.prepareCall(funkcion);
OracleConnection conn = (OracleConnection)DriverManager.getConnection
("jdbc:oracle:thin:@xxxx:1521:xxxxx", "xxx", "xxx");
Object[] atr = new Object[];
StructDescriptor structdesc = StructDescriptor.createDescriptor("A_TYPE", conn);
STRUCT struct = new STRUCT(structdesc, conn, atr);
ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor("A_TYPE_ARRAY", conn);
ARRAY array = new ARRAY(arrayDesc, conn, struct);
cstmt.setArray(1, array);
cstmt.execute();
In line where I trying to make arrayDesc I get error:
Exception occurred during event dispatching:
java.lang.ClassCastException: oracle.sql.StructDescriptor cannot be cast to oracle.sql.ArrayDescriptor
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:112)
Can some tell me what causes this problem?
Thanks.
Similar Messages
-
ClassCastException While using ArrayDescriptor
Hi,
Can anybody help me with this,I'm trying to insert some data in a nested table(Oracle
8i) , for which i need to create an ArrayDescriptor which needs to be passed to
the ARRAY on creation , if i directly get the Connection from the driver , it
works fine , but if i try to get it from the weblogic connection pool , it gives
a ClassCastException . I know internally oracle extension for JDBC uses OracleConnection
, but is there any other ways/workarounds ? Please reply asap .
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("ARRAYOFDATA",connection);
ARRAY array = new ARRAY(descriptor, connection, elements);
ManishaHi Manisha,
I recently ran into the same problem you did. I came up with two workarounds for
this.
1. Given the WebLogic wrapped connection "conn" and the following types that I work
with:
CREATE TYPE dh_id_typ AS OBJECT (
id NUMBER(18)
CREATE TYPE dh_id_tab AS TABLE OF dh_id_typ;
I can do the following to make an Array of dh_id_typ objects for these id numbers
10100, 10101, 10102, 10200, 10201, 10300:
Dynamically build a string that looks like this:
String sql = "select dh_id_tab(dh_id_typ(10100), dh_id_typ(10101), dh_id_typ(10102),
dh_id_typ(10200), dh_id_typ(10201), dh_id_typ(10300)) from dual";
Next, do this:
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
rs.next();
java.sql.Array ids = rs.getArray(1);
"ids" is a DB server-side Array with the specified values. The Array object is good
for the duration of the transaction. No need for Oracle-specific classes and only
one extra round-trip to the DB. The only problem is that Oracle SQL statements have
a max length of 64K, so your Array length is limited by the generated SQL statement's
size.
2. The other workaround I thought of would involve batched inserts of array elements
to a temporary table. It doesn't suffer from any size limits. It means more round-trips
to the database, but it might scale better. It looks like this:
temp table & sequence schema:
CREATE SEQUENCE dh_temp_array_seq;
CREATE TABLE dh_temp_array (
seq_num NUMBER(18),
object_id NUMBER(18)
java code:
long[] ids = ... // Given id's in an array of longs.
PreparedStatement select = conn.prepareStatement("SELECT dh_temp_array_seq.NEXTVAL
FROM DUAL");
ResultSet rs = select.executeQuery(select);
rs.next();
long seqNum = rs.getLong(1);
rs.close();
PreparedStatement insert = conn.prepareStatement("INSERT INTO dh_temp_array (seq_num,
object_id) VALUES (?, ?)");
for (int index = 0; index < ids.length; index++) {
insert.setLong(1, seqNum);
insert.setLong(2, ids[index]);
insert.addBatch();
insert.executeBatch();
String sql = "SELECT CAST(MULTISET(select object_id from dh_temp_array where seq_num=?)
AS dh_id_tab) FROM dual";
PreparedStatement selectArray = conn.prepareStatment(sql);
selectArray.setLong(1, seqNum);
rs = selectArray.executeQuery();
rs.next();
Array idArray = rs.getArray(1);
. // Use Array
PreparedStatement delete = conn.prepareStatement("DELETE FROM dh_temp_array WHERE
seq_num=?");
delete.setLong(1, seqNum);
delete.executeUpdate();
Here, "idArray" is a DB server-side Array with the specified values. Again, no need
for an OracleConnection. This is all done on the wrapped connection.
Of course, you will have to adapt the examples to your schema/types.
BTW, if BEA would just follow the suggestions in Sun's JDBC 2.0 Standard Extension
API specification, located at:
http://java.sun.com/products/jdbc/jdbc20.stdext.pdf (See sections 6 & 7)
Then their Pooling/XA implementations could return us the logical connection wrapper
created by the Oracle driver (javax.sql.PooledConnection.getConnection() & javax.sql.XAConnection.getConnection()),
which DOES implement OracleConnection, but still hides the physical database connection
from the application code. Note, DON'T access PooledConnection or XAConnection from
your application code. Getting PooledConnection's/XAConnection's from their respective
data sources will create a physical database connection every time (slow). They are
meant for application server developers (like BEA), so they can create DataSource
implementation classes that provide connection pooling and distributed transaction
support, without having to create an entire JDBC wrapper driver (like BEA had to,
before JDBC 2.0 Std. Ext. API existed).
I hope that helps.
-Keith
Keith Caceres
Middleware Architect
Tririga Inc.
"Manisha Mehrotra" <[email protected]> wrote:
>
Hi,
Can anybody help me with this,I'm trying to insert some data in a nested
table(Oracle
8i) , for which i need to create an ArrayDescriptor which needs to be passed
to
the ARRAY on creation , if i directly get the Connection from the driver
, it
works fine , but if i try to get it from the weblogic connection pool ,
it gives
a ClassCastException . I know internally oracle extension for JDBC uses
OracleConnection
, but is there any other ways/workarounds ? Please reply asap .
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("ARRAYOFDATA",connection);
ARRAY array = new ARRAY(descriptor, connection, elements);
Manisha -
Java ArrayDescriptor Classcastexception
I'm using Weblogic 8.1 SP2, Oracle Database 9.2.0.1.0 and Oracle JDBC thin driver supplied with Weblogic(major ver. 1, minor ver. 0).
I wanted to pass an array to pl/sql from Java using ArrayDescriptor, but i'm getting ClassCastException. I also tried to pass Clob but same exception occurred.
What to do? Is there any driver patch that needs to be applied?Hi,
This particular forum is for S1AS7. :)
You might want to repost this in the App Server 6.x forum:
http://softwareforum.sun.com/NASApp/jive/forum.jsp?forum=18 -
ClassCastException trying to create ArrayDescriptor
There is one way I found to accomplish something like this. It basically involves
using the customdatum interface that oracle provides. Essentially you can pass
an object through all of the jdbc layers into the oracle driver and then let the
driver call your object back with an oracleconnection - thereby avoiding the classcastexception.
It does require a bit more work, but may be worth it in certain circumstances.
I have attached an example dervied from some working code(though the example probably
will not compile). It shows how to accomplish this for a struct containing an
array of structs (pretty much a one to many model). It can be simplified of course
if such a containment model does not exist. Also one should be able to adjust
this strategy for clobs as well to basically avoid having to do two jdbc calls
to create a new clob.
Rupen
"David" <[email protected]> wrote:
>
Joseph Weinstein <[email protected]> wrote:
Jay Fuller wrote:
I am trying to save information to a Nested Table with type "HISTORY_NT"within "ejbStore", but
I'm getting a ClassCastException when I make this call.
ArrayDescriptor.createDescriptor("HISTORY_NT",conn); // orace.sql.ArrayDescriptor
The exact error statement is:
java.lang.ClassCastException: weblogic.jdbc20.jts.Connection
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:80)...
Hi. We currently don't have any way of offering Oracle non-standardJDBC
extensions through
our pool and jts drivers. For example, that createDescriptor call requires
a naked Oracle JDBC
connection for an argument, not a WebLogic jts or pool connection. There's
nothing we can do to
make our jts or pool connections cast directly to an Oracle class. Unless/until
we provide
you access to the underlying DBMS connection for these purposes, you
will not be able to make
these Oracle calls with a pooled connection. We need to maintain a wrapper
around any pooled
connection to be able to guarantee that when the connection is returned
to the pool, no one retains
a reference to it that is out of our control. Otherwise the next user
of the pooled connection may
have his work corrupted by a former user that mis-uses a reference to
the DBMS connection they
obtained long before. A simple example is that if we gave you access
to the Oracle connection
class to make that call, and when you were done, you closed both pool
connection (returning it
to the pool), and the DBMS connection, you would kill the pooled connection
and the next user
would get a dead pool connection. A more serious example would be if
after closing the pool
connection, you did a commit() or rollback on the DBMS connection, if
some other thread got
the pool connection before the commit/rollback you'd be trampling their
tx.
Joe
My connection statement within my EJB is:
static
new weblogic.jdbc20.jts.Driver();
private Connection getConnection()
throws SQLException
return DriverManager.getConnection("jdbc20:weblogic:jts:OraclePool",null);
I am using a database pool set up as follows.
weblogic.jdbc.connectionPool.OraclePool=\
url=jdbc:oracle:oci8:@dbname,\
driver=oracle.jdbc.driver.OracleDriver,\
loginDelaySecs=1,\
initialCapacity=4,\
maxCapacity=10,\
capacityIncrement=2,\
allowShrinking=true,\
shrinkPeriodMins=15,\
refreshMinutes=10,\
testTable=dual,\
props=user=xxxxxxxx;password=xxxxxx
I'm using WLS 5.1 sp1 and Oracle 8.1.6 and I can make the code workif I access the database
directly, but going through the jts driver there seems to be a bugin the weblogic code. I might
be wrong about this, so if someone can please point out my error Iwould appreciate it.
Jay--
PS: Folks: BEA WebLogic is in S.F., and now has some entry-level positions
for
people who want to work with Java and E-Commerce infrastructure products.
Send
resumes to [email protected]
The Weblogic Application Server from BEA
JavaWorld Editor's Choice Award: Best Web Application Server
Java Developer's Journal Editor's Choice Award: Best Web Application
Server
Crossroads A-List Award: Rapid Application Development Tools for
Java
Intelligent Enterprise RealWare: Best Application Using a ComponentArchitecture
http://weblogic.beasys.com/press/awards/index.htm
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<p>Jay Fuller wrote:
<blockquote TYPE=CITE>I am trying to save information to a Nested Table
with type "HISTORY_NT" within "ejbStore", but I'm getting a ClassCastException
when I make this call.
<p> <b>ArrayDescriptor.createDescriptor("HISTORY_NT",conn);
// </b>orace.sql.ArrayDescriptor
<p>The exact error statement is:
<br> <b>java.lang.ClassCastException:
weblogic.jdbc20.jts.Connection</b>
<br><b>
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:80)
....</b></blockquote>
<p><br>Hi. We currently don't have any way of offering Oracle non-standard
JDBC extensions through
<br>our pool and jts drivers. For example, that createDescriptor call
requires
a naked Oracle JDBC
<br>connection for an argument, not a WebLogic jts or pool connection.
There's nothing we can do to
<br>make our jts or pool connections cast directly to an Oracle class.
Unless/until we provide
<br>you access to the underlying DBMS connection for these purposes,
you
will not be able to make
<br>these Oracle calls with a pooled connection. We need to maintain
a
wrapper around any pooled
<br>connection to be able to guarantee that when the connection is returned
to the pool, no one retains
<br>a reference to it that is out of our control. Otherwise the next
user
of the pooled connection may
<br>have his work corrupted by a former user that mis-uses a reference
to the DBMS connection they
<br>obtained long before. A simple example is that if we gave you access
to the Oracle connection
<br>class to make that call, and when you were done, you closed both
pool
connection (returning it
<br>to the pool), and the DBMS connection, you would kill the pooled
connection and the next user
<br>would get a dead pool connection. A more serious example would be
if
after closing the pool
<br>connection, you did a commit() or rollback on the DBMS connection,
if some other thread got
<br>the pool connection before the commit/rollback you'd be trampling
their
tx.
<br>Joe
<blockquote TYPE=CITE><b></b>
<br>
<p>My connection statement within my EJB is:
<br> <b>static</b>
<br><b> {</b>
<br><b> new weblogic.jdbc20.jts.Driver();</b>
<br><b> }</b>
<p><b> private Connection getConnection()</b>
<br><b> throws SQLException</b>
<br><b> {</b>
<br><b> return
DriverManager.getConnection("jdbc20:weblogic:jts:OraclePool",null);</b>
<br><b> }</b>
<p>I am using a database pool set up as follows.
<br> <b> weblogic.jdbc.connectionPool.OraclePool=\</b>
<br><b> url=jdbc:oracle:oci8:@dbname,\</b>
<br><b> driver=oracle.jdbc.driver.OracleDriver,\</b>
<br><b> loginDelaySecs=1,\</b>
<br><b> initialCapacity=4,\</b>
<br><b> maxCapacity=10,\</b>
<br><b> capacityIncrement=2,\</b>
<br><b> allowShrinking=true,\</b>
<br><b> shrinkPeriodMins=15,\</b>
<br><b> refreshMinutes=10,\</b>
<br><b> testTable=dual,\</b>
<br><b> props=user=xxxxxxxx;password=xxxxxx</b>
<br>
<p>I'm using WLS 5.1 sp1 and Oracle 8.1.6 and I can make the code work
if I access the database directly, but going through the jts driverthere
seems to be a bug in the weblogic code. I might be wrong about
this,
so if someone can please point out my error I would appreciate it.
<p>Jay</blockquote>
<p>--
<p>PS: Folks: BEA WebLogic is in S.F., and now has some entry-levelpositions
for
<br>people who want to work with Java and E-Commerce infrastructureproducts.
Send
<br>resumes to [email protected]
<br>--------------------------------------------------------------------------------
<br>
The Weblogic Application Server from BEA
<br> JavaWorld Editor's
Choice Award: Best Web Application Server
<br> Java Developer's Journal Editor's Choice Award: Best Web Application
Server
<br> Crossroads A-List Award: Rapid Application
Development Tools for Java
<br>Intelligent Enterprise RealWare: Best Application Using a Component
Architecture
<br>
http://weblogic.beasys.com/press/awards/index.htm
<br> </html>
Weblogic connection pool users weblogic.jdbc.rmi.SerialConnection connection
class,
not java.sql.Connection.
Oracle oracle.sql.ArrayDescriptor.createDescriptor method tries to cast
it to
oracle.jdbc.OracleConnection which fails.
One workaround is to use Oracle connection pool.
Oracle8i JDBC Developer's Guide and Reference:
http://download-west.oracle.com/docs/cd/A81042_01/DOC/index.htm
Another workaround is to stop passing Oracle Array to the stored procedure,
pass delimited string and conver it into pl/sql Array internaly.
Here is the code we use (original sample by Tom Kyte):
CREATE OR REPLACE TYPE INT_TABLE AS TABLE OF NUMBER;
CREATE OR REPLACE
FUNCTION str2array( p_string in VARCHAR2 ) RETURN INT_TABLE
AS
l_string long default p_string || ',';
l_data INT_TABLE := INT_TABLE();
n number;
BEGIN
LOOP
EXIT WHEN l_string is null;
n := INSTR( l_string, ',' );
l_data.EXTEND;
l_data(l_data.COUNT) :=
LTRIM( RTRIM( SUBSTR( l_string, 1, n-1 ) ) );
l_string := SUBSTR( l_string, n+1 );
END LOOP;
RETURN l_data;
END;
--Unit test
SELECT * from THE ( select cast( str2array('787, 234, 12, 1024, 1,45,1231243,324235435,3436426767,0,-1,-345235')
AS INT_TABLE ) from dual ) a
--Performance test
DECLARE
it_groups INT_TABLE := INT_TABLE();
BEGIN
FOR i IN 1..1000 LOOP
it_groups:=str2array('787,234,312,787,234,312,345,235,787,235,787,234,312,335,434,235');
END LOOP;
END;
Overhead is about 1 ms to parse 16 tokens.
Hope it helps,
David
[CustomDatumExample.java] -
ArrayDescriptor + DataSource = ClassCastException
Hi all,
I have an issue with creating ArrayDescriptors in JRun 4 when using a DataSource. I've seen this issue in a few posts in different forums but no viable solutions. The problem is that JRun returns a JRunDataSource which then returns a JRunConnectionHandle-JRunConnection. The oracle.sql.ArrayDescriptor constructor requires a connection to be passed as a parameter. When I pass the connection I obtain from the JRunDataSource, I get a ClassCastException since it's trying to cast the JRunConnectionHandle-JRunConnection to an OracleConnection.
I've seen a few solutions which suggest using getPhysicalConnection( ) to obtain the inner connection from the JRun Wrapped Connection and then pass that connection to the ArrayDescriptor. However, this would require that I make my application only compatible with JRun since getPhysicalConnection( ) is a method of JRunConnectionHandle-JRunConnection.
I had the same issue when I placed this application in Tomcat 5.5 since the DataSource returned by Tomcat is a BasicDataSource which then returns a PoolableConnection. However, in Tomcat, I was able to configure the DataSource in the Server.xml by adding type= "oracle.jdbc.pool.OracleDataSource" and factory="oracle.jdbc.pool.OracleDataSourceFactory". After configuring the DataSource with these two Attributes, an OracleDataSource was returned instead of a BasicDataSource in Tomcat. I was hoping to have a similar solution for JRun since this solution does not require any server specific code in my application.
Below is my configuration for both Tomcast 5.5 and JRun 4. Tomcat returns an OracleDataSource which is what I need. JRun returns a JRunDataSource which causes a ClassCastException when I use its connections for an ArrayDescriptor. Any help is greatly appreciated:
Tomcat 5.5
name="jdbc/my_jndi_name" auth="Container" type="oracle.jdbc.pool.OracleDataSource" factory="oracle.jdbc.pool.OracleDataSourceFactory"
maxActive="20" maxIdle="10" maxWait="10000"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@my_db_url:1521:my_db" user="user" password="pw" connectionCachingEnabled="true"
JRun 4
<data-source>
<dbname>my_jndi_name</dbname>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<url>jdbc:oracle:thin:@my_db_url:1521:my_db</url>
<username>user</username>
<password>D46FCD1E3EC74BC58D68FB06AF961666</password>
<encrypted>true</encrypted>
<encryption-class>jrun.security.JRunCrypterForTwofish</encryption-class>
<native-results>true</native-results>
<remove-on-exceptions>true</remove-on-exceptions>
<pool-statements>true</pool-statements>
<initial-connections>1</initial-connections>
<connection-timeout>1200</connection-timeout>
<transaction-timeout>20</transaction-timeout>
<cache-enabled>false</cache-enabled>
<cache-size>5</cache-size>
<cache-refresh-interval>30</cache-refresh-interval>
<jndi-name>my_jndi_name</jndi-name>
<poolname>Pool</poolname>
<minimum-size>0</minimum-size>
<maximum-size>2147483647</maximum-size>
<user-timeout>20</user-timeout>
<skimmer-frequency>420</skimmer-frequency>
<shrink-by>5</shrink-by>
<maximum-soft>true</maximum-soft>
<debugging>false</debugging>
<disable-pooling>false</disable-pooling>
<description>Oracle connection</description>
</data-source>Thank you,
DaveHi all,
I have an issue with creating ArrayDescriptors in JRun 4 when using a DataSource. I've seen this issue in a few posts in different forums but no viable solutions. The problem is that JRun returns a JRunDataSource which then returns a JRunConnectionHandle-JRunConnection. The oracle.sql.ArrayDescriptor constructor requires a connection to be passed as a parameter. When I pass the connection I obtain from the JRunDataSource, I get a ClassCastException since it's trying to cast the JRunConnectionHandle-JRunConnection to an OracleConnection.
I've seen a few solutions which suggest using getPhysicalConnection( ) to obtain the inner connection from the JRun Wrapped Connection and then pass that connection to the ArrayDescriptor. However, this would require that I make my application only compatible with JRun since getPhysicalConnection( ) is a method of JRunConnectionHandle-JRunConnection.
I had the same issue when I placed this application in Tomcat 5.5 since the DataSource returned by Tomcat is a BasicDataSource which then returns a PoolableConnection. However, in Tomcat, I was able to configure the DataSource in the Server.xml by adding type= "oracle.jdbc.pool.OracleDataSource" and factory="oracle.jdbc.pool.OracleDataSourceFactory". After configuring the DataSource with these two Attributes, an OracleDataSource was returned instead of a BasicDataSource in Tomcat. I was hoping to have a similar solution for JRun since this solution does not require any server specific code in my application.
Below is my configuration for both Tomcast 5.5 and JRun 4. Tomcat returns an OracleDataSource which is what I need. JRun returns a JRunDataSource which causes a ClassCastException when I use its connections for an ArrayDescriptor. Any help is greatly appreciated:
Tomcat 5.5
name="jdbc/my_jndi_name" auth="Container" type="oracle.jdbc.pool.OracleDataSource" factory="oracle.jdbc.pool.OracleDataSourceFactory"
maxActive="20" maxIdle="10" maxWait="10000"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@my_db_url:1521:my_db" user="user" password="pw" connectionCachingEnabled="true"
JRun 4
<data-source>
<dbname>my_jndi_name</dbname>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<url>jdbc:oracle:thin:@my_db_url:1521:my_db</url>
<username>user</username>
<password>D46FCD1E3EC74BC58D68FB06AF961666</password>
<encrypted>true</encrypted>
<encryption-class>jrun.security.JRunCrypterForTwofish</encryption-class>
<native-results>true</native-results>
<remove-on-exceptions>true</remove-on-exceptions>
<pool-statements>true</pool-statements>
<initial-connections>1</initial-connections>
<connection-timeout>1200</connection-timeout>
<transaction-timeout>20</transaction-timeout>
<cache-enabled>false</cache-enabled>
<cache-size>5</cache-size>
<cache-refresh-interval>30</cache-refresh-interval>
<jndi-name>my_jndi_name</jndi-name>
<poolname>Pool</poolname>
<minimum-size>0</minimum-size>
<maximum-size>2147483647</maximum-size>
<user-timeout>20</user-timeout>
<skimmer-frequency>420</skimmer-frequency>
<shrink-by>5</shrink-by>
<maximum-soft>true</maximum-soft>
<debugging>false</debugging>
<disable-pooling>false</disable-pooling>
<description>Oracle connection</description>
</data-source>Thank you,
Dave -
ArrayDescriptor ClassCastException DataSource Tomcat5
Hi All,
I wanted to pass an array to pl/sql from Java using ArrayDescriptor, but i'm getting ClassCastException. Can any one suggest a solution for this.
Oracle version is 9.2.0.6
JDBC Drivers are ojdbc14.jar.
with regards
KarthikHi All
[Apologies.... Was out on meeting with client ]
Please Note:-
1)Thr PLSQL WORKS Pergectly Using a Ordinary Connection from
"DriverManager .get Connection()" in a Web container
2) When replaced with Datasource does not work where ever the Array
Discriptor is been declared as JDBC Releam in the Web container.
Tomcat Version is 5.5.12
Oracle is 9.2.0.6
JDBC DRI VER for ORACLE is ojdbc14.jar (from oracle website)
The Code fo which the
ArrayDescriptor adNames = ArrayDescriptor.createDescriptor("ARR_VARCHAR",myCon);
Here is the Stack Trace
==========================================================
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
at com.infinet.clc.VoucherProfileDB.insertProfile(VoucherProfileDB.java:587)
at org.apache.jsp.clc.clc_005fvoucher_005fprofile_005fnew_005fsubmit_jsp._jspService(org.apache.jsp.clc.clc_005fvoucher_005fprofile_005fnew_005fsubmit_jsp:413)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
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 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
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:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
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(Thread.java:595)
nErrorCode : 0
==========================================================
Please some body suggest me a workaround
With regards
Karthik -
Connection ClassCastException trying to create ArrayDescriptor
Create a class that implements oracle.sql.CustomDatum and the toDatum() method. The OracleDriver will call this method to create your oracle.sql.ARRAY object.The just use setObject() to set the value.import oracle.sql.Datum;import oracle.jdbc.driver.OracleConnection;import oracle.sql.CustomDatum;import oracle.sql.ARRAY;import oracle.sql.ArrayDescriptor;public class OracleArray implements CustomDatum { private List data; private String sqlType; // pass in the sql name of the array public OracleArray(String sqlType, List data) { this.data = data; } public Datum toDatum(OracleConnection conn) throws SQLException { ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(sqlType, conn); ARRAY array = new ARRAY(arrayDesc, conn, data.toArray()); return array; }
-
Java.lang.ClassCastException while creating array descriptor
( This post was moved from SQL / PLSQL forum to here )
Hi everyone, i used to pass string array from java to plsql. I wrote a java source, then i load db with loadjava. And i wrote java spec. Then i run the function but i am getting this error :
java.lang.ClassCastException
at oracle.jdbc.driver.PhysicalConnection.putDescriptor(PhysicalConnection.java:4921)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:208)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:175)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:158)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:125)
at SplitterOracle3.tokens2(SplitterOracle3.java:29)
My Java Source is :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import oracle.sql.*;
import oracle.jdbc.driver.OracleConnection;
import oracle.jdbc.driver.OracleDriver;
public class SplitterOracle3 {
public static oracle.sql.ARRAY tokens2(String str,String delim)
try
//Class.forName("oracle.jdbc.driver.OracleDriver");
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//Connection conn = new OracleDriver().defaultConnection( );
OracleDriver ora = new OracleDriver();
OracleConnection conn = (OracleConnection) ora.defaultConnection();
//ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor("MY_ARRAY", ((conn).getRealConnection());
//Connection conn = DriverManager.getConnection("jdbc:default:connection:");
//Connection conn = ((DelegatingConnection) getDataSource().getConnection()).getInnermostDelegate();
// get an initial context
//OracleConnection oracleConnection = (OracleConnection)WSJdbcUtil.getNativeConnection((WSJdbcConnection) wsConn);
ArrayDescriptor arraydesc =
ArrayDescriptor.createDescriptor ("ARR_VARCHAR_100", conn);
String strarr[] = new String[47];
strarr[0]="ahmet";
strarr[1]="mehmet";
int curIndex = 0;
int nextIndex = 0;
boolean nextIsLastToken = false;
int i=0;
while (true)
nextIndex = str.indexOf(delim, curIndex);
if (nextIsLastToken)
//return false;
break;
if (nextIndex == -1)
nextIsLastToken=true;
nextIndex = str.length();
strarr[i] = str.substring(curIndex, nextIndex);
curIndex = nextIndex + 1;
i++;
ARRAY dirArray = new ARRAY(arraydesc, conn, strarr);
return dirArray;*/
catch(Exception ex)
System.err.println(ex.getMessage());
ex.printStackTrace();
return null;
public static void main(String[] args)
String str="2000,2,123553168,1,10,64895,65535,27662,64860,64895,65535,27662,64860,0,,,,,,0,0,2491039806,,,,,,,,,0,0,1,,2491039106,,,,,,,,,,,,";
String strarr[] = new String[47];
long l1,l2;
int j=0;
l1 = System.currentTimeMillis();
for ( int i=0; i<20000000; i++)
strarr = tokens2(str,",");
l2 = System.currentTimeMillis();
System.out.println("Fark :"+ (l2-l1));
The line has "ArrayDescriptor.createDescriptor ("ARR_VARCHAR_100", conn);" causes this error.
java.lang.ClassCastException
at oracle.jdbc.driver.PhysicalConnection.putDescriptor(PhysicalConnection.java:4921)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:208)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:175)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:158)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:125)
at SplitterOracle3.tokens2(SplitterOracle3.java:29)
But i could not find the solution. Can you help me?
Thanks for responses.Hi,
Did you try my suggestion from Re: java.lang.ClassCastException while create array descriptor
Try replacing
oracle.jdbc.driver.OracleConnectionwith
oracle.jdbc.OracleConnectionRegards
Peter -
Error when tyring to create ArrayDescriptors in Weblogic for Oracle
Has anyone every tried to pass arrays to a oracle callable statement within weblogic and recieved the following error?
java.lang.ClassCastException: weblogic.jdbc.rmi.SerialConnection
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:87)
Or has anyone ever gotten this error when trying to use the setObject method - (SQLException Cannot bind object type:) and if so what does it mean.Hi Anver
I am getting this error when I am trying to create ArrayDescriptor using JNDI WL server connection.
Env :
Oracle : 8.1.7
WL Server : 6.1
JDK : 1.3.1
JDBC: 2.0 - classes12.zip
Error Message :
java.lang.ClassCastException: weblogic.jdbc.rmi.SerialConnection
Please let me know if you had find any solution for this error.
This is my code :
public void testArray()
Connection conn = null;
ArrayList serialNumbers=new ArrayList();
serialNumbers.add("296300");
serialNumbers.add("296281");
try
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("SERIALNUMS",conn.getMetaData().getConnection());
ARRAY newArray = new ARRAY(desc, conn, serialNumbers.toArray());
oracle.jdbc.driver.OracleCallableStatement cstmt =(oracle.jdbc.driver.OracleCallableStatement)conn.prepareCall("{call TRIP_WIZARD.GetTripCount(?,?,?)}");
cstmt.setARRAY(1,newArray);
cstmt.registerOutParameter(2,Types.NUMERIC);
cstmt.registerOutParameter(3,Types.VARCHAR);
String errDesc=cstmt.getString(3);
cstmt.execute();
cstmt.close();
}catch(Exception e)
System.out.println("Exception Occured :"+e.toString());
Thanks a lot in advance.
Rama. -
ArrayDescriptor.createDescriptor uses Oracle specific in EJB Server
I use Pramati EJB Server. It is EJB 1.1 compatible. I can use getCustomDatum calls without any error (even though it is Oracle specific). But I can't use setCustomDatum. It throws me ClassCastException error.
My line looks like
((OraclePreparedStatement) pstmt).setCustomDatum(...)
So I tried different method to acheive the same. That is to use Loosely Typed method setArray.
To use setArray I need to get the descriptor from Oracle.
I use the following line to do that.
ArrayDescriptor orderLinesDesc = ArrayDescriptor.createDescriptor("OBL_EMPLOYEE", connection);
Where OBL_EMPLOYEE is a Table of EMPLOYEE Object OB_EMPLOYEE.
Where OB_EMPLOYEE has several primitive fields and a TABLE (OBL_ROLES) of Roles object OB_ROLES.
Where OB_ROLES has primitive types and table (OBL_RESPONSIBILITY) of Responisibilities OB_RESPONSIBILITY
Where OB_Responsibility has primitive types
I get the same ClassCastException.
Both parameters (String, Connection) to createDescriptor are non Oracle-Specific.
But the EJB Server vendor says the method tries to typecast to OracleConnection which they don't support.
Any idea?user521490,
Pardon me if I am asking an obvious question, but did you create the ACCOUNT_TYPE using a "create type" DDL statement? For example:
create or replace type ACCOUNT_TYPE as ...An "ArrayDescriptor" only works for global types (as far as I know).
I'm guessing that JACKCACHE is a [PL/SQL] package, and that's probably why it doesn't work.
Good Luck,
Avi. -
ClassCastException error during setting ArrayDesc
We are using the following code to call pl/sql API passing Arrays as parameters. Following code is working fine in Weblogic 8.1 but throwing a ClassCastException in Weblogic 10.3. Could somebody help to resolve the following issue.
public Object doBaseInConnection(Connection connection) throws SQLException
OracleCallableStatement callableStatement = (OracleCallableStatement)connection.prepareCall(DBUtils.createPreparedStatementFunctionString("bbvoice_customer_discovery_ng", "validate_3", 8));//BBT Comapanion refresh
callableStatement.registerOutParameter(1, Types.INTEGER);
callableStatement.setString(2, identifier);
callableStatement.setString(3, password);
if (productSearchList != null)
ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(configurationService.getConfigurationItem("database.schema.name") + ".PRODUCT_NAME_ARRAY", connection); ARRAY ocbsArray = new ARRAY(arrayDesc, connection, productSearchList);
callableStatement.setARRAY(4, ocbsArray);
else
callableStatement.setNull(4, Types.ARRAY);
Error Message:
java.lang.ClassCastException: $Proxy428 cannot be cast to oracle.jdbc.OracleConnection
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:155)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:123)Windows requires the Windows ECHO service to be installed when using Coherence via the default Windows Firewall, which is probably not the case by default in corporate environments.
To do so, go to Control Panel, Turn Windows features on or off, Install “Simple TCPIP services”. (Make sure the service is started by default).
This should solve the problem. -
VArray,TypeDescriptor, Connection, TransactionManager - ClasscastException
Hi,
I have a problem with unit testing an object with a collection which is stored as a VArray in the database.
I have a datasource with a JNDIConnector. When I use an externalTransactionController I am not able to save my object. The problem is that the connection (T4CConnection) is proxied ($Proxy0). This results in a ClassCastException in the following Oracle code:
TypeDescriptor:
public void setPhysicalConnectionOf(Connection connection) {
m_conn = ((OracleConnection)connection).physicalConnectionWithin();
Is there a workaround for this?
With kind regards.This is the stacktrace:
java.lang.ClassCastException: $Proxy0
at oracle.sql.TypeDescriptor.setPhysicalConnectionOf(TypeDescriptor.java:264)
at oracle.sql.TypeDescriptor.<init>(TypeDescriptor.java:79)
at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:133)
at oracle.toplink.objectrelational.ObjectRelationalDescriptor.buildFieldValueFromDirectValues(ObjectRelationalDescriptor.java:77)
at oracle.toplink.mappings.foundation.AbstractCompositeDirectCollectionMapping.writeFromObjectIntoRow(AbstractCompositeDirectCollectionMapping.java:709)
at oracle.toplink.internal.descriptors.ObjectBuilder.buildRow(ObjectBuilder.java:753)
at oracle.toplink.internal.descriptors.ObjectBuilder.buildRow(ObjectBuilder.java:742)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:401)
at oracle.toplink.queryframework.InsertObjectQuery.executeCommit(InsertObjectQuery.java:60)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.performUserDefinedWrite(DatabaseQueryMechanism.java:622)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.performUserDefinedInsert(DatabaseQueryMechanism.java:586)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.insertObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:479)
at oracle.toplink.queryframework.WriteObjectQuery.executeCommitWithChangeSet(WriteObjectQuery.java:110)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:259)
at oracle.toplink.queryframework.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:47)
at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:603)
at oracle.toplink.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:519)
at oracle.toplink.queryframework.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:100)
at oracle.toplink.queryframework.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:72)
at oracle.toplink.publicinterface.UnitOfWork.internalExecuteQuery(UnitOfWork.java:2532)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:981)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:938)
at oracle.toplink.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:240)
at oracle.toplink.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:161)
at oracle.toplink.publicinterface.Session.writeAllObjectsWithChangeSet(Session.java:3123)
at oracle.toplink.publicinterface.UnitOfWork.commitToDatabase(UnitOfWork.java:1242)
at oracle.toplink.publicinterface.UnitOfWork.commitToDatabaseWithChangeSet(UnitOfWork.java:1330)
at oracle.toplink.publicinterface.UnitOfWork.issueSQLbeforeCompletion(UnitOfWork.java:2799)
at oracle.toplink.publicinterface.UnitOfWork.issueSQLbeforeCompletion(UnitOfWork.java:2779)
at oracle.toplink.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:96)
at oracle.toplink.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:55)
at oracle.toplink.internal.ejb.cmp3.transaction.base.TransactionImpl.commit(TransactionImpl.java:195)
at oracle.toplink.internal.ejb.cmp3.transaction.base.TransactionManagerImpl.commit(TransactionManagerImpl.java:68)
at nl.politie.isc.nlsis.domain.dao.varray.BootMotorVArrayTest.testSave(BootMotorVArrayTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) -
JGeometry / oracle.jdbc.OracleDriver ClassCastException
Hi-
I can't seem to store my JGeometry (from the SDO API) back to the database. The code that causes the problem is this:
===== Sample Code ========
import oracle.jdbc.OracleConnection;
OracleConnection oc = (OracleConnection) st.getConnection();
STRUCT struct = JGeometry.store((JGeometry)value,oc);
==========================
That last line of code throws this error:
===== Exception ============
05/01/04 16:50:26 [ERROR] ResultForm - Could not save the ResultBean <java.lang.ClassCastException>java.lang.ClassCastException
at oracle.jdbc.driver.OracleConnection.unwrapCompletely(OracleConnection.java:5075)
at oracle.jdbc.driver.OracleConnection.physicalConnectionWithin(OracleConnection.java:5126)
at oracle.sql.TypeDescriptor.setPhysicalConnectionOf(TypeDescriptor.java:494)
at oracle.sql.TypeDescriptor.<init>(TypeDescriptor.java:147)
at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:186)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:118)
at oracle.spatial.geometry.JGeometry.createDBDescriptors(JGeometry.java:1323)
at oracle.spatial.geometry.JGeometry.store(JGeometry.java:1257)
at gov.usgswim.wdnr.fishform.GeometryType.nullSafeSet(GeometryType.java:54)
=========================
It looks like the oracle.jdbc.driver.OracleConnection.unwrapCompletely method is assuming the connection to be something that it is not - but I'm stumped without the source code.
I've seen someone speculate that this is a classloader issue, but I'd have no idea how to resolve that within OC4J.
Here is my setup:
Running from JDev 9.0.5.2 using OC4J 9.0.5.
JDBC connections are provided via JNDI by specifying the datasource thru JDev. I've tried replacing the JDBC drivers that come with OC4J with the newer versions (that is, classes12.jar --> classes14.jar)
Database version is 10.1.0.3.0
I'm pretty much stuck until I can work this out, so any help would be appreciated.
Thanks in advance,
Eric EvermanHi LJ - Thanks for the reply.
I'm leaving out detail about the framework I'm working within. For instance, the full method that saves the JGeometry back to the db is part of a Hibernate UserType for which I can't change the method signiture - thus the PreparedStatement.getConnection(). The full method looks like this:
=========== Java Method =================
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
STRUCT struct = null;
if (value != null) {
if (value instanceof JGeometry) {
JGeometry jg = (JGeometry)value;
System.out.println("Storing a Geom object to the db. Info:");
System.out.println(" Type: " + jg.getType());
System.out.println(" # of points: " + jg.getNumPoints());
System.out.println(" isPoint: " + jg.isPoint());
System.out.println(" X, Y: " + jg.getFirstPoint()[0] + ", " + jg.getFirstPoint()[1]);
//System.out.println(" elemInfo length: " + jg.getElemInfo().length); (throws error)
OracleConnection oc = (OracleConnection) st.getConnection();
struct = JGeometry.store(jg,oc);
} else {
throw new HibernateException("Cannot set GeometryType value to " + value.getClass().getName());
} //keep null value
st.setObject(index, struct);
==================================
==== Typical Output ==============
05/01/04 20:53:08 Storing a Geom object to the db. Info:
05/01/04 20:53:08 Type: 1
05/01/04 20:53:08 # of points: 1
05/01/04 20:53:08 isPoint: true
05/01/04 20:53:08 X, Y: 385343.3057, 562597.748
==================================
I've no reason to think that the connection I'd get from the prepared statement would be anything other then the connection returned from JNDI, but I'll try a simplified test to make sure.
My Geom is point data - would I expect JGeometry.getElemInfo() to return null in that case? Currently it does return null immediately after I load the JGeom from the database. -
Remote object trying to return another remote object and a ClassCastExcepti
I have a server running with a TreeModel (the tree model implements Remote). I also have the the TreeNodes all linked together on the server. Now, I can get to the TreeModel on the server and the root node of the remote tree model.
treeModelStub = (treeModelIface)Naming.lookup(url+"remoteTM"); //works
rootStub = (remoteTreeNodeIface)treeModelStub.getRoot(); //works. The call to getRoot returns Object
But when I call
remoteTreeNodeIface aChild = (remoteTreeNodeIface)rootStub.getChildAt(index) //Does not work. "Exception in thread "main" java.lang.ClassCastException
at remoteTreeNode_Stub.getChildAt(Unknown Source)
The remote tree node method getChildAt returns TreeNode because the class implements TreeNode:
public class remoteTreeNode extends UnicastRemoteObject implements rdcaDataIface, Comparable, TreeNode {
public TreeNode getChildAt(int idx) {
System.out.println("DEBUG: class is "+this.getClass()); // class is remoteTreeNode
return (remoteTreeNode)children.get(idx);
The remote interface is defined as:
public interface rdcaDataIface extends java.rmi.Remote {
public TreeNode getChildAt(int idx) throws RemoteException;
Any ideas why this does not work. Why can a remote object of type Object be returned just fine, but a TreeNode not be returned?
Thank you for your help,
BrentI have a server running with a TreeModel (the tree
model implements Remote). I also have the the
TreeNodes all linked together on the server. Now, I
can get to the TreeModel on the server and the root
node of the remote tree model.
treeModelStub =
(treeModelIface)Naming.lookup(url+"remoteTM");
//works
rootStub =
(remoteTreeNodeIface)treeModelStub.getRoot();
//works. The call to getRoot returns Object
But when I call
remoteTreeNodeIface aChild =
(remoteTreeNodeIface)rootStub.getChildAt(index)******************************************
can only be casted to rdcaDataIface. The returned object is an instanceof the rdcaDataIface_stub, which have nothing to do with TreeNode.
//Does not work. "Exception in thread "main"
java.lang.ClassCastException
at remoteTreeNode_Stub.getChildAt(Unknown
t(Unknown Source)
The remote tree node method getChildAt returns
TreeNode because the class implements TreeNode:
public class remoteTreeNode extends
UnicastRemoteObject implements rdcaDataIface,
Comparable, TreeNode {
public TreeNode getChildAt(int idx) {
System.out.println("DEBUG: class is
lass is "+this.getClass()); // class is
remoteTreeNode
return (remoteTreeNode)children.get(idx);
The remote interface is defined as:
public interface rdcaDataIface extends java.rmi.Remote
public TreeNode getChildAt(int idx) throws
ows RemoteException;
Any ideas why this does not work. Why can a remote
object of type Object be returned just fine, but a
TreeNode not be returned?
Thank you for your help,
Brent -
Java.lang.ClassCastException
My class CDRack is almost ready, but in the last method
sortAlphabetically() there
comes java.lang.ClassCastException. I found in the net
http://java.sun.com/docs/books/tutorial/collections/algorithms/
that with method Collections.sort(l) I can sort alphabetically.
The code compiles, but when I run it with a tester program, it stops
to ClassCastException in the almost last row.
Something is wrong with Collections.sort(l) ?
/** Class CDRack represents collections of compact discs. Discs are
located in the rack in slots numbered from zero upwards. The discs are
represented by Record objects and empty slots by null values. */
public class CDRack extends Object {
private Record[] mRecords;
private int size;
/**Creates a new, empty CD rack.
Parameters:
size - the size of the new rack, i.e. the number of slots it has */
public CDRack(int size) {
mRecords = new Record[size];
this.size = size;
/** "Organizes" the discs in the rack so that they will be located in
consecutive slots starting at slot number zero, and any and all empty
slots will be at the "end of the rack". After calling this method, the
discs are in an undefined (i.e. arbitrary) order - the only thing this
method guarantees is that there aren't any empty slots in between full
ones.
public void organize() {
// Turn array into a list - more flexible
List l = Arrays.asList(aanilevyt);
// Remove all nulls from a copy of the list which supports removal.
l = new ArrayList(l);
while (l.remove(null)) /*do nothing*/;
// Clear the original array.
for (int i = 0; i < mRecords.length; i++){
mRecords[i] = null;
} // Put the non-nulls back.
l.toArray(mRecords);
/**"Organizes" the discs in the rack to the beginning of the rack (see
the method organize) and sorts them in alphabetical order. Recordings
by the same artist are placed in alphabetical order by disc name. */
public void sortAlphabetically() {
// Turn array into a list - more flexible
List l = Arrays.asList(aanilevyt);
// Remove all nulls from a copy of the list which supports removal.
l = new ArrayList(l);
while (l.remove(null)) /*do nothing*/;
// Clear the original array.
for (int i = 0; i < mRecords.length; i++){
mRecords[i] = null;
} // Put the non-nulls back.
l.toArray(mRecords);
Collections.sort(l); // alphabetical order. THERE IS CLASSCASTEXCEPTION
}I have thought and thought but the sorting alphabetically doesnt work.
I can't use Collections.sort and class Record doesnt implement Comparable(and I can't change it).
One suggestion was that I could make my own class which implements Comparator. Could it be like this
import java.util.*;
public class AlphabeticComparator
implements Comparator{
public int compare(Object o1, Object o2) {
String s1 = (String)o1;
String s2 = (String)o2;
return s1.toLowerCase().compareTo(
s2.toLowerCase());
} But how an earth can I tell to CDRack class that it would
use the class AlphabeticComparator?
Somebody please save my Christmas!
/** Class CDRack represents collections of compact discs. Discs are
located in the rack in slots numbered from zero upwards. The discs are
represented by Record objects and empty slots by null values. */
public class CDRack extends Object {
private Record[] mRecords;
private int size;
/**Creates a new, empty CD rack.
Parameters:
size - the size of the new rack, i.e. the number of slots it has */
public CDRack(int size) {
mRecords = new Record[size];
this.size = size;
/** "Organizes" the discs in the rack so that they will be located in
consecutive slots starting at slot number zero, and any and all empty
slots will be at the "end of the rack". After calling this method, the
discs are in an undefined (i.e. arbitrary) order - the only thing this
method guarantees is that there aren't any empty slots in between full
ones.
public void organize() {
// Turn array into a list - more flexible
List l = Arrays.asList(aanilevyt);
// Remove all nulls from a copy of the list which supports removal.
l = new ArrayList(l);
while (l.remove(null)) /*do nothing*/;
// Clear the original array.
for (int i = 0; i < mRecords.length; i++){
mRecords<i> = null;
} // Put the non-nulls back.
l.toArray(mRecords);
/**"Organizes" the discs in the rack to the beginning of the rack (see
the method organize) and sorts them in alphabetical order. Recordings
by the same artist are placed in alphabetical order by disc name. */
public void sortAlphabetically() {
Maybe you are looking for
-
Error while transporting function grp from lower version to higher version
Dear Experts, While transporting the function group and function modules from system A to system B, I am getting the below error "Program SAPLZATSCSNG_EINB, Include LEINBF10: Syntax error in line 000068 Field 'GF_ETS_MODIFIED' is unknown. It is nei
-
I do not see glucose monitoring option in health app !!!!!
I have been adding values of my daily blood glucose but suddenly all the data disappeared and now I do not even an option of Blood Glucose in the Health app. What is happening?
-
Bind value truncated in trace file
Hi, I ran a level 12 trace, but it looks like the display of the bind variable values in the trace file is limited to about 255 characters. Is there any setting I can change to get it to dump the entire value? Thanks!
-
Uploaded Flash Page not fully loading
I created a Flash document that contains 6 hidden FLV files that reveal and play with a mouse rollover on respective text. The file tests perfectly well. However, when I upload all FLV files, as well as the respective SWF and HTML files, and then acc
-
I cannot remember the answers to my security questions. Can you please help me reset them?