Wednesday, June 2, 2010

Hibernate property level lazy fetch

lazy properties could be values like name , that are typically mapped to a single column. This is rarely an important feature to enable (this, unlike other lazy fetching strategies in Hibernate 3, is disabled by default).
class employee{
.....
@Basic(fetch=FecthType.Lazy)
String name;
...
}
will not ensure that name is lazy loaded when we query for employee record.

By default, property level lazy loading is silently ignored by hibernate.
To enable property level lazy fetching, your classes have to be instrumented: bytecode is added to the original class to enable such feature.


Add these to the pom.xml

<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.0.GA</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<tasks>
<taskdef name="instrument" classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
<classpath>
<path refid="maven.runtime.classpath" />
<path refid="maven.plugin.classpath" />
</classpath>
</taskdef>
<instrument verbose="false">
<fileset dir="${project.build.outputDirectory}">
<include name="**/domain/**/*.class" />
</fileset>
</instrument>
</tasks>
</configuration>
</plugin>

and if there are any ant task error while maven build regarding slf4j,

add this to the pom.xml file
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
</dependency>

Wednesday, February 17, 2010

extify like jquerify

Drag the extjsify hyperlink to bookmarks toolbar...

extjsify



This is a same like jquerify. Click on the extjsify and you should have the page added with necessary extjs libraries and you can play around in firebug......

Saturday, August 15, 2009

Return List of embedded objects in complex java object

Class Employee{
int id;
Address address;
String name;
}

Class Address{
String city;
String state;
ZipCode zip;
}

Class ZipCode{
String zipcode;
String extension;
}

List employees = ...... list of employees

If i need to retrieve all the zipcodes at which the employees are present.

Before knowing JXpath, I created a small recursive function which retrieves the information of each field. Later converted the object to xml and used xpath and got the values.

JXPath helps you ease you work

public static List returnList(List objList, String xPathName){
JXPathContext jxPathContext = null;
List returnedList = new ArrayList();
for(Object obj:objList){
jxPathContext = JXPathContext.newContext(obj);
returnedList.add(jxPathContext.getValue(xPathName));
}
return returnedList;
}