Category: Oracle

JPA: How to resolve the “java.sql.SQLException: Io exception: Size Data Unit (SDU) mismatch” error in Java/JEE/JPA

I was developing a JPA JEE application were this strange and vague error appeared and stopped me from storing OrderHeader/OrderItem POJO’s.

Internal Exception: java.sql.SQLException: Io exception: Size Data Unit (SDU) mismatch.

This SDU error is rather vague and does not reveal the true problem in the executed SQL or Schema or constraint violation!
After many trials, here is the way I was able to identify the real Oracle DB error !

  1. Take the OrderHeader/OrderItems classes into a new JSE batch project.
  2. in NB , right-click –> insert code–> Persist EntityClass
  3. Add the following properties to “persistence.xml” for more detailed logging:
<properties>
 <property name="toplink.logging.level" value="FINEST"/>
 <property name="eclipselink.logging.parameters" value="true"/>
 </properties>

After the previous update you should be able to see in the Glassfish logs, all the executed SQL’s and even their bind variables.

<pre>Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Io exception: Size Data Unit (SDU) mismatch
Error Code: 17002
Call: INSERT INTO XYZ (x , y, z) values (?,?,?)
 bind => [655, 5, 62]
Query: InsertObjectQuery(zyx.entity.TocOrderItem[ ])
 at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
 at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1605)
 at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:893)
 at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:957)
 at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:630)
 at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
 at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1995)
...
Caused by: oracle.net.ns.NetException: Size Data Unit (SDU) mismatch
at oracle.net.ns.Packet.receive(Packet.java:264)
at oracle.net.ns.DataPacket.receive(DataPacket.java:92)
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:172)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:117)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:92)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:77)
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1034)
at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1010)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:588)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:953)
... 97 more

And now run the new batch project and you will see the (ORA-) error clearly.  Mine was related to some XMLType / Oracle Fields in the records I want to save (out of scope).

The problem as it seems to be : that the EJB Container shields and wraps some of the returned error codes and connections; this produces the vague SDU error. The solution uses the good-old-normal JSE not JEE  JVM which will allow a more interaction between your program and JDBC.

Yet another Oracle XML challenge

If you have read my previous tip about Oracle XML API

You would learn to use XML API as nice quick’n’dirty replacement to tons of decode functions.

In this challenge I got on Oracle 9i (yes they still exist in production 2013).

  • We have a string such as ‘123#124#122’, we need to split the different values into record , sort them and map them from a Value-key pair table in an Oralce 9i database.
  • And for reasons of implementation it has to be done in pure SQL, not PL/SQL.
  • and it is best to avoid creating any stored procedures or functions.

A more elaborate description of the problem : Splitting a delimited text with Oracle SQL into records, and sorting them out.

This is a real challenge in the production environment I’m working in.

Read more »

Quick examples into Oracle PL/SQL collections.

There are three types of Oracle Collections you can use in PL/SQL :

  • Index-by-Tables : Unbounded, Hashes , Single Dimensional
  • Nested-Tables : Unbounded, Array, unordered, Single dimension
  • VARRAYS : Bounded, Single Dimension

Each one of these Types have its own features and limitations.

Most of them, share some common functions like EXTEND, FIRST, LAST, ..etc

These self-explaining examples; helps the reader get a first introduction into each collection type .

Read more »

Some quick and easy examples into oracle XML DB.

Oracle XML DB is the API of SQL functions inside the oracle DBMS which makes oracle XML enabled.

If you don’t know much about XML, please refer to this quick tutorial :  especially the starting slide 74 discussing Oracle and XML.

XML DB is a series of SQL functions ,PL/SQL packages and DBMS features for processing XML data In and out of Oracle.

The most important feature; is adding the new column type “XMLType”; which enable storing structured and unstructured XML documents into oracle. A considerable step ahead from CLOB.

There are two sets of features :

Read more »

JAVA : Statistics Class

Another name for it would be Counter class.

How many times you did this ?

int databaseUpdateCounter=0;
.
{
.
     databaseUpdateCounter++;
.
}
.
.
System.out.println( "databaseUpdateCounter"+ databaseUpdateCounter);

you only need to follow up on the count of a certain operation.

And then you needed to count something else, and kept on adding counterVariables ?!

Read more »