Property not lazy loading with runtime bytecode enhancement, hibernate 5.2

repeated from stackoverflow

ok, here’s the exception I get, it’s pretty obvious that the problem is trying to load a BLOB into a distinct query. Manually edited the BLOB out of the query and it was fine.

Caused by: java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent 
datatypes: expected - got BLOB

This is the problematic field, I’ve been trying to make hibernate not fetch as part of the query.
Document

@Lob
@LazyGroup( "lob" )
@Fetch( FetchMode.SELECT )
@Basic( fetch = FetchType.LAZY )
@Column( name = "file_data", nullable = false )
@Type( type = "org.hibernate.type.MaterializedBlobType" )
private byte[] fileData;

here’s the query in the Spring Data Repository

public interface DocumentRepository extends CrudRepository<Document, Long> {

String FIND_DOCUMENTS_WITH_MAPPING = "select distinct assoc.document"
    + " from DocumentAssociation assoc"
    + " where assoc.code.status = 0" // using ordinal to check for active status
    + " order by assoc.document.subsetId asc";

@Query( FIND_DOCUMENTS_WITH_MAPPING )
List<Document> findDocumentsWithMapping();

This is the Entity Manager Configuration

@Configuration
@EnableLoadTimeWeaving
@Import( { JpaConfig.class } )
@DependsOn( "jgroupsBindPortProps" )
@Profile( "!" + Profiles.TEST )
public class JpaOracleConfig implements Loggable {

    @Value( "${hibernate.search.default.indexBase}" )
    private String indexBase;

    private static final Stream<String> PROPERTY_KEYS = Stream.of(
        "hibernate.show_sql",
        "hibernate.format_sql",
        "hibernate.session_factory_name",
        "hibernate.session_factory_name_is_jndi",
        "hibernate.cache.use_second_level_cache",
        "hibernate.cache.use_query_cache",
        "hibernate.cache.inifinispan.statistics",
        "hibernate.cache.infinispan.cfg",
        "hibernate.cache.infinispan.entity.cfg",
        "hibernate.generate_statistics",
        "hibernate.cache.use_structured_entries",
        "hibernate.search.lucene_version",
        "hibernate.search.default.worker.backend",
        "hibernate.search.default.exclusive_index_use",
        "hibernate.search.services.jgroups.clusterName",
        "hibernate.search.services.jgroups.configurationFile",
        "hibernate.search.default.directory_provider",
        "hibernate.search.infinispan.configuration_resourcename",
        "hibernate.search.default.worker.execution",
        "hibernate.search.default.worker.thread_pool.size",
        "hibernate.search.default.indexBase"
    );

    private final Environment env;

    public JpaOracleConfig( final Environment env ) {
        this.env = env;
    }

    private Map<String, String> jpaPropertyMap() {
        // Needed by infinispan
        // Property hibernate.search.default.indexBase could not be replaced as intended!
        System.setProperty( "hibernate.search.default.indexBase", indexBase );

        final Map<String, String> props = PROPERTY_KEYS.collect( Collectors.toMap(
            Function.identity(),
            env::getProperty
        ) );
        props.put( "hibernate.search.default.indexBase", indexBase );
        props.put( "javax.persistence.validation.mode", ValidationMode.NONE.toString() );
        props.put( "hibernate.search.similarity", IgnoreAllSimilarity.class.getName() );
        props.put( "hibernate.cache.region.factory_class", InfinispanRegionFactory.class.getName() );
        props.put( "hibernate.cache.use_second_level_cache", Boolean.TRUE.toString() );
        props.put( "hibernate.id.new_generator_mappings", Boolean.FALSE.toString() );
        props.put( "hibernate.enhancer.enableLazyInitialization", Boolean.TRUE.toString() );
        props.put( "hibernate.enhancer.enableDirtyTracking", Boolean.TRUE.toString() );
        props.put( "hibernate.enhancer.enableExtendedEnhancement", Boolean.TRUE.toString() );
        return props;
    }

    @Primary
    @Profile( "!" + Profiles.TEST )
    @Bean( JpaConfig.EMF )
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
        DataSource dataSource,
        JpaVendorAdapter jpaVendorAdapter,
        LoadTimeWeaver loadTimeWeaver
    ) {
        LocalContainerEntityManagerFactoryBean emf = new DexLocalContainerEntityManagerFactoryBean( env );
        emf.setDataSource( dataSource );
        emf.setPersistenceUnitName( "persistenceUnit" );
        emf.setPackagesToScan( JpaConfig.PACKAGES );
        emf.setJpaVendorAdapter( jpaVendorAdapter );
        emf.setJpaPropertyMap( this.jpaPropertyMap() );
        emf.setLoadTimeWeaver( loadTimeWeaver );
        return emf;
    }
}

