In-memory database returning identical objects in different transactions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

In-memory database returning identical objects in different transactions

Jeroen van der Vegt-3
Hi all,


I am using HSQLDB 2.2.5 with an in-memory database as a replacement for
a MySQL database for fast unit-testing. When I use MySQL to retrieve an
object with the same databsae-identiefier in two database transactions,
I get two distinct java objects containing identical values. If I use an
in-process HSQL-server with an in-memory database, I get identical java
objects. This is not what I'd expect and causes an error in my software.

I tried connecting to the database through a non-localhost URL, but that
still results in identical objects (surprisingly).

I also tried to create a work-around using an Hibernate interceptor (I
use Hibernate as a O/R-mapper), but interceptors aren't used for
org.hibernate.Query.list().


For now I resort to copying (serializing and deserializing) objects if
they are the same (simply compare with '=='), but that doesn't seem
desirable in client code, I'd say that's what the server should do.


Does somebody have any pointers on what I'm doing or expecting incorrectly?



Kind regards,

Jeroen van der Vegt


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
Reply | Threaded
Open this post in threaded view
|

Re: In-memory database returning identical objects in different transactions

Fred Toussi-2
You insert a value into the database, then retrieve it. The database
returns either the same object or an object that is equal to the object
you inserted. You shouldn't expect always to get identical objects or
non-identical objects, only equal objects.

JVM's use caches for certain objects. A future version of the MySQL
driver may also use an object cache and return identical values.

You'd better rewrite your software for its long term maintenance.


Fred

On Mon, Mar 19, 2012, at 15:34, Jeroen van der Vegt wrote:

> Hi all,
>
>
> I am using HSQLDB 2.2.5 with an in-memory database as a replacement
> for a MySQL database for fast unit-testing. When I use MySQL to
> retrieve an object with the same databsae-identiefier in two database
> transactions, I get two distinct java objects containing identical
> values. If I use an in-process HSQL-server with an in-memory database,
> I get identical java objects. This is not what I'd expect and causes
> an error in my software.
>
> I tried connecting to the database through a non-localhost URL, but
> that still results in identical objects (surprisingly).
>
> I also tried to create a work-around using an Hibernate interceptor (I
> use Hibernate as a O/R-mapper), but interceptors aren't used for
> org.hibernate.Query.list().
>
>
> For now I resort to copying (serializing and deserializing) objects if
> they are the same (simply compare with '=='), but that doesn't seem
> desirable in client code, I'd say that's what the server should do.
>
>
> Does somebody have any pointers on what I'm doing or expecting
> incorrectly?
>
>
>
> Kind regards,
>
> Jeroen van der Vegt
>
>
> ----------------------------------------------------------------------
> --------
> This SF email is sponsosred by: Try Windows Azure free for 90 days
> Click Here http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> Hsqldb-user mailing list [hidden email]
> https://lists.sourceforge.net/lists/listinfo/hsqldb-user
>

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user