1

I hope this message finds you well. I am an engineer based in Japan and I am currently working on a project involving Apache Ignite and Hibernate

I am having trouble mapping java.sql.Types.TIMESTAMP on the DB side to java.util.Date on the Java side in Apache Ignite. Here's the relevant Ignite

configuration:

<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
    <constructor-arg>
        <util:constant static-field="java.sql.Types.TIMESTAMP"/>
    </constructor-arg>
    <constructor-arg value="create_date"/>
    <constructor-arg value="java.util.Date"/>
    <constructor-arg value="createDate"/>
</bean>

But when I run the application, I am facing the following deserialization exception:

Failed to deserialize object [typeName=jp.xxxx.xxx.xxx.xxx.xxx.bean.PlayerXXXXBean]: 
class org.apache.ignite.binary.BinaryObjectException: Failed to read field [name=createDate]
...
Caused by: class org.apache.ignite.binary.BinaryObjectException: 
Unexpected field type [pos=49, expected=Date, actual=-2]

It appears that Ignite is having trouble interpreting the TIMESTAMP field as a Date object.

Has anyone encountered this issue before, and if so, how did you resolve it?

Additionally, I have over 400 Java classes, all of which are automatically generated by Hibernate. Because of this, it's not feasible for me to change the java.util.Date on the Java side, nor is it realistic to add a custom marshaller to each Java class.

Therefore, I am looking for a way to modify the marshaller in Ignite itself to fundamentally handle the mapping from java.sql.Types.TIMESTAMP to java.util.Date.

Any suggestions on how I could approach this would be greatly appreciated.

・chatGpt  → ignite not support java.sql.Types.TIMESTAMP to java.util.Date  → https://ignite.apache.org/docs/latest/sql-reference/data-types

Thx all ,I read comments

thx all Indeed, this issue arises from a redevelopment of a product that's over 10 years old, where I'm attempting to provide scalability using Apache Ignite as the only architect.

The problem lies in the fact that the database side uses Timestamp while the Entity side uses Date, leading to a loss of milliseconds, which is not a desirable design, but the mapping was inevitable.

As an alternative, I am considering creating a wrapper setter and getter for Timestamp that corresponds to Date, for the Bean which is generated by Hibernate. This setup would update the private Date member through these methods.

Ryo-chan
  • 31
  • 2
  • You probably shouldn't be attempting to do that at all. Rather, map it to `java.time.LocalDateTime` (assuming your column type contains no offset or timezone info) – g00se Jul 24 '23 at 11:11
  • I don't know *Ignite*, but FYI, you are using terrible date-time classes that were years ago supplanted by the modern *java.time* classes defined in JSR 310. Search to learn more from the many existing Questions and Answers. – Basil Bourque Jul 25 '23 at 01:01
  • thx all, I agree – Ryo-chan Jul 25 '23 at 03:42
  • I guess you need to use https://ignite.apache.org/docs/latest/sql-reference/data-types#timestamp that is mapped to java.sql.Timestamp, for java.sql.Date you need to use https://ignite.apache.org/docs/latest/sql-reference/data-types#date – Andrei Aleksandrov Jul 28 '23 at 06:31

0 Answers0