I have a h:selectOneMenu dropdown which performs CRUD operation.
The dropdown list has a value "New" which allows the users to enter new values into other form fields thereby performing Create/Insert operation
When users pick other values from the dropdown list it dynamically populates other fields in the form thereby facilitating Update/Delete operation. The problem is whenever i pick a different value from the dropdown list the database call happens twice.
Here is the dropdown
Code:
<h:selectOneMenu id="manufList" value="#{manufacturerBean.selectedManufacturer}" >
<f:selectItem itemLabel="New" itemValue="New" />
<f:selectItems value="#{manufacturerBean.manufacturerList}" />
<a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="manufName,manufDescription,manufSource,btnSave,btnDelete" />
</h:selectOneMenu>
</h:panelGrid>
Here is the sequence of method calls whenever i pick a value from the dropdown list
- First time the method in f:selectItems gets called which results in a database call
- Second time as expected Ajax4JSF onchange event method gets called
- Third time again the method in f:selectItems gets called resulting in database call
Here are the snippets from log file which substantiates that whenever i pick a value from dropdown database call occurs twice
Code:
********** FIRST METHOD CALL ***************************
2007-05-07 16:46:46,002 INFO [com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In getManufacturerList Backing Bean*** >
2007-05-07 16:46:46,002 INFO [com.boeing.nmt.nams.service.impl.ManufacturerManagerImpl] - < *** In getManufacturerList Spring*** >
Hibernate: select namsmanufa0_.ID as ID60_, namsmanufa0_.CHANGE_USER as CHANGE2_60_, namsmanufa0_.NA
ME as NAME60_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_, namsmanufa0_.SOURCE as SOURCE60_, namsmanu
fa0_.STATUS as STATUS60_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_ from NAMS_MANUFACTURER namsmanufa0
_
********** SECOND METHOD CALL ***************************
2007-05-07 16:46:46,237 INFO [com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In loadManufacturerDetails method *** >
Hibernate: select namsmanufa0_.ID as ID60_0_, namsmanufa0_.CHANGE_USER as CHANGE2_60_0_, namsmanufa0
_.NAME as NAME60_0_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_0_, namsmanufa0_.SOURCE as SOURCE60_0_
, namsmanufa0_.STATUS as STATUS60_0_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_0_ from NAMS_MANUFACTUR
ER namsmanufa0_ where namsmanufa0_.ID=?
********** THIRD METHOD CALL ***************************
2007-05-07 16:46:46,565 INFO [com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In getManufacturerList Backing Bean*** >
2007-05-07 16:46:46,565 INFO [com.boeing.nmt.nams.service.impl.ManufacturerManagerImpl] - < *** In getManufacturerList Spring*** >
Hibernate: select namsmanufa0_.ID as ID60_, namsmanufa0_.CHANGE_USER as CHANGE2_60_, namsmanufa0_.NA
ME as NAME60_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_, namsmanufa0_.SOURCE as SOURCE60_, namsmanu
fa0_.STATUS as STATUS60_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_ from NAMS_MANUFACTURER namsmanufa0
Note : I have managed bean in session scope
I have posted this on JSF/MyFaces forums people suggested me to use Hibernate Second Level Cache or Query Cache to avoid unnecessary database calls. As i am newbie to Hibernate any pointers/suggestions with snippet code will be highly appreciated
Regards
Bansi