java - Lazy loading doesn't work for @Formula in Hibernate -


i'm trying make 1 of fields calculable, don't want calculate time entity retrieved. want, calculate in case it's necessary current query or time getter invoked. that's why use @formula:

@basic(fetch = fetchtype.lazy) @formula("(select max(myentity.creation_time) myentity myentity  myentity.account_id = id)") private localdatetime entitiesmodifieddate; 

to make work, use bytecode instrument this:

        <plugin>             <artifactid>maven-antrun-plugin</artifactid>             <version>1.3</version>             <executions>                 <execution>                     <id>instrument domain classes</id>                     <configuration>                         <tasks>                             <taskdef name="instrument" classname="org.hibernate.tool.instrument.javassist.instrumenttask">                                 <classpath>                                     <path refid="maven.dependency.classpath" />                                     <path refid="maven.plugin.classpath" />                                 </classpath>                             </taskdef>                             <instrument verbose="true">                                 <fileset dir="${project.build.outputdirectory}">                                     <include name="**/entity/*.class" />                                 </fileset>                             </instrument>                         </tasks>                     </configuration>                     <phase>process-classes</phase>                     <goals>                         <goal>run</goal>                     </goals>                 </execution>             </executions>         </plugin> 

there 2 problems face here:

  1. it seems syntax incorrect though got question. error have:

an ant buildexception has occurred: instrument doesn't support "verbose" attribute: type doesn't support "verbose" attribute.

  1. in case remove verbose="true", works, however, subquery part of each query entities(no effect).

is there else should done make work?

here took example: http://tricksdev.blogspot.ru/2009/03/hibernate-bytecode-instrumentation.html

updated:

query example:

select ...{fields}..., (     select         max(event.creation_time)             myentity myentity             myentity.accountid = account1_.id ) formula0_ table1 table10_ cross join account_table account1_ table10_.account_id = account1_.id , account1_.user_id = 1 

use hibernate-enhance-maven-plugin , or try maven-antrun-plugin last version (1.8)

 <plugins>     <plugin>         <groupid>org.hibernate.orm.tooling</groupid>         <artifactid>hibernate-enhance-maven-plugin</artifactid>         <executions>             <execution>                 <phase>process-classes</phase>                 <goals>                     <goal>enhance</goal>                 </goals>             </execution>         </executions>     </plugin> </plugins> 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -