Data truncation error while setting INOUT parameter in Stored Procedure - java

I'm calling a stored procedure which has INOUT parameters. Database is AS400 DB2. Type is CHARACTER. I'm getting Data Truncation error while registering and setting the variable. If I set the string directly to the column, it does not have an issue. If I set the same string in a variable and use it to set the column, it throws Data truncation error. Could you please let me know where I'm going wrong and how I can set the value of the column using a variable without causing exception? Please see the end of error stack trace for more information.
try{
String cstmt_str = "CALL " + storedProcName + "(?)";
String status="REJ";
cstmt = conn.prepareCall(cstmt_str);
cstmt.registerOutParameter("5506STS", Types.CHAR);
//cstmt.setString("5506STS","REJ"); does not give a problem
cstmt.setString("5506STS",status); //Data truncation Exception occurs here.
cstmt.execute();
}catch (DataTruncation de) {
logger.error("DatatruncationException error:", de );
displayError(de);
de.printStackTrace();
}
public static void displayError(DataTruncation dataTruncation) {
logger.info("Data truncation error: ");
logger.info("dataTruncation.getDataSize():"+dataTruncation.getDataSize() + " number of bytes of data that should have been transferred.");
if (!dataTruncation.getRead())
logger.info("dataTruncation.getRead() is False. Its Written (Error:). ");
logger.info("dataTruncation.getTransferSize():"+dataTruncation.getTransferSize()
+ " number of bytes of data actually transferred.");
}
Stored Procedure Signature:
Number Mode Name DataType Length
1 INOUT 5506STS CHARACTER 3
I tried to find out the length of the string status:
int len = status.getBytes().length; // Output: 5
I'm out of options. Please let me know how to successfully set the value in the variable "status" into "5506STS".
ERROR TRACE:
DatatruncationException error:
java.sql.DataTruncation: Data truncation
at com.ibm.as400.access.AS400JDBCPreparedStatement.testDataTruncation(AS400JDBCPreparedStatement.java:3450)
at com.ibm.as400.access.AS400JDBCPreparedStatement.setValue(AS400JDBCPreparedStatement.java:3361)
at com.ibm.as400.access.AS400JDBCPreparedStatement.setString(AS400JDBCPreparedStatement.java:2999)
at com.ibm.as400.access.AS400JDBCCallableStatement.setString(AS400JDBCCallableStatement.java:3082)
at org.jboss.jca.adapters.jdbc.WrappedCallableStatement.setString(WrappedCallableStatement.java:1563)
at com.ssss.ssjtracdbws.dao.SSJTracDBWSDAO.submitNewRequestJSON(SSJTracDBWSDAO.java:699)
at com.ssss.ssjtracdbws.webservices.SSJTracDBService.submitNewRequestJSON(SSJTracDBService.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:126)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:559)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340)
at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:353)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:911)
at org.apache.tomcat.util.net.NioEndpoint$ChannelProcessor.run(NioEndpoint.java:920)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Data truncation error:
dataTruncation.getDataSize():5 number of bytes of data that should have been transferred.
dataTruncation.getRead() is False. Its Written (Error:).
dataTruncation.getTransferSize(): 3 number of bytes of data actually transferred.

Well, I found it out myself. The "status" that was passed to the function had a single quote surrounding it.('APP') this made the length 5 instead of 3. Now I removed the single quotes.Its working fine.

Related

Unable to call DOC_INFO_BY_NAME from a Custom WCC Java Service