I believe that enhanced bytecode is working, as when I added the property it blew up until I added @EnableLoadtimeWeaving and injected the weaver, and this is in the logs.

15:31:54,829 [INFO ] Determined server-specific load-time weaver: org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver [localhost-startStop-1] org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:79) (:)

spring boot deps 2.0.3

  • hibernate 5.2.x
  • spring 5.0.x
  • spring data 2.0.x

here’s the debug output of my configuration

11:37:25,900 [DEBUG] Building session factory                                                              [localhost-startStop-1] org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199) (:)
11:37:25,902 [DEBUG] SessionFactory name : defaultSessionFactory                                           [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:69) (:)
11:37:25,902 [DEBUG] Automatic flush during beforeCompletion(): enabled                                    [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:70) (:)
11:37:25,903 [DEBUG] Automatic session close at end of transaction: disabled                               [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:71) (:)
11:37:25,903 [DEBUG] Statistics: disabled                                                                  [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:73) (:)
11:37:25,903 [DEBUG] Deleted entity synthetic identifier rollback: disabled                                [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:75) (:)
11:37:25,903 [DEBUG] Default entity-mode: pojo                                                             [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:76) (:)
11:37:25,904 [DEBUG] Check Nullability in Core (should be disabled when Bean Validation is on): enabled    [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:77) (:)
11:37:25,904 [DEBUG] Allow initialization of lazy state outside session : disabled                         [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:78) (:)
11:37:25,904 [DEBUG] Using BatchFetchStyle : LEGACY                                                        [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:80) (:)
11:37:25,904 [DEBUG] Default batch fetch size: -1                                                          [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:81) (:)
11:37:25,904 [DEBUG] Maximum outer join fetch depth: null                                                  [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:82) (:)
11:37:25,905 [DEBUG] Default null ordering: NONE                                                           [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:83) (:)
11:37:25,905 [DEBUG] Order SQL updates by primary key: disabled                                            [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:84) (:)
11:37:25,905 [DEBUG] Order SQL inserts for batching: disabled                                              [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:85) (:)
11:37:25,905 [DEBUG] multi-tenancy strategy : NONE                                                         [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:87) (:)
11:37:25,905 [DEBUG] JTA Track by Thread: enabled                                                          [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:89) (:)
11:37:25,906 [DEBUG] Query language substitutions: {}                                                      [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:91) (:)
11:37:25,906 [DEBUG] JPA query language strict compliance: disabled                                        [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:92) (:)
11:37:25,906 [DEBUG] Named query checking : enabled                                                        [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:93) (:)
11:37:25,906 [DEBUG] Second-level cache: enabled                                                           [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:95) (:)
11:37:25,906 [DEBUG] Second-level query cache: disabled                                                    [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:96) (:)
11:37:25,907 [DEBUG] Second-level query cache factory: org.hibernate.cache.internal.StandardQueryCacheFactory@7efcc1f6 [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:97) (:)
11:37:25,907 [DEBUG] Second-level cache region prefix: null                                                [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:98) (:)
11:37:25,907 [DEBUG] Optimize second-level cache for minimal puts: enabled                                 [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:99) (:)
11:37:25,907 [DEBUG] Structured second-level cache entries: enabled                                        [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:100) (:)
11:37:25,907 [DEBUG] Second-level cache direct-reference entries: disabled                                 [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:101) (:)
11:37:25,908 [DEBUG] Automatic eviction of collection cache: disabled                                      [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:102) (:)
11:37:25,908 [DEBUG] JDBC batch size: 15                                                                   [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:104) (:)
11:37:25,908 [DEBUG] JDBC batch updates for versioned data: disabled                                       [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:105) (:)
11:37:25,908 [DEBUG] Scrollable result sets: enabled                                                       [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:106) (:)
11:37:25,908 [DEBUG] Wrap result sets: disabled                                                            [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:107) (:)
11:37:25,909 [DEBUG] JDBC3 getGeneratedKeys(): disabled                                                    [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:108) (:)
11:37:25,909 [DEBUG] JDBC result set fetch size: null                                                      [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:109) (:)
11:37:25,909 [DEBUG] Connection release mode: ON_CLOSE                                                     [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:110) (:)
11:37:25,909 [DEBUG] Generate SQL with comments: disabled                                                  [localhost-startStop-1] org.hibernate.cfg.Settings.<init>(Settings.java:111) (:)
11:37:25,997 [DEBUG] Starting Infinispan region factory                                                    [localhost-startStop-1] org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:444) (:)
11:37:25,999 [DEBUG] No JtaPlatform was specified, checking resolver                                       [localhost-startStop-1] org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator.initiateService(JtaPlatformInitiator.java:42) (:)
11:37:26,000 [DEBUG] No JtaPlatformResolver was specified, using default [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver] [localhost-startStop-1] org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformResolverInitiator.initiateService(JtaPlatformResolverInitiator.java:33) (:)
11:37:26,023 [DEBUG] Could not resolve JtaPlatform, using default [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] [localhost-startStop-1] org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver.resolveJtaPlatform(StandardJtaPlatformResolver.java:110) (:)
11:37:26,026 [DEBUG] Configuration override via property hibernate.cache.infinispan.entity.cfg: entity     [localhost-startStop-1] org.hibernate.cache.infinispan.InfinispanRegionFactory.extractProperty(InfinispanRegionFactory.java:635) (:)
11:37:26,026 [DEBUG] Configuration override via property hibernate.cache.infinispan.cfg: infinispan-l2cache.xml [localhost-startStop-1] org.hibernate.cache.infinispan.InfinispanRegionFactory.extractProperty(InfinispanRegionFactory.java:635) (:)
11:37:26,439 [WARN ] ISPN000383: The eviction max-entries attribute has been deprecated. Please use the size attribute instead [localhost-startStop-1] org.infinispan.configuration.parsing.Parser80.parseEviction(Parser80.java:1719) (:)
11:37:26,440 [DEBUG] Configuration override via property hibernate.cache.infinispan.statistics: null       [localhost-startStop-1] org.hibernate.cache.infinispan.InfinispanRegionFactory.extractProperty(InfinispanRegionFactory.java:635) (:)
11:37:27,178 [INFO ] ISPN000078: Starting JGroups channel ISPN                                             [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.start(JGroupsTransport.java:188) (:)

and the field processing shows this

11:37:22,286 [DEBUG] MetadataSourceProcessor property fileData with lazy=true                           [localhost-startStop-1] org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:175) (:)
11:37:22,286 [DEBUG] Attempting to locate auto-apply AttributeConverter for property [com.myapp.Document:fileData] [localhost-startStop-1] org.hibernate.cfg.AbstractPropertyHolder.resolveAttributeConverterDescriptor(AbstractPropertyHolder.java:95) (:)
11:37:22,286 [DEBUG] building SimpleValue for fileData                                                  [localhost-startStop-1] org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:411) (:)
11:37:22,287 [DEBUG] Building property fileData                                                         [localhost-startStop-1] org.hibernate.cfg.annotations.PropertyBinder.makeProperty(PropertyBinder.java:266) (:)

