Tuesday, November 23, 2010

Spring 3.1

Great!!!!!!!!!! here you go Springsource. I just watched a presentation of Jurgen Holler and thought to share it with you guys. here is link http://www.infoq.com/presentations/Spring-3.0-3.1-3.2.
Spring 3.1 with portlet 2.0, Java EE 6 support and aiming towards supporting Java 7.

Friday, July 9, 2010

Presentations on Different Topics of Java

Just a few weeks ago I came across a brilliant site. It contains different presentations, interviews, video trainings on different topics of Java Technologies like Spring framework, Hibernate, Spring Roo, GWT, AJAX, JavaFX, and many more.
One can also make his/her own JUG on Parleys' to share presentations and Interviews with rest of the world.
Its really interesting I would recommend you guys to have a look at that site, you will definitely going to love it.
Not only that you can also download a software of Parleys' on your machine and download presentation to watch them offline as well.
http://www.parleys.com/

Thursday, June 24, 2010

Spring Roo with GWT or GWT with Spring Roo

Google web toolkit has been in the market for a few years now. I remember I started using Google Web Toolkit in 2006 for my project, at that time it was a 0.9 version which was not even stable. I successfully used it in a commercial product with a lot of headache :( ..............................
But now GWT is far better than before with current version 2.0.1 with a new Compiler :).
As UI requirements change and non-traditional clients become more and more important, GWT is set to become increasingly important to Java developers.Spring Source again has came into action to make GWT more attractive and easy to use for Java Developers. Spring Source is going to work with Google to enhance functionality of GWT by integrating it with Spring Roo. This integration makes GWT applications far easier than ever to develop, and gives Spring developers a compelling new UI choice.
GWT is open source and independent of deployment environment, so this integration will benefit all Spring users, regardless of whether they intend to target their applications to Google App Engine. With its knowledge of the domain model, Spring Roo is a match made in heaven for GWT. With today’s integration Spring Roo can generate and round trip GWT interfaces, making developers far more productive throughout the application lifecycle; and support easy deployment to App Engine from within the Roo shell.
I am Anxiously waiting for this integration for happen .........................

Related Posts:
http://www.springsource.org/roo
http://blog.springsource.com/2010/05/19/spring-google-appengine/
http://code.google.com/webtoolkit/

Another great talk by Kathy Sierra

Another Great talk by Kathy Sierra, the co-inventor of the Head First series of books on technical topics, along with her partner. Sierra in her presentation speaks about Business techniques and user experiences. Great message given to product owners.

Related Posts:

http://en.wikipedia.org/wiki/Kathy_Sierra
http://web20show.com/2008/04/episode-43-creating-passionate-users/


Sunday, February 14, 2010

org.hibernate.HibernateException: Unexpected row count: 0 expected: 1

Full Exception:
org.hibernate.HibernateException: Unexpected row count: 0 expected: 1
    at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:32)
    at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1982)
    at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
    at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
    at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
    at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:687)
    at com.dps.hrms.pi.dao.EmployeeDocumentDAOImpl.save(EmployeeDocumentDAOImpl.java:46)
    at com.dps.hrms.pi.service.EmployeeServiceImpl.saveEmployee(EmployeeServiceImpl.java:592)
    at com.dps.hrms.pi.controller.EmployeeWizardController.processFinish(EmployeeWizardController.java:1142)
    at org.springframework.web.servlet.mvc.AbstractWizardFormController.validatePagesAndFinish(AbstractWizardFormController.java:667)
    at org.springframework.web.servlet.mvc.AbstractWizardFormController.processFormSubmission(AbstractWizardFormController.java:490)
    at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:259)
    at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
    at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:717)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:658)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:357)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)


Poooo................................ffff..................   At last I solved it.
The above exception occurred while working on saving Employee Information in my current system.
There is a multi-entry screen in my application which saves employee related documents. I have used GWT for dynamically adding rows when user clicks a button.

