<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Java Blog - Java, J2EE, SOA, Spring and Hibernate &#187; Hibernate</title>
	<link>http://javablog.info</link>
	<description></description>
	<pubDate>Thu, 17 Apr 2008 00:24:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>JBoss Seam EnitityQuery and Restrictions</title>
		<link>http://javablog.info/2007/11/21/jboss-seam-enitityquery-and-restrictions/</link>
		<comments>http://javablog.info/2007/11/21/jboss-seam-enitityquery-and-restrictions/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 21:47:36 +0000</pubDate>
		<dc:creator>Ravi Nallakukkala</dc:creator>
		
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://javablog.info/2007/11/21/jboss-seam-enitityquery-and-restrictions/</guid>
		<description><![CDATA[http://www.jboss.com/index.html?module=bb&#38;op=viewtopic&#38;t=120649
Additional info on restrictions usage:
1) Seam forces one EL expression per restriction.
2) can combine a EL expression and constants in one restriciton
Example:
&#8220;name like concat(lower(#{customer.name}),&#8217;%') or description like &#8216;ILI%&#8217;)&#8221;
3) Multiple restrictions are treated as &#8220;and&#8221; operation.
]]></description>
			<content:encoded><![CDATA[<p>http://www.jboss.com/index.html?module=bb&amp;op=viewtopic&amp;t=120649</p>
<p>Additional info on restrictions usage:</p>
<p>1) Seam forces one EL expression per restriction.<br />
2) can combine a EL expression and constants in one restriciton<br />
Example:<br />
&#8220;name like concat(lower(#{customer.name}),&#8217;%') or description like &#8216;ILI%&#8217;)&#8221;<br />
3) Multiple restrictions are treated as &#8220;and&#8221; operation.</p>
]]></content:encoded>
			<wfw:commentRss>http://javablog.info/2007/11/21/jboss-seam-enitityquery-and-restrictions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Equals and hashcode Approach/ Implementation for Business Objects (Bo)</title>
		<link>http://javablog.info/2007/04/15/equals-and-hashcode-implementation-for-business-objects-bo/</link>
		<comments>http://javablog.info/2007/04/15/equals-and-hashcode-implementation-for-business-objects-bo/#comments</comments>
		<pubDate>Sun, 15 Apr 2007 07:58:37 +0000</pubDate>
		<dc:creator>Ravi Nallakukkala</dc:creator>
		
		<category><![CDATA[Design]]></category>

		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://javablog.info/2007/04/15/equals-and-hashcode-implementation-for-business-objects-bo/</guid>
		<description><![CDATA[A common source for bugs while writing code Business Objects for relational database using Object Relation Mapping tools is the implementation of the Equals and Hashcode methods.
If you would like to know more about the Equals and Hashcode importance for an ORM  Click here.
To summarize the ORM implementation, There are two types of keys: [...]]]></description>
			<content:encoded><![CDATA[<p>A common source for bugs while writing code Business Objects for relational database using Object Relation Mapping tools is the implementation of the Equals and Hashcode methods.</p>
<p>If you would like to know more about the Equals and Hashcode importance for an ORM  <a href="http://www.hibernate.org/109.html" target="_blank">Click here.</a></p>
<p>To summarize the ORM implementation, There are two types of keys: Technical Keys and Business keys.</p>
<p>Technical keys are the primary key on the for a table to uniquely identify a database row, these numbers are auto generated sequence number (Item Unique IDentification/ IUID).</p>
<p>Business keys are the Business primary (/ composite) keys which uniquely identify the business objects   in the database tables.</p>
<p>One of the important factor while writing a equals and hashcode method is to decide on what attributes needs to go into these methods; Some guidelines for deciding the attributes for Equals and hashcode methods.</p>
<ul>
<li>It is not necessary to cover all the attributes in Business Objects in equals/ hashcode methods.</li>
<li>Include the Technical Keys and Business keys in equals and hashcode methods.</li>
<li>Equals and hashcode methods should take care of the null cases.</li>
</ul>
<p>Implementation wise, <a href="http://projects.apache.org/projects/jakarta_commons_lang.html" target="_blank">Apache commons-lang </a>has a very good implementation for hashcode and equals method. Here&#8217;s an example of equals and hashcode methods using the apache commons-lang<code>.</code></p>
<p><code> @Entity<br />
@Table(name = "APP_CONFIGURATION")<br />
@SequenceGenerator(name = "OPS_SEQ", sequenceName = "SQ_CONFIGURATION_CNTR")<br />
public class ConfigurationBo extends AbstractBo {</code></p>
<p>private static final long serialVersionUID = -5098377177228374794L;</p>
<p>@Column(name = &#8220;ITEMNAME&#8221;, length = 100)<br />
private String name;</p>
<p>@Column(name = &#8220;STRINGVALUE&#8221;, length = 100)<br />
private String stringValue;</p>
<p>@Column(name = &#8220;INTVALUE&#8221;)<br />
private Integer intValue;</p>
<p>@Column(name = &#8220;TYPENAME&#8221;, length = 20)<br />
private String type;</p>
<p>public Integer getIntValue() {<br />
return intValue;<br />
}</p>
<p>public void setIntValue(Integer intValue) {<br />
this.intValue = intValue;<br />
}</p>
<p>public String getName() {<br />
return name;<br />
}</p>
<p>public void setName(String name) {<br />
this.name = name;<br />
}</p>
<p>public String getStringValue() {<br />
return stringValue;<br />
}</p>
<p>public void setStringValue(String stringValue) {<br />
this.stringValue = stringValue;<br />
}</p>
<p>public String getType() {<br />
return type;<br />
}</p>
<p>public void setType(String type) {<br />
this.type = type;<br />
}</p>
<p>/**<br />
* {@inheritDoc}<br />
*/<br />
@Override<br />
public boolean equals(Object obj) {<br />
if (this == obj) {<br />
return true;<br />
}<br />
if (!(obj.getClass() == this.getClass())) {<br />
return false;<br />
}<br />
ConfigurationBo other = (ConfigurationBo) obj;</p>
<p>return new EqualsBuilder()<br />
.appendSuper(super.equals(obj))<br />
.append(this.name, other.name)<br />
.append(this.type, other.type)<br />
.isEquals();<br />
}</p>
<p>/**<br />
* {@inheritDoc}<br />
*/<br />
@Override<br />
public int hashCode() {<br />
return new HashCodeBuilder()<br />
.appendSuper(super.hashCode())<br />
.append(this.name)<br />
.append(this.type)<br />
.toHashCode();<br />
}</p>
<p>/**<br />
* {@inheritDoc}<br />
*/<br />
@Override<br />
public String toString() {<br />
return super.toString() + &#8220;[name=&#8221; + name + &#8220;, type=&#8221; + type + &#8220;]&#8221;;<br />
}</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://javablog.info/2007/04/15/equals-and-hashcode-implementation-for-business-objects-bo/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Search Pagination Design (Server side pagination using Hibernate)</title>
		<link>http://javablog.info/2007/03/30/search-pagination-design-server-side-pagination-using-hibernate/</link>
		<comments>http://javablog.info/2007/03/30/search-pagination-design-server-side-pagination-using-hibernate/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 20:45:50 +0000</pubDate>
		<dc:creator>Ravi Nallakukkala</dc:creator>
		
		<category><![CDATA[Design]]></category>

		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://javablog.info/2007/03/30/search-pagination-design-server-side-pagination-using-hibernate/</guid>
		<description><![CDATA[One of the biggest problem which is commonly faced in searches is pagination; On the first day of my new job, I was asked to looked the performance issues related in the search functionality of the application. When I looked at the application, application is slow when the users gets a search results of magnitude [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest problem which is commonly faced in searches is pagination; On the first day of my new job, I was asked to looked the performance issues related in the search functionality of the application. When I looked at the application, application is slow when the users gets a search results of magnitude of 6000 records( each record had 10 fields to be displayed) and all the results were displayed in a single HTML page (Even if you had designed one search implementation, you would have guessed what the problem is).</p>
<p>There is no pagination concept implemented for this search/ problem, its a logical  thing to say this search program is using whole lots of memory and slow. Assuming the search queries are already fine-tuned, Slowness can be mainly attributed to the HTML rendering by the browser. IE browser render the complete HTML and then displays it to the user so the slowness can be easily be found compared to Firefox 2, where the browser starts displaying the data as it receives (rather completely render it and displays it).</p>
<p>Given this background, Now we started seriously looking at pagination as the only option. In pagination, could think three approaches as a potential solutions</p>
<ul>
<li>Real time pagination on the server side.</li>
<li>Criteria Caching based pagination on Server side.</li>
<li>Pagination on the UI front.</li>
</ul>
<p>Lets go in details of each one of them.</p>
<p><strong>Real time pagination on the server side :</strong></p>
<p>This is an approach where from the UI, always pass the search criteria plus the page start record and the end record (or size of the page). So your server implementation will have these two extra arguments along with your query and returns you only the required result set which needs to be passed to front end.</p>
<p>On the implementation front, you could handle this scenario at two levels</p>
<ul>
<li>Write a stored procedure which takes your criteria and start and end record (or Size)  for the page as argument and using &#8216;cursors&#8217;  you can return only the required result set, for more details on oracle specific result set using cursor <a href="http://asktom.oracle.com/tkyte/ResultSets/index.html" target="_blank"><strong>click here</strong></a></li>
<li>Say you are using ORM tools like hibernate, they make our life even easier you could try something like <strong><br />
</strong></li>
</ul>
<p>Query q = s.createQuery( &#8220;your query&#8230;.&#8221; );<br />
q.setMaxResults(PAGE_SIZE);<br />
q.setFirstResult(PAGE_SIZE * pageNumber);<br />
List page = q.list();</p>
<ul>
<li>For more details on this hibernate approach <a href="http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html" target="_blank"><strong>click here</strong></a></li>
</ul>
<p>Lets looks at the pros and cons of this approach</p>
<ul>
<li>Its a real time pagination search, say your query is based on order by name, on the first page we show say 25 records, in the mean while say another user deletes few records (say 20 to 25th record gets deleted), now when the first user click the next button, the request goes as original criteria and retrieve the records from 26th to 50th record and we return 26 to 50 th records (because of the deletion, ideally we should have displayed from 20th to 45th records), essentially now we are not showing 5 records this is a disadvantage. For the same example, addition of records &#8216;could&#8217; be an advantage for this approach.</li>
</ul>
<p><strong>Criteria Caching based pagination on Server side</strong></p>
<p>This is an approach where all records matching to the search criteria will be fetched from the database to the the server and cached. Caching is based the search criteria and a timeout period.</p>
<p>From the UI point of view, request will contain the search criteria plus the start record and the size( r the end record) to be fetched.</p>
<p>Lets looks at the pros and cons of this approach</p>
<ul>
<li>This solution should fairly work for most of the search cases, unless you have a requirement for real time pagination.</li>
<li>When Caching is considered, Caching algorithm plays an important role and this also has to take care of the timeout period and the memory allocated for the caching mechanism.</li>
<li>Arriving on the timeout period is quite crucial as this directly impacts your performance of the search. Too low timeout (is very near to real time pagination case) will cause too many hits to your database and can cause slowness also has the drawbacks of real time pagination. Too long timeout period will have the drawback of having out-dated data on the server cache.</li>
</ul>
<p><strong>Pagination on the UI front</strong></p>
<p>This is an approach where all the records corresponding the search criteria will be retrieved from the database and held in the controller of the UI Framework and using custom tag libraries the records could be displayed in the Jsp/ Servlet.</p>
<p>Here are some of the recommendations for writing your own custom pagination tab lib</p>
<ul>
<li>The bean will have attributes for collection of all the records, total number of pages, records per page and start record number for the current page.</li>
<li>On the first display of the page, read all the corresponding records for this page and store the bean in HTTP Session.</li>
<li>On the selection of the next page, previous page, etc.,;  retrieve the bean from the HTTP Session and then calculate which data needs to be displayed.</li>
</ul>
<p>Lets looks at the pros and cons of this approach</p>
<ul>
<li>This would be dream design approach for small volume search results (where memory is not a constraint).</li>
<li>Most the cases, you do have a memory constraint, hence this may not be a feasible approach.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://javablog.info/2007/03/30/search-pagination-design-server-side-pagination-using-hibernate/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hibernate Vs EJB</title>
		<link>http://javablog.info/2007/03/25/hibernate-vs-ejb/</link>
		<comments>http://javablog.info/2007/03/25/hibernate-vs-ejb/#comments</comments>
		<pubDate>Sun, 25 Mar 2007 03:26:34 +0000</pubDate>
		<dc:creator>Ravi Nallakukkala</dc:creator>
		
		<category><![CDATA[Hibernate]]></category>

		<category><![CDATA[Java/ J2EE]]></category>

		<guid isPermaLink="false">http://javablog.info/?p=4</guid>
		<description><![CDATA[Advantages:
- Hibernate Beans are easier to implement since you don&#8217;t  need any interface coding.
- Queries can be dynamic and perform faster (at  least on WebLogic and JBoss)
- Hibernate offers a more object-oriented  approach. You can map is-a relationships as subclasses.
- For data transfer  you can use Hibernate Beans as DTOs if [...]]]></description>
			<content:encoded><![CDATA[<p>Advantages:<br />
- Hibernate Beans are easier to implement since you don&#8217;t  need any interface coding.<br />
- Queries can be dynamic and perform faster (at  least on WebLogic and JBoss)<br />
- Hibernate offers a more object-oriented  approach. You can map is-a relationships as subclasses.<br />
- For data transfer  you can use Hibernate Beans as DTOs if you want (and if it&#8217;s applicable). You  can even fill &#8216;custom&#8217; DTOs with query results just with one line of code using  the select-new construct.</p>
<p>Disadvantages:<br />
- Hibernate Beans are not  automatically &#8216;locked&#8217; for others while used during a transaction. This can lead  to inconsistent data when more clients concurrently modify the same  data.<br />
-Object Pooling is an Issue</p>
]]></content:encoded>
			<wfw:commentRss>http://javablog.info/2007/03/25/hibernate-vs-ejb/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
