These are chat archives for hibernate/hibernate-orm

15th
Feb 2018
Raj
@rajjaiswalsaumya
Feb 15 05:08
Hi all. I have a table which was being used for id generation using jdbc. I have introduced hibernate now. Can someone tell how to write an IdGenerator where there is only one column which is also primary key. I saw GenericGenrator but it seems to use two columns. I have only one column named NEXT_VAL
Raj
@rajjaiswalsaumya
Feb 15 05:36
Can someone please tell how to write one custom generator or is there any generator of such type existing.
Raj
@rajjaiswalsaumya
Feb 15 06:37
Can some one please help ?
:(
Bgvć
@istiti
Feb 15 07:12
@sebersole im using Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) Oct 28 2016 18:17:30 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 6.3 <X64> (Build 16299: ) can you please explain more, how can I solve this issue ? I think it's not hibernate issue, it seems it is really mssql making randomly slow same request. And when I say slow it's until 5-10seconds while mostly they takes <1second , can this article be related to what you say?
Bgvć
@istiti
Feb 15 08:49
@sebersole in sql server i filter request more than 1sec and play with website , 15 times is fast and one time I get this :
image.png
if someone can explain whats going on
Giovanni Lovato
@heruan
Feb 15 10:29
I'm having problems with embedded fields, i.e. when an embedded field changes the value is not updated to the DB.
It seems like dirty-checking does not detect the change, but the embeddable instance is a fresh one , e.g. entity.setFoo(new Foo("foo")) where Foo is @Embeddable (and @Embedded on entity field) and has equals/hashCode based on the "foo" string (which is different from the one set before).
Giovanni Lovato
@heruan
Feb 15 11:13
Interesting fact: the embedded gets saved to the DB if other fields are updated too.
Steve Ebersole
@sebersole
Feb 15 15:00
@rajjaiswalsaumya our sequence generator can also consume such a table
you'd have to configure it to use table using the generator's force_table_use setting
just be aware that we stopped supporting such table-based generation because it is consistently shown as a huge perf concern
Steve Ebersole
@sebersole
Feb 15 15:05
if you really want to use that approach then I would highly suggest using one of the "pooled optimizers" with the generator - aka to "reserve" a number of id values at once
@istiti the article may be related... its hard to say without having access to your database. WRT your png, again its hard to say without context
@heruan are you using the new feature of handling empty and null embeddables as equivalent?
@heruan specifically : hibernate.create_empty_composites.enabled
Giovanni Lovato
@heruan
Feb 15 15:13
@sebersole No, but I've tested it a bit more and my example before isn't right: I tried to simplify to be clear, but actually if a String field in the embeddable changes the update is triggered. Problem is when only a Blob field changes: no update triggered.
The blob is created with the LOB helper, and if I test the old blob with the new one they have differente hashCode() and equals of them returns false.
Steve Ebersole
@sebersole
Feb 15 15:15
i think Blobs are only checked by reference, i may be wrong about that
Giovanni Lovato
@heruan
Feb 15 15:15
But still, not update. If I change another field on the emebeddable, e.g. a string, then both the string and the blob are updated to the DB.
Steve Ebersole
@sebersole
Feb 15 15:16
i'd have to look
but I'm in the middle of stuff
look at the BlobType class to see
Giovanni Lovato
@heruan
Feb 15 15:18
Hm what should I see there? There's a getReplacement method, is the one which chooses if the blob is the same as the original?
Steve Ebersole
@sebersole
Feb 15 15:29
no thats used for merge
Bgvć
@istiti
Feb 15 15:29
@sebersole ok it can only be my sql server config if you guys have not this problem
Steve Ebersole
@sebersole
Feb 15 15:29


    @Override
    public boolean areEqual(Blob one, Blob another) {
        return one == another;
    }
Bgvć
@istiti
Feb 15 15:30
How can i share something to understand my issue
Steve Ebersole
@sebersole
Feb 15 15:30
thats from org.hibernate.type.descriptor.java.BlobTypeDescriptor#areEqual
so its just doing reference checking
Steve Ebersole
@sebersole
Feb 15 15:35
@heruan the easiest thing for you for now is probably to register a custom JavaTypeDescriptor for blobs that does a deep check
which unfortunately means (1) keeping around the original state and (2) checking them byte-by-byte
but really thats the only way to know if a lob changed internally
Giovanni Lovato
@heruan
Feb 15 15:38
Then why if I change another property of the embeddable, the blob gets actually updated?
Steve Ebersole
@sebersole
Feb 15 15:38
becuase once Hibernate sees that something has changed it updates all of the state (unless you use DynamicUpdate)
@istiti that's something you are going to have to track down on your own. this is why dbas are important
people think "oh, i'm just going to throw a db server on this machine over-there and then forget about it"
does not work that way
they need tlc
Giovanni Lovato
@heruan
Feb 15 15:41
Hm wait though, I am generating a new Blob so the reference checking should fail :confused:
Steve Ebersole
@sebersole
Feb 15 15:41
anyway, there are lots of "dba" sites out there (like AskTom for Oracle e.g.). thats a better place for help for this
Bgvć
@istiti
Feb 15 15:42
its relativ... i know its sql server taking this random time not tellin its hibernate
Giovanni Lovato
@heruan
Feb 15 15:42
(Didn't know about @DynamicUpdate, seems like a huge performance boost especially with blobs involved!)
Steve Ebersole
@sebersole
Feb 15 15:43
its not always (usually actualy)
because it means new statement needs to be built/prepared for every update
play with it and see, but regardless that won't help the problem you are askng about
Giovanni Lovato
@heruan
Feb 15 15:45
Of course, but if I have a huge blob field which isn't changed and a string field which has, that would permit to update just the string and not the blob.
Steve Ebersole
@sebersole
Feb 15 15:45
sure
but again, it means the following steps every time an update is done:
Giovanni Lovato
@heruan
Feb 15 15:45
I'll try it! But, yes, it doesn't solve my problem. Actually, it kills the workaround of changing other properties!
Steve Ebersole
@sebersole
Feb 15 15:45
1) generate SQL string
2) prepare it into PreparedStatement
3) ...
Giovanni Lovato
@heruan
Feb 15 15:46
4) profit!
Steve Ebersole
@sebersole
Feb 15 15:46
:)
no, the point is that there is a trade-off perf-wise
you need to decide where that fulcrum is
Giovanni Lovato
@heruan
Feb 15 15:46
Got it, thank you for the clarification!
Still, can't understand why Hibernate doesn't catch the blob change if it compares instances and the instance is actually a new one.
Steve Ebersole
@sebersole
Feb 15 15:47
anyway, back to your problem... you'd have to step through it and see. set a break point at that spot I mentioned
Giovanni Lovato
@heruan
Feb 15 15:47
Sure, I'll do it.
Thanks!
Steve Ebersole
@sebersole
Feb 15 15:49
sure, let us know how it goes
@heruan i should have asked.. which version is this?
Giovanni Lovato
@heruan
Feb 15 15:50
5.2.12
Steve Ebersole
@sebersole
Feb 15 15:51
k