I'm creating a Custom Java Component for oracle-ucm to do some processing based on passed in Excel Files. The files are keyed off of Content ID.
one of the first things the application does after reading the excel file is call DOC_INFO_BY_NAME.
In short: Why can't DOC_INFO_BY_NAME by name find dProcessingState and how do I fix it?
Full Details Below
However, when I do I get the following Error Message:
Error getting DOC_INFO for 'LOCALHOST16200000001'. Unable to retrieve information for 'LOCALHOST16200000001'. Unable to retrieve file format information. Cannot find the parameter 'dProcessingState'. [ Details ]
An error has occurred. The stack trace below shows more information.
!$Error getting DOC_INFO for 'LOCALHOST16200000001'.!csUnableToGetRevInfo2,LOCALHOST16200000001!csUnableToGetFileFormatInfo!syParameterNotFound,dProcessingState
intradoc.common.ServiceException: !csUnableToGetRevInfo2,LOCALHOST16200000001!csUnableToGetFileFormatInfo
at intradoc.server.ServiceRequestImplementor.buildServiceException(ServiceRequestImplementor.java:2176)
at intradoc.server.Service.buildServiceException(Service.java:2404)
at intradoc.server.Service.createServiceExceptionEx(Service.java:2398)
at intradoc.server.Service.createServiceException(Service.java:2393)
at intradoc.server.DocCommonHandler.getDocFormats(DocCommonHandler.java:271)
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:597)
at intradoc.common.IdcMethodHolder.invokeMethod(IdcMethodHolder.java:86)
at intradoc.common.ClassHelperUtils.executeMethodReportStatus(ClassHelperUtils.java:324)
at intradoc.server.ServiceHandler.executeAction(ServiceHandler.java:79)
at intradoc.server.Service.doCodeEx(Service.java:622)
at intradoc.server.Service.doCode(Service.java:594)
at intradoc.server.ServiceRequestImplementor.doAction(ServiceRequestImplementor.java:1693)
at intradoc.server.Service.doAction(Service.java:566)
at intradoc.server.ServiceRequestImplementor.doActions(ServiceRequestImplementor.java:1483)
at intradoc.server.Service.doActions(Service.java:561)
at intradoc.server.ServiceRequestImplementor.executeActions(ServiceRequestImplementor.java:1415)
at intradoc.server.Service.executeActions(Service.java:547)
at intradoc.server.ServiceRequestImplementor.doRequestInternalEx(ServiceRequestImplementor.java:958)
at intradoc.server.ServiceRequestImplementor.executeServiceTopLevelSimple(ServiceRequestImplementor.java:1070)
at com.lowes.content.edam.massMetaDataUpdate.service.types.ServicesWrapper.executeService(ServicesWrapper.java:139)
at com.lowes.content.edam.massMetaDataUpdate.service.file.GetFileService.getDocInfo(GetFileService.java:478)
at com.lowes.content.edam.massMetaDataUpdate.service.ServiceFieldMapper.getMappings(ServiceFieldMapper.java:76)
at com.lowes.content.edam.massMetaDataUpdate.file.mapper.impl.FieldMapWorker.doInBackground(FieldMapWorker.java:107)
at com.lowes.content.edam.massMetaDataUpdate.file.mapper.impl.FieldMapWorker.doInBackground(FieldMapWorker.java:37)
at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at javax.swing.SwingWorker.run(SwingWorker.java:316)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: intradoc.data.DataException: !syParameterNotFound,dProcessingState
at intradoc.data.DataBinder.getEx(DataBinder.java:1258)
at intradoc.data.DataBinder.get(DataBinder.java:1057)
at intradoc.server.DocCommonHandler.getProcessingState(DocCommonHandler.java:277)
at intradoc.server.DocCommonHandler.getDocFormats(DocCommonHandler.java:184)
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:597)
at intradoc.common.IdcMethodHolder.invokeMethod(IdcMethodHolder.java:87)
at intradoc.common.ClassHelperUtils.executeMethodReportStatus(ClassHelperUtils.java:324)
at intradoc.server.ServiceHandler.executeAction(ServiceHandler.java:79)
at intradoc.server.Service.doCodeEx(Service.java:622)
at intradoc.server.Service.doCode(Service.java:595)
... 20 more
I've tried multiple ways of calling the additional service.
currently I'm using:
public DataBinder executeService(DataBinder binder, Workspace workspace)
throws DataException, ServiceException
{
final String serviceName = binder.getLocal(Services.IdcService);
//check for REMOTE_USER
String username = binder.getEnvironmentValue("REMOTE_USER");
if ( null == username || "".equals(username.trim()))
{
log.warn("username not found, searching the binder.");
try { username = binder.get("dUser"); }
catch (DataException de) { log.error("Unable to get Username.", de); }
if ( null != username && !"".equals(username.trim()))
{ binder.setEnvironmentValue("REMOTE_USER", username); }
else { throw new IllegalStateException("Username required!"); }
}
//clear idcToken
binder.getLocalData().remove("idcToken");
log.info("About to run '" + serviceName + "' as '" + username +"'");
try
{
log.info("Calling service " + serviceName + ": "
+ binder.getLocalData().toString());
// Execute service
service.createRequestImplementor();
service.getRequestImplementor()
.executeServiceTopLevelSimple(binder, serviceName,
service.getUserData());
log.info("Finished calling service");
return service.getBinder();
}
catch (DataException e)
{
String msg = "Unexpected Failure executing service '"+serviceName+"'";
log.info(msg, e);
throw e; //log and duck
}
}
So why can't WCC find dProcessingState, and how do I fix it?
Your way of calling the service is fairly standard and I don't think that is the reason. My first guess is that your other code is interfering with your call to DOC_INFO_BY_NAME. If you disable all your other custom code (perhaps easier said than done) and call the service in a clean component, then I think it'll work. Second candidate is to reconsider if your custom service really should be a FileService. Not sure if that affects the result, but perhaps worth a try.
It almost seems like a bug to me.
getProcessingState() is called from getDocFormats() which is called from the DOC_INFO* service.
The code for getProcessingState() first retrieves dProcessingState.
String curProcState = this.m_binder.get("dProcessingState");
Then, it checks if this is null:
if (curProcState != null)
However, it never gets to the null check. This is because DataBinder.get() is requiring a value for any key passed in (in this case dProcessingState.)
Trying setting dProcessingState to a value in the DataBinder before calling the service.
binder.setLocal("dProcessingState", "ignore");
The problem was totally my fault. I had tried to be fancy, and extend Databinder to make it easier for me to use. Turns out my extension was faulty.
Rolling back to the default and double checking my data in the binder fixed it.

