JCache with Redisson, how serialization / deserialization works? - java

I am using JCache with Redisson, it's not clear to me how serialization/deserialization works while using the cache.
When I setup the Cache via configuration I didn't setup anything about this. Is this done transparently?
The objects I am storing in cache are lists, objects from java.time for example, but I require all of objects of the classes I am storing in the cache implement Serializable, is this enough?
Looking at the data on redis it seems it is storing data serialized via java default serialization, am I wrong?
Can I control this behaviour? or it's better to leave it as it is ?
Thanks for help

As my comment, from redisson documentation Redisson use Kryo as default data serializer/deserializer.

Related

Does Spring Data Redis support Externalizable?

I am new to Redis things.
I have some Object which is Externalizable.
But Spring Data Redis is not working with these Objects.
Does Spring Data Redis need Serializable strictly or there is some way to work with Externalizable as well?
Spring Data Redis supports different serialization strategies to represent your objects in binary form so it can be stored in Redis.
One of the serialization formats is using Java's serialization mechanism via ObjectOutputStream. There are no Spring Data specifics when using Java serialization.

How Hibernate uses(if it does) serialization

Does hibernate internally uses Serialization for persisting POJO classes? If yes, How does it use it in persisting data? If No, then how does it persist data to DB?
Hibernate persists data to the database using SQL. Java serialization is not used at all. (SQL) databases are language-agnostic. As such, they cannot depend on language-specific technology such as Java serialization.
Serialization is only relevant when you need to send a POJO over the wire to other servers running Java. For example, if you have some sort of cache of POJOs that spans multiple machines, you could use serialization to send copies of the POJO over the wire.
See https://stackoverflow.com/a/2726387/14731 for a related discussion.

Persisting Protobuf messages to Database

What is the right way to persist data defined using protobuf3. I am using golang and Java, both place with support of ORMs. In java with Hibernate and golang with gorm. Both place i need to convert the Generated code to corresponding Entity model. I feel that is more pain full to maintain same object structure in order to be understandable by ORM. Is there any Database which i can use along with protobuf objects as is. Or i can define the relations between objects in the protobuf itself.
Any helps really appreciated.
There is a not-straightforward solution to this problem.
Protobuf 3 standardises JSON mapping for the messages. Once you serialise your message to JSON, you have multiple options for storing it in a database.
The following (and many more) databases can store JSON data:
MariaDB
PostgreSQL
MongoDB
Your ORM is dealing with objects, by definition. It should not know or care about serialization on the network. I'd suggest deserializing the protobuf message into objects that your ORM is used to and letting it persist them. There's no good reason to couple your persistence tier to the network protocol.
It might make sense to store the protobuf serialization directly if you get rid of JPA and go with a document based solution.
You have to decide how much value JPA is providing for you.
Although this question is quite old, things have happened since then and the FoundationDB Record Layer, released by Apple in 2018, stores Protocol Buffer natively.
In Go, I don't know about gorm, but it seems that with Ent (a competing ORM) Protobufs can be deserialized into exactly the same objects which are used for DB tables/relations. Ent's official tutorial for that.
The caveat is that you specify your Protobuf with Ent's Golang structures, not via the standard proto3 language.

Using CacheBuilder and redis together

Guava CacheBuilder only uses a single JVM. I want to use the CacheBuilder interface to load data from redis and redis in turn loads the data from MySQL.
How do I solve it? Is it even possible?
Why not try Spring Cache framework?It did good wrapper around Redis.

Using default Java Serialization for Externalizable classes with XStream

I am using XStream as part of my application for serializing objects. For one of the use cases, I have to serialize some of the objects implementing Externalizable interface. For my use case I would like to serialize them using native Java serialization.
I found a link on the internet, http://old.nabble.com/How-to-remove-Externalizable-Converter-td22747484.html, which helped me address this issue and started using Reflection Converter for Externalizable objects.
When testing the application, I am seeing that the application is spending lot of time (10's of seconds) in converter code during highly concurrent access. I can see that the problem is in the buildMap method of FieldDictionary.
I was wondering if there is a better way to address my original issue? Is the performance for Reflection Converter expected to be bad when having highly concurrent environment?
To give some additional context on the environment. It is a web application and the serialization is happening during the request processing and application can have 100's of concurrent threads.
I really appreciate any help/advice regarding this.
This is technically not an answer.. but I hope it helps anyways.
While creating a Java Swing based desktop app that was used for Bio-molecular research modeling, we were serializing very complicated and interconnected object graphs to disk for performance reasons.
Even after working our way through Externalization and Serializable related issues, we had to abandon the whole approach and start fresh, because Java serialization is very sensitive to object structure / name etc. Which means innocent refactoring of the model was leading to major crashes in production, when users tried to load old serialized models.
Eventually we created a data store friendly object structure (No strong inter-references to other nodes in the graph), and serialized this structure. This was much simpler, less error prone and much faster than serializing and deserializing the original graph. This also meant that we could refactor / modify our domain graph objects at will, as long as the Adapters (components that converted Domain objects to DataStore objects) was kept updated properly.

Categories

Resources