HsqlException: data exception - hsqldb

I am using hsqldb version 2.2.5 in my application sometimes I am getting
org.hsqldb.HsqlException: data exception: string data, right truncation.
So I want to know what are the possible reasons for that. I am not inserting any data like longvarchar in a varchar column.
http://sourceforge.net/tracker/index.php?func=detail&aid=2993445&group_id=23316&atid=378131
I searched above link but could not get proper feedback.
Given below the exception stack
This exception is not happening frequently.
So what could be the reason for that and how to set the data type length in script file to increase at run time ?
java.sql.SQLException: data exception: string data, right truncation
at org.hsqldb.jdbc.Util.sqlException(Util.java:255)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(JDBCPreparedStatement.java:4659)
at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(JDBCPreparedStatement.java:311)
at com.dikshatech.agent.db.NodesRuntimeTable.persistData(NodesRuntimeTable.java:151)
at com.dikshatech.agent.jobs.WorkFlowJob.execute(WorkFlowJob.java:108)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: org.hsqldb.HsqlException: data exception: string data, right truncation
at org.hsqldb.error.Error.error(Error.java:134)
at org.hsqldb.error.Error.error(Error.java:104)
at org.hsqldb.types.CharacterType.castOrConvertToType(CharacterType.java:523)
at org.hsqldb.types.CharacterType.convertToType(CharacterType.java:638)
at org.hsqldb.StatementDML.getInsertData(StatementDML.java:921)
at org.hsqldb.StatementInsert.getResult(StatementInsert.java:124)
at org.hsqldb.StatementDMQL.execute(StatementDMQL.java:190)
at org.hsqldb.Session.executeCompiledStatement(Session.java:1344)
at org.hsqldb.Session.execute(Session.java:997)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(JDBCPreparedStatement.java:4651)

The maximum size of a VARCHAR column is user-defined. If the inserted data is larger than this, an exception is thrown. The example below defines a table with a VARCHAR(100) column, which limits the size to 100 characters.
CREATE TABLE T (ID INT, DATA VARCHAR(100))
You can use a database manager and execute the SCRIPT command to see all your table definitions and their column size. Alternatively, SELECT * FROM INFORMATION_SCHEMA.COLUMNS shows the characteristics of each column.
You can use the ALTER TABLE table_name ALTER COLUMN col_name SET DATA TYPE to increase the size of an existing column.

For Hibernate/HSQLDB automatically generated schema via #Column annotation on #Entity field of type String you might need to provide length atrribute. Otherwise the length will default to 255 and long input will not fit:
#Lob
#Column(name="column_name", length = 1000)
private String description;

Your field length is not large enough. I used the LONGVARCHAR data type to fix this error.
CREATE TABLE "DEMO_TABLE" ("ID" NUMBER(19,0), "MESSAGE" LONGVARCHAR);
WARNING: Rant follows...
Yep, the error message java.sql.SQLException: data exception: string data, right truncation... makes total sense only after you know what's wrong. Occasionally I find a clear, well-written error message, meant to inform users. The time it takes to write one will be returned 100 fold (or more depending on usage), but usually to others. Hence, there is too little incentive for most to spend the time. It can however come back to benefit the product, as with the Spring Framework which has generally superior error messages.
I'm sure stackoverflow.com does not mind. Poor error messages likely drive people here every minute of every day!

I encountered this error while using Hibernate with HSQLDB. Instead of the usual String field, the offender was a serializable field.
Hibernate mapping file was
<hibernate-mapping package="in.fins.shared">
<class name="Data">
<id name="id" column="id">
<generator class="uuid" />
</id>
<property name="date" column="Date" />
<property name="facts" column = "facts" type="serializable" />
</class>
</hibernate-mapping>
For facts field, which is set to serializable, Hibernate creates a column of type VARBINARY with maximum length 255 in HSQLDB. As serialized object size was more than this size data exception: string data, right truncation was thrown by HSQLDB.
Changing the facts column to Blob with sql-type attribute resolves the problem.
<property name="facts" type="serializable">
<column name="facts" sql-type="blob" />
</property>