GoogleAppEngine : GenericScorer.search throws NegativeArraySizeException

I am trying to search an index in my project.
When i search with the
searchText: semester:"S1 / 2016" AND status:Validated AND emp_id>0
, I am getting the results properly.
When i search with the
searchText: semester:"S1 / 2016" AND status:Validated AND emp_id>500 , I am getting the below exception
java.lang.NegativeArraySizeException
at com.google.appengine.api.search.dev.GenericScorer.search(GenericScorer.java:196)
at com.google.appengine.api.search.dev.LocalSearchService.searchForApp(LocalSearchService.java:584)
at com.google.appengine.api.search.dev.LocalSearchService.search(LocalSearchService.java:534)
at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:541)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:484)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:461)
at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:493)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:490)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Below is my code where the search is performed:
public Results<ScoredDocument> retrieveDocuments(String searchText) {
if (searchText.length() > 2000) {
throw new InternalException(new Exception("Error - Too long query !!"),
BaseValidationMessages.SEARCH_STRING_EXCEEDS_LIMIT);
}
QueryOptions options =QueryOptions.newBuilder().setOffset(0).setLimit(2)
.setSortOptions(createSortOptions("emp_id", "asc")).build();
Query query = Query.newBuilder().setOptions(options).build(searchText);
IndexSpec indexSpec = IndexSpec.newBuilder().setName("Beneficiaries").build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
return index.search(query);
}
Google Appengine throws NegativeArraySizeException, if the offset passed to the index search is out range of the available results count.
For E.g, Consider that there 50 documents available in search Index for the given search Query Text, if the offset set in the search query options is more than 50, then it would throw NegativeArraySizeException on executing the search.
QueryOptions options = QueryOptions.newBuilder().setOffset(**51**)
So Before setting offset, make sure the documents are available for the offset using the previous results.
First Query:
QueryOptions options = QueryOptions.newBuilder().setOffset(0).setLimit(50);
IndexSpec indexSpec = IndexSpec.newBuilder().setName("Beneficiaries").build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
Results<ScoredDocument>results = index.search(query);
If the results returned from the above query is equal to 50, then search for the Next Set;
QueryOptions options = QueryOptions.newBuilder().setOffset(**51**)
if the results returned is less than 50, then we can assume that, there is no more results available to search for the offset > 50, then we can stop further searching.

