-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: @Formula and Lazy
PostPosted: Mon Sep 15, 2008 2:22 pm 
Newbie

Joined: Tue Mar 18, 2008 12:34 pm
Posts: 6
Hi All,
How do I set a field loaded with @Formula annotation as lazy?

I tried

@Formula( "(select abc from x)" )
@LazyCollection(LazyCollectionOption.TRUE)

But didn't work. What is the correct form?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 2:33 pm 
Newbie

Joined: Tue Mar 18, 2008 12:34 pm
Posts: 6
I fould a partial answer on http://forums.hibernate.org/viewtopic.php?p=2301129.
But didn't find more info about build time enhancement. Anyone?


Top
 Profile  
 
 Post subject: Same problem here
PostPosted: Thu Sep 25, 2008 6:19 pm 
Newbie

Joined: Thu Sep 25, 2008 6:10 pm
Posts: 4
I found this: http://www.hibernate.org/hib_docs/refer ... mance.html

The very last section 19.1.7. seems to be what we need.

I put the ant task in my build script after the compile section and everything builds fine, but the collections are still not lazy.

I am using the following in my bean:
Code:
@Formula("(SELECT COUNT(u.user_id) FROM users u WHERE  u.X > X)")
@Basic(fetch=FetchType.LAZY)
protected Integer newVar;


I am using Netbeans to manage my ant building and put the following into my build-impl.xml file
Code:
        <target name="instrument" depends="compile">
       <taskdef name="instrument" classname="org.hibernate.tool.instrument.InstrumentTask">
           <classpath path="${build.generated.dir}/lib"/>
           <classpath path="${build.classes.dir}"/>
           <classpath refid="lib.class.path"/>
       </taskdef>

       <instrument verbose="true">
           <fileset dir="${build.generated.dir}/classes/com/XXX/beans">
               <include name="*.class"/>
           </fileset>
       </instrument>
   </target>



Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 7:13 pm 
Newbie

Joined: Thu Sep 25, 2008 6:10 pm
Posts: 4
Still havent had any luck getting this to work.

I tried the Ant code in the Hibernate book, but that didn't work either.
Code:
<target name="instrument" depends="compile">
       <taskdef name="instrument"
                classname="org.hibernate.tool.instrument.cglib.InstrumentTask"
                classpathref="${build.classes.dir}"/>
       <instrument verbose="true">
           <fileset dir="${build.generated.dir}/classes/com/XXX/beans/">
               <include name="*.class"/>
           </fileset>
       </instrument>
   </target>



The book mentioned hibernate proxies are better than interception in most cases. Does anyone know if its possible to use a proxy for a @Formula mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 7:01 pm 
Newbie

Joined: Thu Sep 25, 2008 6:10 pm
Posts: 4
Finally got it working, although now compiles take forever.

Here is what I put in my build.xml


Code:
<path id="lib-jar">
            <fileset dir="build/web/WEB-INF/lib/">
                <include name="*.jar"/>
            </fileset>
        </path>
   
        <target name="-pre-dist" depends="compile">
       <taskdef name="instrument" classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
                <classpath>
                    <path refid="lib-jar"/>
                </classpath>     
       </taskdef>           
       <instrument verbose="true">
           <fileset dir="${build.web.dir}/WEB-INF/classes/com/X/beans/">
               <include name="A.class"/>
                    <include name="B.class"/>
                    <include name="C.class"/>
           </fileset>
       </instrument>
   </target>

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 7:02 pm 
Newbie

Joined: Thu Sep 25, 2008 6:10 pm
Posts: 4
Finally got it working, although now compiles take forever.

Here is what I put in my build.xml


Code:
<path id="lib-jar">
            <fileset dir="build/web/WEB-INF/lib/">
                <include name="*.jar"/>
            </fileset>
        </path>
   
        <target name="-pre-dist" depends="compile">
       <taskdef name="instrument" classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
                <classpath>
                    <path refid="lib-jar"/>
                </classpath>     
       </taskdef>           
       <instrument verbose="true">
           <fileset dir="${build.web.dir}/WEB-INF/classes/com/X/beans/">
               <include name="A.class"/>
                    <include name="B.class"/>
                    <include name="C.class"/>
           </fileset>
       </instrument>
   </target>



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.