I actually faced the same problem, and got fixed relatively quickly.
In my case I've declared a DB table column column like this: description VARCHAR(50), but I was trying to insert a longer string/text in there, and that caused the exception.
Hope this will help you :)

I had the same problem as you describe while testing with HSQLDB.
I'm using hibernate as JPA implementation and this is my mapping class:
#Column (name = "file")
private byte[] file;
In production I'm using PostgreSQL and the problem don't shown up, but with HSQL I had to add the #Type annotation in my mapping to solve that error:
#Column (name = "file")
#Type(type = "org.hibernate.type.MaterializedBlobType")
private byte[] file;
There are many implementations of types. You can take a look at hibernate-core jar, inside the package org.hibernate.type and pick some that matches your mappings.

This error occurs in some scenario's but in the following scenario it is difficult
to retrieve the cause, assume following scenario:
Assume the following entity
#Entity
public class Car {
private String name;
#ManyToOne
#JoinColumn(name = "ownerId")
private Owner owner;
...
When the annotation '#ManyToOne' would be forgotten, but the annotation ' #JoinColumn(name = "ownerId")' would be present! This error would occur, which doesn't really indicate the real issue.

Related

Change profile custom field type (Sitefinity 6.3)

I have an old installation of Sitefinity (version 6.3)
On the profile, I have a custom field that is numeric. I now have the needs to change this to hold a string instead.
What I found was that there is no easy way to change datatype (https://www.progress.com/documentation/sitefinity-cms/edit-an-existing-custom-field), but is It possible by code/config?
I'm guessing that one option is to delete the field, and then recreate it is a possibility, but since I have much data it would be a lot of work to restore data in the field. Is this the only way?
Edit: I've deleted the column and recreated it as a string/varchar.
I'm now facing a problem with some type of converter
type converter initialization failed. The converter with name 'DecimalConverter' does not convert from CLR type 'System. String' to SQL type 'DECIMAL'.
Parameter name: converterName
Actual value was OpenAccessRuntime.Data.DecimalConverter, Telerik.OpenAccess.Runtime, Version=2013.3.1211.3, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342.
This line in stack trace is of importance
[MetadataException: The metadata for field 'CustomerNo_sv' of class 'Telerik.Sitefinity.Security.Model.SitefinityProfile' cannot be initialized: Type converter initialization failed. The converter with name 'DecimalConverter' does not convert from CLR type 'System. String' to SQL type 'DECIMAL'.
Parameter name: converterName
Actual value was OpenAccessRuntime.Data.DecimalConverter, Telerik.OpenAccess.Runtime, Version=2013.3.1211.3, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342.]
Somehow the language specified values isn't converted as I can see. Now the whole site is down and I can't reach backend. So I guess I have to solve this out in DB?
What I do in similar cases is this:
I create the new field and then populate the new column in the database with the values from the old column (field).
In your case, you'd be looking at the sf_sitefinity_profile table.
This way the data will be migrated to the new field.
After that you can delete the old field and start using the new one.

Write to a dynamic BigQuery table through Apache Beam

I am getting the BigQuery table name at runtime and I pass that name to the BigQueryIO.write operation at the end of my pipeline to write to that table.
The code that I've written for it is:
rows.apply("write to BigQuery", BigQueryIO
.writeTableRows()
.withSchema(schema)
.to("projectID:DatasetID."+tablename)
.withWriteDisposition(WriteDisposition.WRITE_TRUNCATE)
.withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED));
With this syntax I always get an error,
Exception in thread "main" java.lang.IllegalArgumentException: Table reference is not in [project_id]:[dataset_id].[table_id] format
How to pass the table name with the correct format when I don't know before hand which table it should put the data in? Any suggestions?
Thank You
Very late to the party on this however.
I suspect the issue is you were passing in a string not a table reference.
If you created a table reference I suspect you'd have no issues with the above code.
com.google.api.services.bigquery.model.TableReference table = new TableReference()
.setProjectId(projectID)
.setDatasetId(DatasetID)
.setTableId(tablename);
rows.apply("write to BigQuery", BigQueryIO
.writeTableRows()
.withSchema(schema)
.to(table)
.withWriteDisposition(WriteDisposition.WRITE_TRUNCATE)
.withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED));