Octave not able to evaluate script due to failure in loading scalar constant

I have a project where I need to make several computations using Octave. I communciate with Octave using the javaoctave bridge. Below is simplified example code to show what I am doing.
// One of the fields of my class that evaluates equations. This class is provided by teh bridge.
private OctaveEngine scriptEngine;
// The script contains the equation, e.g.: Ampere = PowerConsumption (Lights, Dryer, Dishwasher, Laptop, Smartphone);
private String script;
public synchronized void evaluate() {
// Variable is a class implementing Cloneable and harbouring a unit as well as its unit and a few utility functions.
LinkedHashSet<Variable> dependentVariables;
String evaluationErrors;
Preconditions.checkState(scriptEngine != null);
try {
engineErrors.reset();
scriptEngine.setErrorWriter(engineErrors);
initParameters();
scriptEngine.eval(this.script);
} catch (Exception exception) {
LOGGER.log(Level.SEVERE, "Error while evaluating script " + this.script, exception); //$NON-NLS-1$
}
// The mapping stores the variables and the interface objects changing or reading their values.
dependentVariables = mapping.getDependentVariables();
for (Variable variable : dependentVariables) {
try {
OctaveDouble result = scriptEngine.get(OctaveDouble.class, variable.getName());
variable.setValue(result.get(1));
} catch (Exception exception) {
LOGGER.log(Level.SEVERE, "Error while retrieving variable " + variable.getName(), exception); //$NON-NLS-1$
}
}
evaluationErrors = engineErrors.toString();
if (evaluationErrors.length() > 0) {
LOGGER.log(Level.WARNING, "Error while evaluating equation :" + evaluationErrors); //$NON-NLS-1$
}
}
private void initParameters() {
for (Variable variable : lockedMapping.getIndependentVariables()) {
Double numericValue = Double.valueOf(variable.getValue().toString());
if (isNegative(numericValue)) {
numericValue *= -1d;
}
scriptEngine.put(variable.getName(), Octave.scalar(numericValue));
}
}
private static boolean isNegative(double _double) {
return Double.doubleToRawLongBits(_double) < 0;
}
What I was getting as error message was that:
WARNING: Error while evaluating equation :error: load: failed to load scalar constant
error: load: trouble reading ascii file '-'
error: load: reading file -
Googling a bit I found that negative values (or large inputs) can cause this problem. However, it was deemed to be solved. I don't have large inputs and I tried to make sure my values are positive (which all were even by testing using a syso!
I did a more in-depth search for the root cause and stumbled upon it. It seems that in the OcaveExec class, line 157 in the getFromFuture method where it calles future.get(), an ExecutionException is thrown. Below is the immediate stacktrace:
java.util.concurrent.ExecutionException: dk.ange.octave.exception.OctaveIOException: IOException during close
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at dk.ange.octave.exec.OctaveExec.getFromFuture(OctaveExec.java:157)
at dk.ange.octave.exec.OctaveExec.eval(OctaveExec.java:142)
at dk.ange.octave.io.OctaveIO.set(OctaveIO.java:56)
at dk.ange.octave.OctaveEngine.put(OctaveEngine.java:141)
at [redacted].OctaveEquation.initParameters(OctaveEquation.java:109)
at [redacted].OctaveEquation.evaluate(OctaveEquation.java:72)
at [redacted].LinearEquationSystem.inputChanged(LinearEquationSystem.java:105)
at [redacted].variable.NumericalVariable.setValue(NumericalVariable.java:127)
at [redacted].widget.ValueWidget.actionDrop(ValueWidget.java:88)
at [redacted].TangibleObjectManager.dropObject(TangibleObjectManager.java:207)
at [redacted].adapter.TuioAdapter.addTangibleObject(TuioAdapter.java:318)
at [redacted].adapter.TuioAdapter.addTuioObject(TuioAdapter.java:295)
at TUIO.TuioClient.acceptMessage(TuioClient.java:339)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchMessage(OSCPacketDispatcher.java:73)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchPacket(OSCPacketDispatcher.java:49)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchBundle(OSCPacketDispatcher.java:56)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchPacket(OSCPacketDispatcher.java:40)
at com.illposed.osc.OSCPortIn.run(OSCPortIn.java:65)
at java.lang.Thread.run(Unknown Source)
Caused by: dk.ange.octave.exception.OctaveIOException: IOException during close
at dk.ange.octave.exec.OctaveReaderCallable.call(OctaveReaderCallable.java:65)
at dk.ange.octave.exec.OctaveReaderCallable.call(OctaveReaderCallable.java:1)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
... 1 more
Caused by: java.io.IOException: Pipe to octave-process broken
at dk.ange.octave.exec.OctaveExecuteReader.read(OctaveExecuteReader.java:68)
at java.io.Reader.read(Unknown Source)
at dk.ange.octave.exec.OctaveExecuteReader.close(OctaveExecuteReader.java:96)
at dk.ange.octave.exec.OctaveReaderCallable.call(OctaveReaderCallable.java:61)
... 5 more
java.util.concurrent.ExecutionException: dk.ange.octave.exception.OctaveIOException: IOException during close
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at dk.ange.octave.exec.OctaveExec.getFromFuture(OctaveExec.java:157)
at dk.ange.octave.exec.OctaveExec.eval(OctaveExec.java:142)
at dk.ange.octave.io.OctaveIO.set(OctaveIO.java:56)
at dk.ange.octave.OctaveEngine.put(OctaveEngine.java:141)
at [redacted].OctaveEquation.initParameters(OctaveEquation.java:109)
at [redacted].OctaveEquation.evaluate(OctaveEquation.java:72)
at [redacted].LinearEquationSystem.inputChanged(LinearEquationSystem.java:105)
at [redacted].variable.NumericalVariable.setValue(NumericalVariable.java:127)
at [redacted].widget.ValueWidget.actionDrop(ValueWidget.java:88)
at [redacted].TangibleObjectManager.dropObject(TangibleObjectManager.java:207)
at [redacted].adapter.TuioAdapter.addTangibleObject(TuioAdapter.java:318)
at [redacted].adapter.TuioAdapter.addTuioObject(TuioAdapter.java:295)
at TUIO.TuioClient.acceptMessage(TuioClient.java:339)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchMessage(OSCPacketDispatcher.java:73)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchPacket(OSCPacketDispatcher.java:49)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchBundle(OSCPacketDispatcher.java:56)
at com.illposed.osc.utility.OSCPacketDispatcher.dispatchPacket(OSCPacketDispatcher.java:40)
at com.illposed.osc.OSCPortIn.run(OSCPortIn.java:65)
at java.lang.Thread.run(Unknown Source)
Caused by: dk.ange.octave.exception.OctaveIOException: IOException during close
at dk.ange.octave.exec.OctaveReaderCallable.call(OctaveReaderCallable.java:65)
at dk.ange.octave.exec.OctaveReaderCallable.call(OctaveReaderCallable.java:1)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
... 1 more
Caused by: java.io.IOException: Pipe to octave-process broken
at dk.ange.octave.exec.OctaveExecuteReader.read(OctaveExecuteReader.java:68)
at java.io.Reader.read(Unknown Source)
at dk.ange.octave.exec.OctaveExecuteReader.close(OctaveExecuteReader.java:96)
at dk.ange.octave.exec.OctaveReaderCallable.call(OctaveReaderCallable.java:61)
... 5 more
I am working on a Windows 7 machine, have the path to the Octave bin on my classpath and not sure what I am doing wrong. I assume something goes wrong during IO but I can't seem to put my finger on it.
To be sure all my inputs are known, below are my *.m filed holding both scripts. All my inputs are positive and range from 0 to 2200 (as doubles).
function Load = CircuitLoad(Breaker, Lights, Dryer, Dishwasher, Laptop, Smartphone)
Load = Breaker / ((Lights + Dryer + Dishwasher + Laptop + Smartphone) / 230);
And the second one:
function Ampere = PowerConsumption(Lights, Dryer, Dishwasher, Laptop, Smartphone)
Ampere = (Lights + Dryer + Dishwasher + Laptop + Smartphone) / 230;