Thing which was happening which ate a lot of time of mine was just a SIMPLE thing, on some jsp page employeeDocumentId was set as '0', and when I called saveOrUpdate method of HibernateTemplate (Spring hibernate support class), it was going to update the record which DID NOT EXIST IN THE DATABASE :(.

Solution: Simple solution that if you are going to save a new record assign NULL to the ID which will be auto generated (as per your setting in .hbm.xml file). But if you assign an ID it must be valid (means the record must have to be existed in the database), coz Hibernate will go and try to update the record. If the record does not exist with that ID it will give above BIG exception.

Your comments would be highly appreciated.... If this post helped you in solving your problem.

Related Posts:
https://forum.hibernate.org/viewtopic.php?t=941985
http://bechblog.blogspot.com/2006/06/hibernate-could-not-synchronize.html

Saturday, January 23, 2010

org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance .........

Full Exception:
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.gr8riaz.hrms.JobTitle; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.gr8riaz.hrms.JobTitle

This exception occurs when you try to save an object with NULL parent ID. This also occurs when you try to save an object with parent ID which does not exist in database e,g. if you try to save record with parent ID "-1" hibernate session will through an exception mentioned above.

Explaination:
For example if you have following two objects (POJOs):

JobTitle.java


/**
 * File Name: JobTitle.java
 * Created By: Muhammad Riaz
 */
package com.gr8riaz.hrms;

/**
 *
 * @author Muhammad Riaz
 *
 */
public class JobTitle {

    private Long jobTitleId;
    private String jobTitleName;
    private String jobTitleCode;

  
    public Long getJobTitleId() {
        return jobTitleId;
    }


    public void setJobTitleId(Long jobTitleId) {
        this.jobTitleId = jobTitleId;
    }
   

    public String getJobTitleName() {
        return jobTitleName;
    }
   
    public void setJobTitleName(String jobTitleName) {
        this.jobTitleName = jobTitleName;
    }
   
    public String getJobTitleCode() {
        return jobTitleCode;
    }

    public void setJobTitleCode(String jobTitleCode) {
        this.jobTitleCode = jobTitleCode;
    }
}


Employee.java


/**
 * File Name: Employee.java
 * Created By: Muhammad Riaz
 */
package com.gr8riaz.hrms;

/**
 *
 * @author Muhammad Riaz
 *
 */
public class Employee {

    private Long employeeId;
    private String employeeName;
    private JobTitle jobTitle;

  
    public JobTitle getJobTitle() {
        return jobTitle;
    }


    public void setJobTitle(JobTitle jobTitle) {
        this.jobTitle = jobTitle;
    }
   

    public String getEmployeeName() {
        return employeeName;
    }
   
    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }
   
    public String getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(String employeeId) {
        this.employeeId = employeeId;
    }
}

In this case if you try to save employee as follows:

............
Employee employee = new Employee();
employee.setEmployeeName("Muhammad Riaz");
employee.setJobTitle(new JobTitle());

hibernateSession.saveOrUpdate(employee);
............
This will give following exception:
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.gr8riaz.hrms.JobTitle; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.gr8riaz.hrms.JobTitle

SOLUTION:

//In case JobTitle is nullable

.............................

Employee employee = new Employee();
employee.setEmployeeName("Muhammad Riaz");
employee.setJobTitle(null); //In case JobTitle is nullable
hibernateSession.saveOrUpdate(employee);
...........................

//In case JobTitle is not nullable


.............................
Employee employee = new Employee();
employee.setEmployeeName("Muhammad Riaz");
JobTitle jobTitle = new JobTitle();
jobTitle.setJobTitleId(new Long(1));   //There should have to be a record of JobTitle with Id=1 in
                                                          //database, otherwise it will give the same above exception
employee.setJobTitle(jobTitle);
hibernateSession.saveOrUpdate(employee);
...........................

Monday, January 18, 2010

Spring 3.0 Web Stack

A complete and comprehensive explanation and eleboration of Spring Web Stack is provided in this presentation SpringOne Conference 2009. Keith Donald (principal and founding partner at SpringSource) discusses the Spring 3.0 web stack, key Spring Framework and Spring MVC features, demos of Spring MVC capabilities, REST support, validation support, automatic data conversion, data binding and validation, Joda Time support, Spring JavaScript, Dojo, Spring Web Flow, Spring Security, Spring BlazeDS, and the roadmap for the Spring web stack more...

Sunday, January 17, 2010

How to protect yourself against the Chinese Google hack

Most obvious solution is not mentioned, "Don't use IE, instead use Firefox, Chrome or Opera"

Worried about the security hole in Internet Explorer that was used to launch attacks by China against Google and others? There are ways to help close it and limit your exposure to similar threats --- and it won't take more than a few minutes. Here's how to do it. more...

German government warns against using MS Explorer

The German government has warned web users to find an alternative browser to Internet Explorer to protect security.
The warning from the Federal Office for Information Security comes after Microsoft admitted IE was the weak link in recent attacks on Google's systems.
Microsoft rejected the warning, saying that the risk to users was low and that the browsers' increased security setting would prevent any serious risk.
However, German authorities say that even this would not make IE fully safe more....

Tuesday, January 12, 2010

USB 3.0 finally arrives in the market

When you're in front of your PC, waiting for something to transfer to removable media, that's when seconds feel like minutes, and minutes feel like hours. And data storage scenarios such as that one is where the new SuperSpeed USB 3.0's greatest impact will be felt first. As of CES, 17 SuperSpeed USB 3.0-certified products were introduced, including host controllers, adapter cards, motherboards, and hard drives (but no other consumer electronics devices). Still more uncertified USB 3.0 products are on the way, and they can't get here fast enough.

One of the things to look for in the coming months is the certified SuperSpeed USB 3.0 logo. Products are currently filling the queues at the official certification testing labs, but presence of that certification logo will give you some peace of mind that the product you're buying truly does live up to the USB 3.0 spec more...