<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 
        <base href="https://hibernate.atlassian.net"> 
        <title>Message Title</title> 
    </head> 
    <body class="jira" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429"> 
        <table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0" bgcolor="#f5f5f5"> 
            <!-- header here --> 
            <tbody>
                <tr> 
                    <td id="header-pattern-container" style="padding: 0; border-collapse: collapse; padding: 10px 20px"> 
                        <table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="header-avatar-image-container" valign="top" style="padding: 0; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px" width="32"> <img id="header-avatar-image" class="image_fix" src="cid:jira-generated-image-avatar-f5ec8925-40e1-4dd8-9507-533a0fd3b21d" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top"> </td> 
                                    <td id="header-text-container" valign="middle" style="padding: 0; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="chammer" id="email_chammer" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=chammer" style="color:#6c797f;; color: #3b73af; text-decoration: none">Carsten Hammer</a> <strong>updated</strong> an issue </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="email-content-container" style="padding: 0; border-collapse: collapse; padding: 0 20px"> 
                        <table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; border-spacing: 0; border-collapse: separate"> 
                            <tbody>
                                <tr> 
                                    <!-- there needs to be content in the cell for it to render in some clients --> 
                                    <td class="email-content-rounded-top mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 15px; background-color: #ffffff; border-left: 1px solid #cccccc; border-top: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly" height="10" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> 
                                        <table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="page-title-pattern-first-line " style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; padding-top: 10px"> <a href="https://hibernate.atlassian.net/browse/HHH" style="color: #3b73af; text-decoration: none">Hibernate ORM</a> / <a href="https://hibernate.atlassian.net/browse/HHH-11098" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-38bb27e2-6602-4b6c-ad16-6f8d6523b9aa" height="16" width="16" border="0" align="absmiddle" alt="Improvement" style="vertical-align: text-bottom"></a> <a href="https://hibernate.atlassian.net/browse/HHH-11098" style="color: #3b73af; text-decoration: none">HHH-11098</a> </td> 
                                                </tr> 
                                                <tr> 
                                                    <td style="vertical-align: top;; padding: 0; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-11098" style="color: #3b73af; text-decoration: none">Attributeconverter converttoEntityAttribute and convertToDatabaseColumn code is called within a query.list() call -&gt; slow</a> </span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  wrapper-special-margin" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 10px; padding-bottom: 5px" bgcolor="#ffffff"> 
                                        <table class="keyvalue-table" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Change By:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <a class="user-hover" rel="chammer" id="email_chammer" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=chammer" style="color:#6c797f;; color: #3b73af; text-decoration: none">Carsten Hammer</a> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  issue-description-container" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 5px; padding-bottom: 10px" bgcolor="#ffffff"> 
                                        <table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0; border-collapse: collapse; padding: 0 0 10px"> <span class="diffcontext">I am not sure if this not really is a bug.<br>StandardCacheEntryImpl calls TypeHelper.disassemble which causes the freshly converted (converttoEntityAttribute) attribute again to be converted the other way round (convertToDatabaseColumn). If this conversion is slow this is a problem. This is processed within one query.list() call. It would be nice if there was a way to suppress this forward and backward conversion that slows processing down a lot. <br><br>It ends up to be in AttributeConverterMutabilityPlan.deepCopyNotNull(). There I can see the convertToDatabaseColumn() method to be called immediately followed by a call to converttoEntityAttribute(). If I somehow could switch this off my application would be several orders of magnitude faster. What is this for?:<br><br>public class AttributeConverterMutabilityPlanImpl&lt;T&gt; extends MutableMutabilityPlan&lt;T&gt; {<br> private final AttributeConverter attributeConverter;<br><br> public AttributeConverterMutabilityPlanImpl(AttributeConverter attributeConverter) {<br>&nbsp;&nbsp;this.attributeConverter = attributeConverter;<br> }<br><br> @Override<br> @SuppressWarnings("unchecked")<br> protected T deepCopyNotNull(T value) {<br>&nbsp;&nbsp;return (T) attributeConverter.convertToEntityAttribute( attributeConverter.convertToDatabaseColumn( value ) );<br> }<br>}<br><br>Here is the relevant part of the stacktrace:<br><br>AttributeConverterMutabilityPlanImpl&lt;T&gt;.deepCopyNotNull(T) line: 29 <br>AttributeConverterMutabilityPlanImpl&lt;T&gt;(MutableMutabilityPlan&lt;T&gt;).deepCopy(T) line: 35 <br>AttributeConverterMutabilityPlanImpl&lt;T&gt;(MutableMutabilityPlan&lt;T&gt;).disassemble(T) line: 24 <br>AttributeConverterTypeAdapter&lt;T&gt;(AbstractStandardBasicType&lt;T&gt;).disassemble(Object, SessionImplementor, Object) line: 284 <br>TypeHelper.disassemble(Object[], Type[], boolean[], SessionImplementor, Object) line: 129 <br>StandardCacheEntryImpl.&lt;init&gt;(Object[], EntityPersister, Object, SessionImplementor, Object) line: 55 <br>AbstractEntityPersister$StandardCacheEntryHelper.buildCacheEntry(Object, Object[], Object, SessionImplementor) line: 5216 <br>SingleTableEntityPersister(AbstractEntityPersister).buildCacheEntry(Object, Object[], Object, SessionImplementor) line: 4227 <br>TwoPhaseLoad.doInitializeEntity(Object, EntityEntry, boolean, SessionImplementor, PreLoadEvent) line: 182 <br>TwoPhaseLoad.initializeEntity(Object, boolean, SessionImplementor, PreLoadEvent) line: 125 <br>QueryLoader(Loader).initializeEntitiesAndCollections(List, Object, SessionImplementor, boolean, List&lt;AfterLoadAction&gt;) line: 1139 <br>QueryLoader(Loader).processResultSet(ResultSet, QueryParameters, SessionImplementor, boolean, ResultTransformer, int, List&lt;AfterLoadAction&gt;) line: 998 <br>QueryLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean, ResultTransformer) line: 936 <br>QueryLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean, ResultTransformer) line: 342 <br>QueryLoader(Loader).doList(SessionImplementor, QueryParameters, ResultTransformer) line: 2622 <br>QueryLoader(Loader).listUsingQueryCache(SessionImplementor, QueryParameters, Set&lt;Serializable&gt;, Type[]) line: 2464 <br>QueryLoader(Loader).list(SessionImplementor, QueryParameters, Set&lt;Serializable&gt;, Type[]) line: 2426 <br>QueryLoader.list(SessionImplementor, QueryParameters) line: 501 <br>QueryTranslatorImpl.list(SessionImplementor, QueryParameters) line: 371 <br>HQLQueryPlan.performList(QueryParameters, SessionImplementor) line: 216 <br>SessionImpl.list(String, QueryParameters) line: 1339 <br>QueryImpl.list() line: 87 <br><br></span> <span class="diffaddedchars" style="background-color:#ddfade;"><br>Here is a test that shows the issue in the behavior.:<br><br>package org.hibernate.test.converter;<br><br>import java.beans.XMLDecoder;<br>import java.beans.XMLEncoder;<br>import java.io.ByteArrayInputStream;<br>import java.io.ByteArrayOutputStream;<br>import java.io.IOException;<br>import java.util.HashMap;<br>import java.util.List;<br>import java.util.Map;<br><br>import javax.persistence.AttributeConverter;<br>import javax.persistence.Convert;<br>import javax.persistence.Converter;<br>import javax.persistence.Entity;<br>import javax.persistence.Id;<br>import javax.persistence.Lob;<br>import javax.persistence.Table;<br><br>import org.hibernate.Session;<br>import org.hibernate.cfg.Configuration;<br>import org.hibernate.cfg.Environment;<br>import org.hibernate.query.Query;<br>import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;<br>import org.junit.Test;<br><br>import static org.junit.Assert.assertEquals;<br><br>/**<br> * Test to check the number of attributeconverter calls on a simple save and list<br> *<br> * @author Carsten Hammer<br> */<br>public class AttributeConverterLobTest extends BaseCoreFunctionalTestCase {<br> @Override<br> protected Class&lt;?&gt;[] getAnnotatedClasses() {<br>&nbsp;&nbsp;return new Class[] { EntityImpl.class };<br> }<br> <br> @Override<br> public void configure(Configuration cfg) {<br>&nbsp;&nbsp;super.configure( cfg );<br>&nbsp;&nbsp;cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );<br>&nbsp;&nbsp;cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );<br> }<br><br> @Test<br> public void testMappingAttributeWithLobAndAttributeConverter() {<br>&nbsp;&nbsp;Session session = openSession();<br>&nbsp;&nbsp;session.beginTransaction();<br>&nbsp;&nbsp;EntityImpl object = new EntityImpl();<br>&nbsp;&nbsp;object.status=new HashMap&lt;&gt;();<br>&nbsp;&nbsp;object.status.put( "asdf", Integer.valueOf( 6 ) );<br>&nbsp;&nbsp;object.status.put( "key", "table" );<br>&nbsp;&nbsp;object.id=1;<br>&nbsp;&nbsp;session.save( object );<br>&nbsp;&nbsp;session.getTransaction().commit();<br>&nbsp;&nbsp;session.close();<br>&nbsp;&nbsp;/**<br>&nbsp;&nbsp;&nbsp;* What? Why the hell 2 and not 1?<br>&nbsp;&nbsp;&nbsp;*/<br>&nbsp;&nbsp;assertEquals(2,ConverterImpl.todatabasecounter);<br>&nbsp;&nbsp;/**<br>&nbsp;&nbsp;&nbsp;* Why a from database conversion at all?<br>&nbsp;&nbsp;&nbsp;*/<br>&nbsp;&nbsp;assertEquals(1,ConverterImpl.fromdatabasecounter);<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;session = openSession();<br>&nbsp;&nbsp;session.beginTransaction();<br>&nbsp;&nbsp;Query&lt;EntityImpl&gt; createQuery = session.createQuery( "select e from EntityImpl e", EntityImpl.class );<br>&nbsp;&nbsp;List&lt;EntityImpl&gt; resultList = createQuery.getResultList();<br>&nbsp;&nbsp;assertEquals(1,resultList.size());<br>&nbsp;&nbsp;session.getTransaction().commit();<br>&nbsp;&nbsp;session.close();<br>&nbsp;&nbsp;/**<br>&nbsp;&nbsp;&nbsp;* Why again a to database conversion? These conversions are very expensive and should only be done if really needed..<br>&nbsp;&nbsp;&nbsp;*/<br>&nbsp;&nbsp;assertEquals(3,ConverterImpl.todatabasecounter);<br>&nbsp;&nbsp;assertEquals(3,ConverterImpl.fromdatabasecounter);<br>&nbsp;&nbsp;assertEquals("table",resultList.get(0 ).status.get( "key" ));<br>&nbsp;&nbsp;assertEquals(3,ConverterImpl.fromdatabasecounter);<br> }<br><br> @Converter<br> public static class ConverterImpl implements AttributeConverter&lt;Map, byte[]&gt; {<br>&nbsp;&nbsp;public static int todatabasecounter=0;<br>&nbsp;&nbsp;public static int fromdatabasecounter=0;<br>&nbsp;&nbsp;@Override<br>&nbsp;&nbsp;public byte[] convertToDatabaseColumn(Map map) {<br>&nbsp;&nbsp;&nbsp;todatabasecounter++;<br>&nbsp;&nbsp;&nbsp;ByteArrayOutputStream out=new ByteArrayOutputStream();<br>&nbsp;&nbsp;&nbsp;try(XMLEncoder encoder=new XMLEncoder(out)){<br>&nbsp;&nbsp;&nbsp;&nbsp;encoder.writeObject( map );<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;return out.toByteArray();<br>&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;@Override<br>&nbsp;&nbsp;public Map convertToEntityAttribute(byte[] dbData) {<br>&nbsp;&nbsp;&nbsp;fromdatabasecounter++;<br>&nbsp;&nbsp;&nbsp;try(ByteArrayInputStream in=new ByteArrayInputStream(dbData)){<br>&nbsp;&nbsp;&nbsp;&nbsp;XMLDecoder decoder=new XMLDecoder(in);<br>&nbsp;&nbsp;&nbsp;&nbsp;return (Map) decoder.readObject();<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;catch (IOException e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return null;<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;}<br> }<br><br> @Entity(name = "EntityImpl")<br> @Table( name = "EntityImpl" )<br> public static class EntityImpl {<br>&nbsp;&nbsp;@Id<br>&nbsp;&nbsp;private Integer id;<br><br>&nbsp;&nbsp;@Lob<br>&nbsp;&nbsp;@Convert(converter = ConverterImpl.class)<br>&nbsp;&nbsp;private Map status;<br> }<br>}<br><br></span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> 
                                        <table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="actions-pattern-container" valign="middle" style="padding: 0; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0"> 
                                                        <table align="left" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                                            <tbody>
                                                                <tr> 
                                                                    <td class="actions-pattern-action-icon-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-11098#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-d7d05d32-2516-4662-aaca-abd30f49f297" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle"> </a> </td> 
                                                                    <td class="actions-pattern-action-text-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://hibernate.atlassian.net/browse/HHH-11098#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a> </td> 
                                                                </tr> 
                                                            </tbody>
                                                        </table> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <!-- there needs to be content in the cell for it to render in some clients --> 
                                <tr> 
                                    <td class="email-content-rounded-bottom mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #ffffff; border-top: 0; border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly" height="5" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="footer-pattern" style="padding: 0; border-collapse: collapse; padding: 12px 20px"> 
                        <table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> This message was sent by Atlassian JIRA <span id="footer-build-information">(v1000.319.1#100012-<span title="913341feb8e17597160ad65b0697fe6d43c909cc" data-commit-id="913341feb8e17597160ad65b0697fe6d43c909cc}">sha1:913341f</span>)</span> </td> 
                                    <td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0; border-collapse: collapse; padding-left: 20px; vertical-align: top"> 
                                        <table style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="footer-pattern-logo-desktop-padding" style="padding: 0; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-e3ef2900-2096-42d4-97b4-b0fca5025ab8" alt="Atlassian logo" title="Atlassian logo" width="169" height="36" class="image_fix"> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
            </tbody>
        </table>   
    </body>
</html>