String was not recognized as a valid Boolean Error on varchar column

I am getting this error:
String was not recognized as a valid Boolean.Couldn't store <No> in meetsstd Column. Expected type is Boolean
When I am running this query:
SELECT * FROM work_nylustis_2013_q3.nylustis_details WHERE siteid = 'NYLUSTIS-155718' LIMIT 50
From this code:
Adapter.SelectCommand = New NpgsqlCommand(SQL, MLConnect)
Adapter.Fill(subDT) ' This line throws error
The meetsstd field is a varchar(3) and it does store either a 'Yes' or a 'No' value. How is this getting this confused with a boolean - a varchar should not care whether is holds 'Yes', or 'Si', or 'Oui'? And it only happens on 27 records out of the 28,000 in the table.
I usually blame npgsql for this kind of strangeness, but the last entry in the stack trace is: System.Data.DataColumn.set_Item(Int32 record, Object value)
Any clues?
Thanks!
Brad
To check if it is problem with database or with driver you can reduce problem to one row and column using your current environment:
SELECT meetsstd FROM work_nylustis_2013_q3.nylustis_details WHERE sitenum=1
(of course you must change sitenum into primary key)
Then try such query using psql, pgAdmin or some JDBC/ODBC based general editor.
If psql shows such record which raises error with your Npgsql based application then problem is with Npgsql driver or problem is with displaying query results.
If other tools shows such strange errors then problem is with your data.
Have you changed type of meetsstd field? Mayby you try to show it on some grid and this grid used Boolean field which was converted to Yes/No for displaying?

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. error in VB.Net

There were three similar questions in StackOverFlow but none gave an answer..
If have found why this error in occurring but don't know the fix.
I am using Strongly Typed Dataset for my project which is created as a dll for DAL.
I have added the Sql Server Table into this dataset using the designer and has created a DataAdapter
It works fine when i insert using DataTableAdapter
daLabTest.Insert(txtLabTestId.Text, cmbLabTestType.Text, cmbTestName.Text, txtLabFees.Text, dtpLabEffDate.Value)
but when i want to show the data from the table in a combobox or gridview i get this error.
i told that i found out what the problem is, I just previewed the data using DataSet designer and found out that the Function returns data like this...
The query i wrote to view this in dataset is
Select distinct(TestType) from LabTestTypes
so this should return only one column but the dataset is returning 5 columns but others as null, and the TestName column is a primary which should not be null when returned, so the problem exists..
To resolve this i tried to change the NullValue & AllowDBNull property to [Empty] and true respectively but that didn't worked for me.
Please help me in this...
That overly general constraint exception is nasty, where's the InnerException after so many complaints?!
This template may help identify the problem row and column but a "Fill" version of the query function is needed. E.g. GetDistinct*() --> Fill*(). Then a table can be created and interrogated for the row's error text.
SomeTable tTable = new SomeTable()
try {
// sorry, if you have a GetData, change to the fill version
someTable.FillByActiveLogin(tTable, loginName);
} catch (System.Data.ConstraintException constrExc) {
System.Data.DataRow[] rowsErr = tTable.GetErrors();
for (int i = 0; i < rowsErr.Count(); i++)
if (rowsErr[i].HasErrors)
Dbg.WriteLine(rowsErr[i].RowError);
}
(Thanks Michael S for this hint whoever/wherever you are!)
I got this error in a function from a DLL that uses a stored procedure. The procedure did not return all the fields in the table. One of the fields excluded was one that cannot be null. That apparently caused the constraint exception. When I changed the procedure and the DLL to include that field, the exception went away.
After spending ages on this problem myself, I have resolved it modifying the query in the dataset to return a dummy value (that can be ignored) for each key field that is not required in the output.
So your query would become...
Select distinct TestType, 1 as ID, "Dummy" as TestName, "Dummy" as TestFees, "Dummy" as TestDate
from LabTestTypes