Storing an ordered List with JPA/Hibernate

On a Device a user can select the languages of preference in which the content is going to be showed. I have used this for a long time, but updated the system that this list is ordered:
#Required
#OrderColumn(name="preferenceOrder")
#ManyToMany(fetch= FetchType.LAZY)
public List<Language> languages;
But when I try to update the list with the following code:
try{
// Get the codes of the Device
Device device = Device.findById(deviceId);
device.languages.clear();
for(String langCode : languageCodes){
Language lang = Language.findByCode(langCode);
device.languages.add(lang);
}
device.save();
return true;
} catch (Exception e) {
Logger.error(e, "Problem with updating the languages for device: " + e.getLocalizedMessage());
return false;
}
I get the following error:
15:30:36,376 ERROR ~ Problem with updating the languages for device: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 5; expected: 1
javax.persistence.PersistenceException: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 5; expected: 1
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1389)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1323)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:965)
at play.db.jpa.JPABase._save(JPABase.java:41)
at play.db.jpa.GenericModel.save(GenericModel.java:215)
at logic.helpers.LanguageUpdatePerformer.doJobWithResult(LanguageUpdatePerformer.java:47)
at logic.helpers.LanguageUpdatePerformer.doJobWithResult(LanguageUpdatePerformer.java:1)
at play.jobs.Job.call(Job.java:146)
at play.jobs.Job$1.call(Job.java:66)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 5; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:95)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1401)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:86)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:187)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:345)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:962)
... 12 more
What is the reason for this?
I find 5 records, which is right is this case, but expects 1?
Is it because I first clear the whole list, and should I use another way? This is just the easiest for me to add them in the order they are given me.