How can I change my code such that fileData will only be fetched if requested?

1 Like

Try making it a Blob. I don’t see how Hibernate could proxy a byte[]:

@Lob
@Column( name = "file_data", nullable = false )
private Blob fileData;

If you really want it to be a byte[], you indeed need the @Basic( fetch = FetchType.LAZY ) and @LazyGroup( "lob" ), but that will only work if and only if you also use bytecode enhancement.

Otherwise, lazy attributes will always be fetched eagerly.

1 Like

I tried making it a Blob in another iteration, didn’t work any better.

If you really want it to be a byte, you indeed need the @Basic( fetch = FetchType.LAZY ) and @LazyGroup( “lob” ), but that will only work if and only if you also use bytecode enhancement.

I did all that using runtime enhancement and it’s shown here in my code, or is there something I’ve missed?

maybe I’m doing something wrong to enable runtime bytecode enhancement in 5.2. I found this… https://hibernate.atlassian.net/browse/HHH-12602 which says the docs are wrong for how to enable it…

Try will compile bytecode enhancement. Check out this article for an example of how to use the enhance Maven plugin.

we are hoping not to use the maven build tool plugin… because of IDE’s, but if I did do that, how would I get it working for the IDE?

I’ve always used the compile bytecode enhancement and never had any issue with the IDE.

Why do you think it won’t work?

because the IDE (unless configured otherwise, and I’ve only seen that work in Intellij for gradle) has it’s own compiler/settings. So doing things like source/bytecode manipulation have always always required that I make the IDE aware that it needs to do the same transformations. Maybe my assumptions are wrong, I’ll give it a go…

Last time I used Eclipse was in 2005 when I gave a try to Intellij IDEA. Well, I’m still using it and never had any problem with bytecode.