How does NHibernate Projections.Max work with an empty table?

I'm trying to get the maximum value of an integer field in a table. Specifically, I'm trying to automatically increment the "InvoiceNumber" field when adding a new invoice. I don't want this to be an autoincrement field in the database, however, since it's controlled by the user -- I'm just trying to take care of the default case. Right now, I'm using
session.CreateCriteria<Invoice>()
.SetProjection(Projections.Max("InvoiceNumber"))
.FutureValue<int>();
to get the biggest invoice number already in the database. This works great, except when there are no invoices already in the database. Then I get a System.ArgumentException: The value "" is not of type "System.Int32" and cannot be used in this generic collection. Changing to FutureValue<int?>() didn't solve the problem. Is there a way to tell NHibernate to map the empty string to null? Or is there a better way to accomplish my goal altogether?
The stack trace of the exception (at least the relevant part) is
NHibernate.HibernateException: Error executing multi criteria : [SELECT max(this_.[InvoiceNumber]) as y0_ FROM dbo.[tblInvoice] this_;
SELECT this_.ID as ID647_0_, this_.[NHVersion] as column2_647_0_, this_.[Description] as column3_647_0_, this_.[DiscountPercent] as column4_647_0_, this_.[DiscountDateDays] as column5_647_0_, this_.[PaymentDueDateDays] as column6_647_0_, this_.[Notes] as column7_647_0_, this_.[DiscountDateMonths] as column8_647_0_, this_.[PaymentDueDateMonths] as column9_647_0_, this_.[DiscountDatePeriod] as column10_647_0_, this_.[DiscountDateMonthlyDay] as column11_647_0_, this_.[DiscountDateMonthlyDayDay] as column12_647_0_, this_.[DiscountDateMonthlyDayMonth] as column13_647_0_, this_.[DiscountDateMonthlyThe] as column14_647_0_, this_.[DiscountDateMonthlyTheDOW] as column15_647_0_, this_.[DiscountDateMonthlyTheMonth] as column16_647_0_, this_.[DiscountDateMonthlyTheWeek] as column17_647_0_, this_.[PaymentDueDatePeriod] as column18_647_0_, this_.[PaymentDueDateMonthlyDay] as column19_647_0_, this_.[PaymentDueDateMonthlyDayDay] as column20_647_0_, this_.[PaymentDueDateMonthlyDayMonth] as column21_647_0_, this_.[PaymentDueDateMonthlyThe] as column22_647_0_, this_.[PaymentDueDateMonthlyTheDOW] as column23_647_0_, this_.[PaymentDueDateMonthlyTheMonth] as column24_647_0_, this_.[PaymentDueDateMonthlyTheWeek] as column25_647_0_ FROM dbo.[tblTermsCode] this_;
] ---> System.ArgumentException: The value "" is not of type "System.Int32" and cannot be used in this generic collection.
Parameter name: value
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
at System.Collections.Generic.List`1.VerifyValueType(Object value)
at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
at NHibernate.Impl.MultiCriteriaImpl.GetResultsFromDatabase(IList results)
use....UniqueValue<int?>();
NH uses a non-generic IList in their MultiCriteria implementation. Which is used for FutureValue batching. see here for why List<int?> fails to add null through it's IList implementation. I'm surprised I've never run into this before. Avoid using nullable value types with Future or MultiCriteria.
With the QueryOver API:
Session.QueryOver<T>()
.Select(Projections.Max<Statistic>(s => s.PeriodStart))
.SingleOrDefault<object>();
if nothing is returned its null, otherwise cast the result as numeric