How to provide correct arguments to setAsciiStream method?

This is my FULL test code with the main method:
public class TestSetAscii {
public static void main(String[] args) throws SQLException, FileNotFoundException {
String dataFile = "FastLoad1.csv";
String insertTable = "INSERT INTO " + "myTableName" + " VALUES(?,?,?)";
Connection conStd = DriverManager.getConnection("jdbc:xxxxx", "xxxxxx", "xxxxx");
InputStream dataStream = new FileInputStream(new File(dataFile));
PreparedStatement pstmtFld = conStd.prepareStatement(insertTable);
// Until this line everything is awesome
pstmtFld.setAsciiStream(1, dataStream, -1); // This line fails
System.out.println("works");
}
}
I get the "cbColDef value out of range" error
Exception in thread "main" java.sql.SQLException: [Teradata][ODBC Teradata Driver] Invalid precision: cbColDef value out of range
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLBindInParameterAtExec(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setStream(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setAsciiStream(Unknown Source)
at file.TestSetAscii.main(TestSetAscii.java:21)
Here is the link to my FastLoad1.csv file. I guess that setAsciiStream fails because of the FastLoad1.csv file , but I am not sure
(In my previous question I was not able to narrow down the problem that I had. Now I have shortened the code.)
It would depend on the table schema, but the third parameter of setAsciiStream is length.
So
pstmtFld.setAsciiStream(1, dataStream, 4);
would work for a field of length 4 bytes.
But I dont think it would work as you expect it in the code. For each bind you should have separate stream.
This function setAsciiStream() is designed to be used for large data values BLOBS or long VARCHARS. It is not designed to read csv file line by line and split them into separate values.
Basicly it just binds one of the question marks with the inputStream.
After looking into the provided example it looks like teradata could handle csv but you have to explicitly tell that with:
String urlFld = "jdbc:teradata://whomooz/TMODE=ANSI,CHARSET=UTF8,TYPE=FASTLOADCSV";
I don't have enough reputation to comment, but I feel that this info can be valuable to those navigating fast load via JDBC for the first time.
This code will get the full stack trace and is very helpful for diagnosing problems with fast load:
catch (SQLException ex){
for ( ; ex != null ; ex = ex.getNextException ())
ex.printStackTrace () ;
}
In the case of the code above, it works if you specify TYPE=FASTLOADCSV in the connection string, but when run multiple times will fail due to the creation of the error tables _ERR_1 and _ERR_2. Drop these tables and clear out the destination tables to run again.

Categories