tried adding the plugin to our “model” module, when building with the IDE (and not maven) there is no change in behavior. When building with maven it looks like it’s doing the enhancement but failing to compile our last module, because hibernate is set to be a runtime dep of that module, though I don’t understand why that’s a problem, it calls entities, but it doesn’t have to build any…

cannot access org.hibernate.engine.spi.PersistentAttributeInterceptable
cannot access org.hibernate.engine.spi.SelfDirtinessTracker
...
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.15.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:5.0.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-webmvc:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:4.2.6.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.6.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-web:jar:4.2.6.RELEASE:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.11:compile
[INFO] |  \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |     \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] +- commons-io:commons-io:jar:2.5:compile
[INFO] +- com.google.guava:guava:jar:20.0:compile
[INFO] +- com.mckesson.dex:dex-ui-model:jar:0.0.1-SNAPSHOT:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:2.0.8.RELEASE:compile
[INFO] |  +- com.mckesson.dex:dex-model:jar:0.0.1-SNAPSHOT:compile
[INFO] |  |  \- com.google.gwt:gwt-elemental:jar:2.8.2:compile
[INFO] |  |     \- com.google.gwt:gwt-user:jar:2.8.2:compile
[INFO] |  |        +- com.google.jsinterop:jsinterop-annotations:jar:1.0.2:compile
[INFO] |  |        +- com.google.jsinterop:jsinterop-annotations:jar:sources:1.0.2:compile
[INFO] |  |        \- javax.validation:validation-api:jar:sources:1.0.0.GA:compile
[INFO] |  +- com.vaadin:vaadin-compatibility-server:jar:8.1.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  \- org.hibernate.validator:hibernate-validator:jar:6.0.10.Final:runtime
[INFO] |     \- com.fasterxml:classmate:jar:1.3.4:runtime
[INFO] +- com.mckesson.dex:dex-controller:jar:0.0.1-SNAPSHOT:runtime
[INFO] |  +- org.hibernate:hibernate-core:jar:5.2.17.Final:runtime
[INFO] |  |  +- org.javassist:javassist:jar:3.21.0-GA:runtime
[INFO] |  |  +- antlr:antlr:jar:2.7.7:runtime
[INFO] |  |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.1.Final:runtime
[INFO] |  |  +- org.jboss:jandex:jar:2.0.3.Final:runtime
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:runtime
[INFO] |  \- io.springfox:springfox-swagger2:jar:2.6.1:runtime
[INFO] |     +- io.swagger:swagger-annotations:jar:1.5.10:runtime
[INFO] |     +- io.swagger:swagger-models:jar:1.5.10:runtime
[INFO] |     +- io.springfox:springfox-spi:jar:2.6.1:runtime
[INFO] |     |  \- io.springfox:springfox-core:jar:2.6.1:runtime
[INFO] |     +- io.springfox:springfox-schema:jar:2.6.1:runtime
[INFO] |     +- io.springfox:springfox-swagger-common:jar:2.6.1:runtime
[INFO] |     +- io.springfox:springfox-spring-web:jar:2.6.1:runtime
[INFO] |     +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:runtime
[INFO] |     +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:runtime
[INFO] |     \- org.mapstruct:mapstruct:jar:1.0.0.Final:runtime
[INFO] +- com.mckesson.dex:dex-viewmodel:jar:0.0.1-SNAPSHOT:compile
[INFO] +- com.mckesson.dex:dex-util:jar:0.0.1-SNAPSHOT:compile
[INFO] |  +- org.springframework:spring-expression:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.apache.tika:tika-core:jar:1.16:runtime
[INFO] |  +- com.thoughtworks.xstream:xstream:jar:1.4.10:runtime
[INFO] |  |  +- xmlpull:xmlpull:jar:1.1.3.1:runtime
[INFO] |  |  \- xpp3:xpp3_min:jar:1.1.4c:runtime
[INFO] |  +- org.apache.velocity:velocity:jar:1.7:runtime
[INFO] |  |  \- commons-lang:commons-lang:jar:2.6:runtime
[INFO] |  +- org.apache.poi:poi:jar:3.15:runtime
[INFO] |  |  \- org.apache.commons:commons-collections4:jar:4.1:runtime
[INFO] |  +- org.apache.poi:poi-ooxml:jar:3.15:runtime
[INFO] |  |  +- org.apache.poi:poi-ooxml-schemas:jar:3.15:runtime
[INFO] |  |  |  \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:runtime
[INFO] |  |  |     \- stax:stax-api:jar:1.0.1:runtime
[INFO] |  |  \- com.github.virtuald:curvesapi:jar:1.04:runtime
[INFO] |  +- dom4j:dom4j:jar:1.6.1:runtime
[INFO] |  +- org.apache.pdfbox:pdfbox:jar:2.0.5:runtime
[INFO] |  |  \- org.apache.pdfbox:fontbox:jar:2.0.5:runtime
[INFO] |  \- org.apache.lucene:lucene-analyzers-common:jar:5.5.5:runtime
[INFO] |     \- org.apache.lucene:lucene-core:jar:5.5.5:compile
[INFO] +- com.mckesson.dex:dex-test-util:jar:0.0.1-SNAPSHOT:test
[INFO] +- com.mckesson.dex:dex-ui-widgetset:jar:8.1.3.0-SNAPSHOT:compile
[INFO] |  \- com.vaadin:vaadin-push:jar:8.1.3:compile
[INFO] |     \- com.vaadin.external.atmosphere:atmosphere-runtime:jar:2.4.11.vaadin2:compile
[INFO] |        \- com.vaadin.external.slf4j:vaadin-slf4j-jdk14:jar:1.6.1:compile
[INFO] +- com.mckesson.dex:dex-service-api:jar:0.0.1-SNAPSHOT:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.2.17.Final:runtime
[INFO] |  |  \- net.bytebuddy:byte-buddy:jar:1.7.11:runtime
[INFO] |  +- org.hibernate:hibernate-search-orm:jar:5.7.3.Final:runtime
[INFO] |  +- org.hibernate:hibernate-search-engine:jar:5.7.3.Final:compile
[INFO] |  |  +- org.apache.lucene:lucene-misc:jar:5.5.5:compile
[INFO] |  |  \- org.apache.lucene:lucene-facet:jar:5.5.5:compile
[INFO] |  +- com.mckesson.dex:dex-config:jar:0.0.1-SNAPSHOT:compile
[INFO] |  |  +- com.lmax:disruptor:jar:3.4.2:runtime
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-log4j2:jar:2.0.3.RELEASE:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.10.0:runtime
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-core:jar:2.10.0:runtime
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-jul:jar:2.10.0:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:runtime
[INFO] |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:runtime
[INFO] |  +- com.mckesson.dex:dex-batch:jar:0.0.1-SNAPSHOT:compile
[INFO] |  +- com.mckesson.dex:dex-dal:jar:0.0.1-SNAPSHOT:compile
[INFO] |  |  +- org.codehaus.castor:castor-xml:jar:1.4.1:runtime
[INFO] |  |  |  +- org.codehaus.castor:castor-core:jar:1.4.1:runtime
[INFO] |  |  |  \- javax.inject:javax.inject:jar:1:runtime
[INFO] |  |  +- com.mckesson.dex:dex-dbms:jar:0.0.1-SNAPSHOT:runtime
[INFO] |  |  |  +- xerces:xercesImpl:jar:2.12.0:runtime
[INFO] |  |  |  |  \- xml-apis:xml-apis:jar:1.4.01:runtime
[INFO] |  |  |  +- org.jasypt:jasypt:jar:1.9.0:runtime
[INFO] |  |  |  +- org.jasypt:jasypt-hibernate4:jar:1.9.0:runtime
[INFO] |  |  |  +- org.hibernate:hibernate-c3p0:jar:5.2.17.Final:runtime
[INFO] |  |  |  \- org.liquibase:liquibase-core:jar:3.5.5:runtime
[INFO] |  |  |     \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] |  |  +- org.springframework:spring-tx:jar:5.0.7.RELEASE:compile
[INFO] |  |  \- com.mchange:c3p0:jar:0.9.5.2:runtime
[INFO] |  +- org.springframework:spring-context-support:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-orm:jar:5.0.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-acl:jar:4.2.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-aspects:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:2.0.8.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjrt:jar:1.8.13:compile
[INFO] |  +- org.springframework.batch:spring-batch-core:jar:4.0.1.RELEASE:runtime
[INFO] |  |  +- javax.batch:javax.batch-api:jar:1.0:runtime
[INFO] |  |  +- org.codehaus.jettison:jettison:jar:1.2:runtime
[INFO] |  |  \- org.springframework.batch:spring-batch-infrastructure:jar:4.0.1.RELEASE:runtime
[INFO] |  +- org.springframework:spring-web:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework.integration:spring-integration-core:jar:4.3.16.RELEASE:runtime
[INFO] |  |  +- org.springframework:spring-messaging:jar:5.0.7.RELEASE:runtime
[INFO] |  |  \- org.springframework.retry:spring-retry:jar:1.2.2.RELEASE:runtime
[INFO] |  +- org.springframework.integration:spring-integration-sftp:jar:4.3.16.RELEASE:runtime
[INFO] |  |  +- org.springframework.integration:spring-integration-stream:jar:4.3.16.RELEASE:runtime
[INFO] |  |  \- com.jcraft:jsch:jar:0.1.54:runtime
[INFO] |  +- org.springframework.integration:spring-integration-file:jar:4.3.16.RELEASE:runtime
[INFO] |  +- org.springframework.batch:spring-batch-integration:jar:4.0.1.RELEASE:runtime
[INFO] |  +- org.springframework:spring-oxm:jar:5.0.7.RELEASE:compile
[INFO] |  +- org.springframework.ws:spring-xml:jar:3.0.1.RELEASE:runtime
[INFO] |  +- org.springframework.ws:spring-ws-core:jar:3.0.1.RELEASE:compile
[INFO] |  +- org.quartz-scheduler:quartz:jar:2.3.0:compile
[INFO] |  |  \- com.mchange:mchange-commons-java:jar:0.2.11:compile
[INFO] |  +- org.apache.lucene:lucene-queryparser:jar:5.5.5:runtime
[INFO] |  |  +- org.apache.lucene:lucene-queries:jar:5.5.5:compile
[INFO] |  |  \- org.apache.lucene:lucene-sandbox:jar:5.5.5:runtime
[INFO] |  +- joda-time:joda-time:jar:2.9.9:runtime
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:runtime
[INFO] |  \- com.fasterxml.jackson.module:jackson-module-jsonSchema:jar:2.9.6:compile
[INFO] +- org.jgroups:jgroups:jar:3.6.13.Final:compile
[INFO] +- org.jsoup:jsoup:jar:1.9.2:compile
[INFO] +- org.owasp.esapi:esapi:jar:2.1.0.1:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.6:runtime
[INFO] |  |  \- commons-digester:commons-digester:jar:1.8:runtime
[INFO] |  +- commons-fileupload:commons-fileupload:jar:1.3.1:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.2:runtime
[INFO] |  +- xom:xom:jar:1.2.5:compile
[INFO] |  +- org.beanshell:bsh-core:jar:2.0b4:compile
[INFO] |  \- org.owasp.antisamy:antisamy:jar:1.5.3:compile
[INFO] |     \- net.sourceforge.nekohtml:nekohtml:jar:1.9.22:compile
[INFO] +- com.googlecode.libphonenumber:libphonenumber:jar:8.0.0:compile
[INFO] +- com.vaadin:vaadin-compatibility-client:jar:8.1.3:provided
[INFO] |  +- com.vaadin:vaadin-client:jar:8.1.3:provided
[INFO] |  |  \- com.vaadin:vaadin-shared:jar:8.1.3:compile
[INFO] |  \- com.vaadin:vaadin-compatibility-shared:jar:8.1.3:compile
[INFO] +- com.vaadin:vaadin-compatibility-client-compiled:jar:8.1.3:runtime
[INFO] +- com.vaadin:vaadin-compatibility-themes:jar:8.1.3:compile
[INFO] +- com.vaadin:vaadin-themes:jar:8.1.3:compile
[INFO] +- org.vaadin.addons:extended-token-field:jar:0.3.0:compile
[INFO] +- org.vaadin.addon:jfreechartwrapper:jar:4.0.0:compile
[INFO] |  +- com.vaadin:vaadin-server:jar:8.1.3:compile
[INFO] |  |  +- com.vaadin:vaadin-sass-compiler:jar:0.9.13:compile
[INFO] |  |  |  +- org.w3c.css:sac:jar:1.3:compile
[INFO] |  |  |  \- com.vaadin.external.flute:flute:jar:1.3.0.gg2:compile
[INFO] |  |  \- com.vaadin.external:gentyref:jar:1.2.0.vaadin1:compile
[INFO] |  +- jfree:jfreechart:jar:1.0.13:compile
[INFO] |  +- org.apache.xmlgraphics:batik-svggen:jar:1.9.1:compile
[INFO] |  |  +- org.apache.xmlgraphics:batik-awt-util:jar:1.9.1:compile
[INFO] |  |  |  \- org.apache.xmlgraphics:xmlgraphics-commons:jar:2.2:compile
[INFO] |  |  \- org.apache.xmlgraphics:batik-util:jar:1.9.1:compile
[INFO] |  |     +- org.apache.xmlgraphics:batik-constants:jar:1.9.1:compile
[INFO] |  |     \- org.apache.xmlgraphics:batik-i18n:jar:1.9.1:compile
[INFO] |  \- jfree:jcommon:jar:1.0.15:compile
[INFO] +- org.springframework.security:spring-security-taglibs:jar:4.2.6.RELEASE:runtime
[INFO] |  \- org.springframework:spring-aop:jar:5.0.7.RELEASE:compile
[INFO] +- org.hibernate:hibernate-infinispan:jar:5.2.17.Final:runtime
[INFO] |  \- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] +- org.hibernate:hibernate-search-serialization-avro:jar:5.7.3.Final:runtime
[INFO] |  \- org.apache.avro:avro:jar:1.7.7:runtime
[INFO] |     +- com.thoughtworks.paranamer:paranamer:jar:2.3:runtime
[INFO] |     \- org.apache.commons:commons-compress:jar:1.4.1:runtime
[INFO] +- org.hibernate:hibernate-search-backend-jgroups:jar:5.7.3.Final:runtime
[INFO] +- org.infinispan:infinispan-directory-provider:jar:8.2.11.Final:runtime
[INFO] |  +- org.infinispan:infinispan-lucene-directory:jar:8.2.11.Final:runtime
[INFO] |  \- org.infinispan:infinispan-core:jar:8.2.11.Final:runtime
[INFO] |     +- org.infinispan:infinispan-commons:jar:8.2.11.Final:runtime
[INFO] |     +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:runtime
[INFO] |     \- org.jboss.marshalling:jboss-marshalling-osgi:jar:2.0.0.Beta3:runtime
[INFO] +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.31:test
[INFO] |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.31:test
[INFO] +- org.apache.tomcat.embed:tomcat-embed-jasper:jar:8.5.31:test
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.31:test
[INFO] |  \- org.eclipse.jdt:ecj:jar:3.12.3:test
[INFO] +- org.apache.tomcat:tomcat-jasper:jar:8.5.31:test
[INFO] |  +- org.apache.tomcat:tomcat-servlet-api:jar:8.5.31:test
[INFO] |  +- org.apache.tomcat:tomcat-juli:jar:8.5.31:test
[INFO] |  +- org.apache.tomcat:tomcat-el-api:jar:8.5.31:test
[INFO] |  +- org.apache.tomcat:tomcat-jasper-el:jar:8.5.31:test
[INFO] |  +- org.apache.tomcat:tomcat-api:jar:8.5.31:test
[INFO] |  \- org.apache.tomcat:tomcat-util-scan:jar:8.5.31:test
[INFO] |     \- org.apache.tomcat:tomcat-util:jar:8.5.31:test
[INFO] +- org.apache.tomcat:tomcat-jsp-api:jar:8.5.31:test
[INFO] +- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] +- com.vaadin.external.json:json:jar:0.0.20080701:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] +- org.easymock:easymockclassextension:jar:2.4:test
[INFO] |  +- org.easymock:easymock:jar:3.0:test
[INFO] |  \- cglib:cglib-nodep:jar:2.1_3:test
[INFO] +- org.powermock:powermock-api-easymock:jar:1.6.6:test
[INFO] |  \- org.powermock:powermock-api-support:jar:1.6.6:test
[INFO] |     +- org.powermock:powermock-core:jar:1.6.6:test
[INFO] |     \- org.powermock:powermock-reflect:jar:1.6.6:test
[INFO] |        \- org.objenesis:objenesis:jar:2.5.1:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.6:test
[INFO] |  \- org.powermock:powermock-module-junit4-common:jar:1.6.6:test
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- taglibs:standard:jar:1.1.2:compile
[INFO] +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.springframework:spring-test:jar:5.0.7.RELEASE:test
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] +- org.hamcrest:hamcrest-integration:jar:1.3:test
[INFO] +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.25:runtime
[INFO] +- org.apache.commons:commons-lang3:jar:3.7:compile
[INFO] +- com.opencsv:opencsv:jar:4.0:compile
[INFO] |  \- org.apache.commons:commons-text:jar:1.1:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.8.13:compile
[INFO] +- org.apache.httpcomponents:httpasyncclient:jar:4.1.3:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.9:compile
[INFO] |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.9:compile
[INFO] |  \- org.apache.httpcomponents:httpclient:jar:4.5.5:compile
[INFO] +- com.lowagie:itext:jar:2.1.7:compile
[INFO] +- org.bouncycastle:bcprov-jdk15on:jar:1.59:compile
[INFO] +- javax.mail:mail:jar:1.4.2:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] \- com.oracle:ojdbc7:jar:12.1.0.2:runtime
2 Likes

