Monday, September 29, 2014

Can we create a hibernate file with out id field?

Answer is NO.

Here is why?
Hibernate identifies Objects (in first and 2nd level cache) using the ID of the object, so an object without an ID cannot be represented in hibernate.

Solution:
You need create a composite key combination . But finally you need to have any one of id combination. :-)

  <class name="com.cscinfo.nameprotect.db.np.dao.VaObBuildQueueView" table="VA_OB_BUILD_QUEUE_VIEW" schema="NP">
    
    <composite-id>
<key-property name="fileId" column="FILE_ID"  />
<key-property name="fileDataId" column="FILE_DATA_ID"  />
<key-property name="vaBuildRequestId" column="BUILD_REQUEST_ID"  />
</composite-id>

Friday, September 26, 2014

How to write a junit test case for a void return type?

Example code:

public void initiateArchiverBuilder(WcBrand wcBrand,
VaReportEntry vaReportEntry) {
VaBuildRequest vaBuildRequest = new VaBuildRequest();
vaBuildRequest.setObjectId(vaReportEntry.getId());
vaBuildRequest.setPriority(1);
vaBuildRequest.setBuilder("BUILDER_ARCHIVER");
vaBuildRequest.setAction("ARCHIVER_ACTION_ARCHIVE)";
vaBuildRequestDao.create(vaBuildRequest);
}

Junit :

You can verify the create method is called or not in junit.
Mockito.verify(vaReportEntryDao).create(Mockito.any(VaReportEntry.class));

To verify a Method is called or not in JUNIT which is running by MockitoJUnitRunner

We can verify a method its called or not?

This is the way to verify:

Mockito.verify(vaBuildRequestDao).create(Mockito.any(VaBuildRequest.class));

Above verify meaning we should expect a create method be called on VaBuildRequestDao.


Mockito.verify(vaBuildRequestDao,Mockito.times(2)).create(Mockito.any(VaBuildRequest.class));

Above verify meaning we are expecting the create method is called 2 times on VaBuildRequestDao .If it wont call the test case will be failed.

Friday, September 19, 2014

Composite key in hibernate

@Embeddable
public class RolesMenu {
    @Column(name = "RoleID")
    private String roleID;

    @Column(name = "MenuItemID")
    private String menuItemID;

    //getter, setter methods
}

 @Entity
 @Table(name = "RolesMenuItems")
 public class RolesMenuItems {

     @EmbeddedId
     private RolesMenu roleMenu;

  /*setter getter methods */
 }

Thursday, September 18, 2014

confirm box issue in IE.

Confirm box will never work in IE7 & 8 , When you click on cancel also it will continue the same operation.

Here is solution or fix:

if(confirm('Do you really want to delete this document?')==false){event.returnValue=false;return false;}else{return true;};

This will fix the confirm box IE issue.

Thanks,
kiran.vennampelli.

Wednesday, September 10, 2014

Formatting or customizing the jqgrid colmodel view

JqGrid colModel setup:
Here we need to add new property to customize the data for example building a hyper link instead of showing the data, we need to add property called formatter below is the sample code 
colModel : [{name : 'whois',
index : 'whois',
width : 25,
align : 'center',
sortable : false,
editable : false,
classes : "actions-col",
formatter : buildWhoisLink
},
......
]




Here is the function for buildWhoisLink

function buildWhoisLink(cellvalue, options, rowObject) {
return "<a id=\"whois_"+options.rowId+"\" onclick=\"return showWhois('"+rowObject[0]+"', "+options.rowId+");\" href=\"#\">Whois</a>";
}

Tuesday, September 9, 2014

Jquery:Call some other click event in a other function

<input type="button" id="saveUpdatedRows" value="Save" />

Simple button click function:This function will be called when save button is clicked.
$(function(){
$("#saveUpdatedRows").click(
   function(){
    //Write your logic
   }
);        

});

When you want to call same save button click function from some other function eg. like on pagination, on complete ..etc.

you can use the trigger function to trigger the click event on saveUpdatedRows function.
Code below:

$( "#saveUpdatedRows" ).trigger( "click" );