I have a problem with a solr Date format. In a jar file the following row generates a conversion error:
**cannot cast 'java.util.ArrayList' to 'java.util.Date'**
Date date = (Date) list.get(0).getFieldValue(fieldName);
The line that generates the error is from mycore-oai-2019.11.jar and MCROAISolrSearcher.java class and as you know I cant change it.
The date column in solr is saved in the following format:
"modified":["2018-08-17T06:10:55Z"]
Debbuging the code in that row I see the following Date format :
I cant understand the error! I am trying for hours to figure it out but nothing. Is the Timezone the problem? Is the mapping of the field a problem? Please any advice/help would safe me!
Thank you in advance!
The field in Solr is a multivalued field - the code expects it to be single valued. A multi valued field returns a list (that's the arraylist you're seeing), while a single valued field returns the field directly (which would be the Date field).
Change your schema (remove multiValued="true" or explicitly set multiValued="false") for the field) and re-index.
By default, in schemaless mode, all fields are multivalued, so that's usually why this appears - you haven't explicitly configured your schema (which you should do in production use).
Related
I am using MS SQL as my DB and I have a DATE column called 'START_DATE' in one of my tables. This is a non mandatory column.
In my java layer I am have mapped this to the LocalDate . When I dont have any value set for START_DATE, then I set it to null or leave it empty.
In both cases I get the error that
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Implicit conversion from data type varbinary to date is not allowed. Use the CONVERT function to run this query.
How do I fix this, please advise?
Are you using 2012 version or newer? The problem is in the way SQL 2012 interprets null values for a datetime time. Insert query from Java should have an explicit convert function to forcefully insert it as datetime to avoid this unexpected error.
Something like:
convert(DATETIME,START_DATE,21)
More info
I had the same issue with SQL Server. I fixed it by changing the insert value from just myValue to
CONVERT(DATE, myValue)
folks!
I'm having a problem using DBUnit:
In my test class, when I call DatabaseOperation.INSERT.execute(connection, dataSet), using a FlatXmlDataSet referencing a table that contains a column of type YEAR(4) - MySQL - I get the following:
(...)
Caused by: org.dbunit.dataset.datatype.TypeCastException: Error casting value for table 'Vehicle' and column 'LaunchYear'
at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:210)
at net.carroramafleet.ws.utils.DbUnitHelper.execute(DbUnitHelper.java:57)
... 33 more
Caused by: org.dbunit.dataset.datatype.TypeCastException: Unable to typecast value <2010> of type <java.lang.String> to DATE
at org.dbunit.dataset.datatype.DateDataType.typeCast(DateDataType.java:110)
at org.dbunit.dataset.datatype.DateDataType.setSqlValue(DateDataType.java:141)
at org.dbunit.database.statement.SimplePreparedStatement.addValue(SimplePreparedStatement.java:73)
at org.dbunit.database.statement.AutomaticPreparedBatchStatement.addValue(AutomaticPreparedBatchStatement.java:63)
at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:200)
... 34 more
Here's my dataset:
<dataset>
<Vehicle
ID="999"
LaunchYear="2010" />
</dataset>
As I have mentioned above, I have a YEAR(4) type column, LaunchYear, in the table Vehicle. And DBUnit can't insert this row because of this information can't be converted correctly.
I've already tried to replace this information using DBUnit's ReplacementDataSet, but I still have problem with TypeCastException. I really can't set a valid YEAR-formatted information.
Could somebody help me?
Thanks,
Jeff
This question is a bit old but I thought I would reply as I just ran into this same issue today.
I believe this is a bug in DbUnit. BTW, I'm using 2.4.9 but did check the release notes for later releases to see if this is mentioned as a bug fix.
The YEAR column is being converted into a java.sql.Date object. The initial bug is that there is no conversion from a simple string "2016" to a java.sql.Date. That leads to the TypeCastException. Changing this field to something like "2016-08-10" gets you past this initial error but leads to a SQLException when MySql attempts to truncate the Date into a integer or short.
The only way I have been able to work around this is to add specific code in the #SetUp or #Before methods to populate the table with initial data.
I have the following code:
conditions.add("mydate = str_to_date('"+date_from_user+"', '%Y-%m-%d')");
the above works fine but since I am taking input from the user and shoving it in my query I'm risking the security of the query. So I wanted to use named template so I changed the code to:
conditions.add("mydate = str_to_date(':mydate', '%Y-%m-%d')");
namedParams.put("mydate", date_from_user);
However, the above code doesn't work and produces the following error message:
<SQLWarning ignored: SQL state 'HY000', error code '1411', message [Incorrect datetime value: ':mydate' for function str_to_date]>
so it seems that namedparameter isn't picking up the value..
Have you tried removing the quotes in ':mydate' and change it as below,
conditions.add("mydate = str_to_date(:mydate, '%Y-%m-%d')");
namedParams.put("mydate", date_from_user);
First check your DB server date format. Then give input in same format. create your date object in the same Object or pass string in same format.
I am integrating with salesforce through java there in Opportunity there is a field named CloseDate .
my code for the same is
opportunitySObject.setField("CloseDate", "2010-01-01");
but i get message='Close Date: value not of required type: 2010-01-01'
statusCode='INVALID_TYPE_ON_FIELD_IN_RECORD'
what i see by quering the database is CloseDate in 2010-01-01 format i.e. yyyy-MM-dd.
Please help.
If this is java code, try passing an actual Date value instead of a string. Your SOAP stack (Axis, CXF, etc.) will serialize the date into the proper wire format.
This advice is really for the Enterprise API. If you're using Partner API, it could be a little different.
Im using Oracle 10g,Hibernate 3,springMVC, jqgrid. I have some Date fields in ORACLE which are mapped as follows
#Temporal(TemporalType.DATE)
#Column(name = "DOC_CREATION_DATE", length = 7,insertable=true,updatable=false)
public Date getDocCreationDate() {
return this.docCreationDate;
}
In my grid I filter date using jqueryCalendar and everything is fine. now I have a new request from the client which is to show the time of documentCreation and they also want to be able to filter by a time range. for example:
find all records created between 6:am and 7:pm, find all records created at 6:am.
I have tried already formatting the date field with
#Temporal(TemporalType.TIMESTAMP)
and that's not what they want
Is there any other approach to this problem, any good ideas how to implement this are very welcome.
the thing is I need to use the same mapped field to query in one column of the Jqgrid for the regular date(12/01/2012 using jqueryCalendar)and add another column for the time part of that same mapped field once that is done I need to query (hibernate criteria) the time column for a range of time
something like this mock:
...
criteria.add(Restrictions.ge("docCreationDate.mappedFieldTimePart",6AM ));
thank you for all the help
The column is of type mapped to a Time, and thus you must compare its value with a Time:
Time sixAM = Time.valueOf("06:00:00");
criteria.add(Restrictions.ge("docCreationDate.mappedFieldTimePart", sixAM));
You can also use a regular date:
Date sixAM = new SimpleDateFormat("HH:mm").parse("06:00");
criteria.add(Restrictions.ge("docCreationDate.mappedFieldTimePart", sixAM));
You must change the #Temporal annotation to use either TemporalType.TIMESTAMP or add another field and annotate it with TemporalType.TIME. Hibernate uses the #Temporal annotation to determine if the field is to be treated like a java.sql.Timestamp or a java.util.Date with the time lopped-off (set to midnight, or 00h 00m 00.0s). This allows developers to use java.util.Date everywhere in their application and never have to worry about the Timestamp class (it's banished from most of our codebase).