Fork this GitHub repository, set this plugin attribute to true and run mvn clean test-compile.

It works like a charm. Then, compare to your setting.

when running in a docker container after using the mvn clean compile package -DskipTests to build the war

[ParallelWebappClassLoader@60332273] error can't determine implemented interfaces of missing type org.springframework.ldap.core.support.BaseLdapPathContextSource
when weaving type org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer
when weaving classes 
when weaving 
 [Xlint:cantFindType]
[ParallelWebappClassLoader@60332273] error can't determine implemented interfaces of missing type org.springframework.ldap.core.support.BaseLdapPathContextSource
when weaving type org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer
when weaving classes 
when weaving 
 [Xlint:cantFindType]
Jul 25, 2018 6:48:20 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [com.mckesson.dex.config.DexContextLoaderListener]
javax.persistence.EntityNotFoundException: Unable to find com.myapp.model.procedure.ProviderTest with id 254

this is the settings I was using for the maven plugin.

      <plugin>
        <groupId>org.hibernate.orm.tooling</groupId>
        <artifactId>hibernate-enhance-maven-plugin</artifactId>
        <version>${hibernate.version}</version>
        <executions>
          <execution>
            <configuration>
              <enableDirtyTracking>true</enableDirtyTracking>
              <enableLazyInitialization>true</enableLazyInitialization>
              <enableExtendedEnhancement>true</enableExtendedEnhancement>
            </configuration>
            <goals>
              <goal>enhance</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
2 Likes

That looks like a Spring issue. Try to ask the question on their framework. From Hibernate perspective, everything works fine as demonstrated by that provided repository.

I opened an issue on spring core requesting docs, I found a page in a spring book that suggests runtime bytecode enhancement only works with spring instrumentation. hibernate docs don’t suggest any 3rd party requirement. So I got that up and running, seeing this type of stuff in the logs

12:19:03,243 [DEBUG] Skipping enhancement of [com.sun.proxy.$Proxy334]: not entity or composite            [localhost-startStop-1] org.hibernate.bytecode.enhance.internal.javassist.EnhancerImpl.enhance(EnhancerImpl.java:155) (:)
12:19:03,439 [DEBUG] Skipping enhancement of [myapp.service.labTest.NoCoverageReportViewModel$$EnhancerBySpringCGLIB$$592c608]: not entity or composite [localhost-startStop-1] org.hibernate.bytecode.enhance.internal.javassist.EnhancerImpl.enhance(EnhancerImpl.java:155) (:)
12:19:03,529 [DEBUG] Skipping enhancement of [myapp.dao.loader.ProviderTestImportJobDao$$EnhancerBySpringCGLIB$$f176c5f2]: not entity or composite [localhost-startStop-1] org.hibernate.bytecode.enhance.internal.javassist.EnhancerImpl.enhance(EnhancerImpl.java:155) (:)

odd thing is, everything but the proxy is a service… so of course it would skip… but what is the proxy and why is it not picking up entities…

I give up, with build time enhancement 'causing things blow up that don’t blow up without it… requiring me to pollute higher layers with compile time deps they shouldn’t otherwise need. And runtime enhancement either seemingly impossible or not doing what I mean (not sure which is actually true from even trace loggging). better to just write my own lazy method for retrieval… (actually, now I’m thinking why can’t I do this where I write a Supplier for a field and let hibernate inject the supplier…

@Query( value = "SELECT file_data FROM document where id = ?", nativeQuery = true )
Blob getDocumentData( long id );

/* I am an evil method written to preserve prior contracts */
static Supplier<InputStream> getDocumentDataById( long id ) {
    return () -> {
        try {
            return SpringHelper.getBean( DocumentRepository.class )
                .getDocumentData( id )
                .getBinaryStream();
        }
        catch ( SQLException e ) {
            LoggerFactory.getLogger( DocumentRepository.class ).error( "data not retrieved {}", e );
        }
        return new ByteArrayInputStream( new byte[0] );
    };
}
1 Like

Or, you can just use subentities.

It works like a charm.

that would actually be a worse solution in our case, but that’s because we’re using Local DTOs and what I wrote allowed me to truly defer execution until the file contents were requested. That of course is not an issue with hibernate but rather an issue of ours, and vaadin’s design.

P.S. I opened a doc request with spring, though I’d suggest that the runtime loading docs are perhaps also incomplete since your repositories code uses use build time enhancement, and it seems simply enabling the properties does not result in runtime enhancement working, 2 cents. https://jira.spring.io/browse/SPR-17089

1 Like

Unlike DTOs, subentities can track modifications. So, they can handle both reads and writes.