SQL Zone is brought to you in partnership with:

I am Siva, a passionate java developer, open source enthusiast, blogger. I like to cover Java, Struts, Spring, Hibernate, Ajax Tutorials, How-To's and Best Practices. Sivaprasadreddy is a DZone MVB and is not an employee of DZone and has posted 35 posts at DZone. You can read more from them at their website. View Full User Profile

SpringMVC3 Hibernate CRUD Sample Application

04.04.2011
| 61326 views |
  • submit to reddit

To learn any web framework starting with a HelloWorld application is a good idea. Once you have some familiarity with the framework configuration, it's better to do a CRUD(Create,Read,Update,Delete) application which covers various aspects of a web framework like Validation, Request URL Mappings, Request Parameter Binding, Pre-populating forms etc.

Now I am going to explain how to write a Simple CRUD application using SpringMVC3, Hibernate and MySQL.
Our Application is ContactsManagement where you can view or search contacts, create new contacts, edit or delete existing contacts.

Step#1: Create the CONTACTS Table

CREATE TABLE  CONTACTS
(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(45) NOT NULL,
address varchar(45) DEFAULT NULL,
gender char(1) DEFAULT 'M',
dob datetime DEFAULT NULL,
email varchar(45) DEFAULT NULL,
mobile varchar(15) DEFAULT NULL,
phone varchar(15) DEFAULT NULL,
PRIMARY KEY (id)
);
Step#2: Copy the SpringMVC, Hibernate and their dependent jars into WEB-INF/lib folder.
If you are using Maven you can mention the following dependencies.

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.5.RELEASE</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>javassist</artifactId>
<version>3.7.ga</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.14</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>

 
Step#3: Configure SpringMVC
 
 a) Configure DispatcherServlet in web.xml
   
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
   b) Configure View Resolver in WEB-INF/dispatcher-servlet.xml
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/jsp/" p:suffix=".jsp">
</bean>
 
c) Configure Annotation support, PropertyPlaceHolderConfigurer, ResourceBundleMessageSource in WEB-INF/classes/applicationContext.xml
 
    <context:annotation-config></context:annotation-config>

<context:component-scan base-package="com.sivalabs"></context:component-scan>

<mvc:annotation-driven> </mvc:annotation-driven >

<context:property-placeholder location="classpath:config.properties"></context:property-placeholder>

<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="Messages">
</bean>
Step#4: Configure JDBC connection parameters and Hibernate properties in config.properties

################### JDBC Configuration ##########################
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/sivalabs
jdbc.username=root
jdbc.password=admin

################### Hibernate Configuration ##########################
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
#hibernate.hbm2ddl.auto=update
hibernate.generate_statistics=true

    

Step#5: Configure DataSource, SessionFactory, TransactionManagement support in WEB-INF/classes/applicationContext.xml

 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}">
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<property name="packagesToScan" value="com.sivalabs"></property>
</bean>


<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory">
</bean>

<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>

  Step#6: Configure the Labels, error messages in WEB-INF/classes/Messages.properties
App.Title=SivaLabs
typeMismatch.java.util.Date={0} is Invalid Date.
dob=DOB
Step#7: Create the Entity class Contact.java
package com.sivalabs.contacts;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@Table(name="CONTACTS")
public class Contact
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column private String name;
@Column private String address;
@Column private String gender;
@Column private Date dob;
@Column private String email;
@Column private String mobile;
@Column private String phone;

@Override
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
//setters & getters
}
Step#8: Create the ContactsDAO.java which performs CRUD operations on CONTACTS table.
package com.sivalabs.contacts;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class ContactsDAO
{
@Autowired
private SessionFactory sessionFactory;

public Contact getById(int id)
{
return (Contact) sessionFactory.getCurrentSession().get(Contact.class, id);
}

@SuppressWarnings("unchecked")
public List<Contact> searchContacts(String name)
{
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Contact.class);
criteria.add(Restrictions.ilike("name", name+"%"));
return criteria.list();
}

@SuppressWarnings("unchecked")
public List<Contact> getAllContacts()
{
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Contact.class);
return criteria.list();
}

public int save(Contact contact)
{
return (Integer) sessionFactory.getCurrentSession().save(contact);
}

public void update(Contact contact)
{
sessionFactory.getCurrentSession().merge(contact);
}

public void delete(int id)
{
Contact c = getById(id);
sessionFactory.getCurrentSession().delete(c);
}
}

Step#9: Create ContactFormValidator.java which performs the validations on saving/updating a contact.
package com.sivalabs.contacts;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

@Component("contactFormValidator")
public class ContactFormValidator implements Validator
{
@SuppressWarnings("unchecked")
@Override
public boolean supports(Class clazz)
{
return Contact.class.isAssignableFrom(clazz);
}

@Override
public void validate(Object model, Errors errors)
{
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name","required.name", "Name is required.");
}
}
Step#10: Create ContactsControllers.java which processes all the CRUD requests.

package com.sivalabs.contacts;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ContactsControllers
{
@Autowired
private ContactsDAO contactsDAO;

@Autowired
private ContactFormValidator validator;

@InitBinder
public void initBinder(WebDataBinder binder)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

@RequestMapping("/searchContacts")
public ModelAndView searchContacts(@RequestParam(required= false, defaultValue="") String name)
{
ModelAndView mav = new ModelAndView("showContacts");
List<Contact> contacts = contactsDAO.searchContacts(name.trim());
mav.addObject("SEARCH_CONTACTS_RESULTS_KEY", contacts);
return mav;
}

@RequestMapping("/viewAllContacts")
public ModelAndView getAllContacts()
{
ModelAndView mav = new ModelAndView("showContacts");
List<Contact> contacts = contactsDAO.getAllContacts();
mav.addObject("SEARCH_CONTACTS_RESULTS_KEY", contacts);
return mav;
}

@RequestMapping(value="/saveContact", method=RequestMethod.GET)
public ModelAndView newuserForm()
{
ModelAndView mav = new ModelAndView("newContact");
Contact contact = new Contact();
mav.getModelMap().put("newContact", contact);
return mav;
}

@RequestMapping(value="/saveContact", method=RequestMethod.POST)
public String create(@ModelAttribute("newContact")Contact contact, BindingResult result, SessionStatus status)
{
validator.validate(contact, result);
if (result.hasErrors())
{
return "newContact";
}
contactsDAO.save(contact);
status.setComplete();
return "redirect:viewAllContacts.do";
}

@RequestMapping(value="/updateContact", method=RequestMethod.GET)
public ModelAndView edit(@RequestParam("id")Integer id)
{
ModelAndView mav = new ModelAndView("editContact");
Contact contact = contactsDAO.getById(id);
mav.addObject("editContact", contact);
return mav;
}

@RequestMapping(value="/updateContact", method=RequestMethod.POST)
public String update(@ModelAttribute("editContact") Contact contact, BindingResult result, SessionStatus status)
{
validator.validate(contact, result);
if (result.hasErrors()) {
return "editContact";
}
contactsDAO.update(contact);
status.setComplete();
return "redirect:viewAllContacts.do";
}

@RequestMapping("deleteContact")
public ModelAndView delete(@RequestParam("id")Integer id)
{
ModelAndView mav = new ModelAndView("redirect:viewAllContacts.do");
contactsDAO.delete(id);
return mav;
}
}

Step#11: Instead of writing the JSTL tag library declerations in all the JSPs, declare them in one JSP and include that JSP in other JSPs.

 


taglib_includes.jsp

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

Step#12: Create the JSPs.

a)showContacts.jsp

<%@include file="taglib_includes.jsp" %>

<html>
<head>

<title><spring:message code="App.Title"></spring:message> </title>
<script type="text/javascript" src="js/contacts.js"></script>
</head>
<body style="font-family: Arial; font-size:smaller;">
<center>
<form action="searchContacts.do" method="post">
<table style="border-collapse: collapse;" border="0" bordercolor="#006699" width="500">
<tr>
<td>Enter Contact Name</td>
<td><input type="text" name="name"/>
  <input type="submit" value="Search"/>
  <input type="button" value="New Contact" onclick="javascript:go('saveContact.do');"/>
</td></tr>
</table>
</form>

<table style="border-collapse: collapse;" border="1" bordercolor="#006699" width="500">
<tr bgcolor="lightblue">
<th>Id</th>
<th>Name</th>
<th>Address</th>
<th>Mobile</th>
<th></th>
</tr>
<c:if test="${empty SEARCH_CONTACTS_RESULTS_KEY}">
<tr>
<td colspan="4">No Results found</td>
</tr>
</c:if>
<c:if test="${! empty SEARCH_CONTACTS_RESULTS_KEY}">
<c:forEach var="contact" items="${SEARCH_CONTACTS_RESULTS_KEY}">
<tr>
<td><c:out value="${contact.id}"></c:out></td>
<td><c:out value="${contact.name}"></c:out></td>
<td><c:out value="${contact.address}"></c:out> </td>
<td><c:out value="${contact.mobile}"></c:out></td>
<td>
 <a href="updateContact.do?id=${contact.id}">Edit</a>
  <a href="javascript:deleteContact('deleteContact.do?id=${contact.id}');">Delete</a>
</td>
</tr>
</c:forEach>
</c:if>
</table>
</center>

</body>
</html>

b)newContact.jsp

<%@include file="taglib_includes.jsp" %>

<html>
<head>
<script type="text/javascript" src="js/contacts.js"></script>
<title><spring:message code="App.Title"></spring:message> </title>
</head>
<body style="font-family: Arial; font-size:smaller;">

<table bgcolor="lightblue" width="750" height="500" align="center" style="border-collapse: collapse;" border="1" bordercolor="#006699" >
<tr>
<td align="center"><h3>Edit Contact Form</h3></td>
</tr>
<tr valign="top" align="center">
<td align="center">
<form:form action="saveContact.do" method="post" commandName="newContact">

<table width="500" style="border-collapse: collapse;" border="0" bordercolor="#006699" cellspacing="2" cellpadding="2">
<tr>
<td width="100" align="right">Name</td>
<td width="150">
<form:input path="name"/></td>
<td align="left">
<form:errors path="name" cssStyle="color:red"></form:errors>
</td>
</tr>

<tr>
<td width="100" align="right">DOB</td>
<td><form:input path="dob"/></td>
<td align="left"><form:errors path="dob" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td width="100" align="right">Gender</td>
<td>
<form:select path="gender">
<form:option value="M" label="Male"/>
<form:option value="F" label="Female"/>
</form:select>
</td>
<td>
</td>
</tr>
<tr>
<td width="100" align="right">Address</td>
<td><form:input path="address"/></td>
<td align="left">
<form:errors path="address" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td width="100" align="right">Email</td>
<td><form:input path="email"/></td>
<td align="left"><form:errors path="email" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td width="100" align="right">Mobile</td>
<td><form:input path="mobile"/></td>
<td align="left">
<form:errors path="mobile" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" name="" value="Save">
  
<input type="reset" name="" value="Reset">
  
<input type="button" value="Back" onclick="javascript:go('viewAllContacts.do');">
</td>
</tr>
</table>
</form:form>
</td>
</tr>
</table>
</body>
</html>

c)editContact.jsp

<%@include file="taglib_includes.jsp" %>

<html>
<head>
<script type="text/javascript" src="js/contacts.js"></script>
<title><spring:message code="App.Title"></spring:message> </title>
</head>
<body style="font-family: Arial; font-size:smaller;">

<table bgcolor="lightblue" width="750" height="500" align="center" style="border-collapse: collapse;" border="1" bordercolor="#006699" >
<tr>
<td align="center"><h3>Edit Contact Form</h3></td>
</tr>
<tr valign="top" align="center">
<td align="center">
<form:form action="updateContact.do" method="post" commandName="editContact">
<table width="500" style="border-collapse: collapse;" border="0" bordercolor="#006699" cellspacing="2" cellpadding="2">
<tr>
<td width="100" align="right">Id</td>
<td width="150">
<form:input path="id" readonly="true"/></td>
<td align="left">
<form:errors path="id" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td width="100" align="right">Name</td>
<td>
<form:input path="name"/></td>
<td align="left">
<form:errors path="name" cssStyle="color:red"></form:errors>
</td>
</tr>

<tr>
<td width="100" align="right">DOB</td>
<td><form:input path="dob"/></td>
<td align="left"><form:errors path="dob" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td width="100" align="right">Gender</td>
<td>
<form:select path="gender">
<form:option value="M" label="Male"/>
<form:option value="F" label="Female"/>
</form:select>
</td>
<td>
</td>
</tr>
<tr>
<td width="100" align="right">Address</td>
<td><form:input path="address"/></td>
<td align="left">
<form:errors path="address" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td width="100" align="right">Email</td>
<td><form:input path="email"/></td>
<td align="left"><form:errors path="email" cssStyle="color:red"></form:errors> </td>
</tr>
<tr>
<td width="100" align="right">Mobile</td>
<td><form:input path="mobile"/></td>
<td align="left">
<form:errors path="mobile" cssStyle="color:red"></form:errors> </td>
</tr>
<tr valign="bottom">
<td colspan="3" align="center">
<input type="button" value="Delete" onclick="javascript:deleteContact('deleteContact.do?id=${editContact.id}');">
  
<input type="submit" name="" value="Save">
  
<input type="button" value="Back" onclick="javascript:go('viewAllContacts.do');">
</td>
</tr>

</table>
</form:form>
</td>
</tr>
</table>


</body>
</html>

Step#13: Write the javascript file js/contacts.js containing the utility methods

function go(url)
{
window.location = url;
}

function deleteContact(url)
{
var isOK = confirm("Are you sure to delete?");
if(isOK)
{
go(url);
}
}

Step#14: The welcome file index.jsp
<%
response.sendRedirect("viewAllContacts.do");
%>
Step#15: Start the server and point your browser URL to http://localhost:8080/SpringMVCHibernate

 

 

From: http://sivalabs.blogspot.com/2011/04/springmvc3-hibernate-crud-sample.html

 

Published at DZone with permission of Sivaprasadreddy Katamreddy, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Cloves Almeida replied on Mon, 2011/04/04 - 7:52am

Very nice.

Sometimes we forget there are always newcomers to the language and a comprehensive Hello World on the newest technologies are always good.

I'm on the Java EE 6 camp and such a Hello World using JPA, CDI, JSF 2 and JAX-RS should be just as simple or simpler.

David Martin replied on Mon, 2011/04/04 - 11:35am

That's one of the major issue with current Java frameworks : even CRUD apps need to be created from scratch each time... We are in 2011, don't you consider this odd ? Maybe it can be useful for student to learn how it works, but for an enterprise, that's simply not acceptable anymore : Spring Fuse, Spring Roo (or any other initiative adopting the MDA paradigm) should be mandatory (ok, roo is not stable/feature rich enough :) ).

Howard Lewis Ship replied on Mon, 2011/04/04 - 7:20pm in response to: David Martin

Tapestry 5 includes a lot of CRUD support out of the box (easy Hibernate integration, simple transaction management, and complex components such as BeanEditForm) , and this is significantly enhanced by the add-on library Tynamo.

Cloves Almeida replied on Mon, 2011/04/04 - 8:35pm

Not counting the MDD frameworks like OpenXava, for a while, the Seam framework had the seam-gen tool to create a up-and-running app in minutes with minor scaffolding. Grail (like Rails) and Play also has some very nice "fuse" features.

The issue with seam-gen is that it's just a bunch of ingenious ant scripts and has become too complex to evolve. In a few weeks, the new Seam 3 framework will release the SeamForge tool to replace seam-gen. It provides a cleaner architecture so one wil be able to customize the app startup (like init git repo, configure Hudson, apply a standard template, etc.)

Sivaprasadreddy... replied on Tue, 2011/04/05 - 12:04am in response to: Cloves Almeida

Hi Cloves Almeida,

When I tried to learn some frameworks I was struggled with lack of documentation about some small details which took hours to figure it out what exactly the problem is. So here i tried to put all the things(as much as possible)  that need to have a CRUD application. I hope it would be helpful for beginners. :-)

Sivaprasadreddy... replied on Tue, 2011/04/05 - 1:06am in response to: David Martin

Hi David MARTIN,

I partially agree with you about we don't have a standard java web framework that is suitable for building CRUD apps easily. But here I am seeing the problem in a different way.

Is this the problem with Java frameworks or Developers or IDE vendors???

I normally don't write repeated stuff again and again. If I have to start building a new application using Spring+Hibernate (whatever the technologies), first I create a project and configure everything that needs to wire up all the basic things like DataSource, SessionFactory, PropertyPlaceHolder, MessageResourceBundle, ViewResolvers etc which are independent my apllication logic and save it as a Eclipse Project Template. So that for the second time i can just import my existing template start from the things that are specific to my application.For application to application hardly my JDBC configuration, or file names might be changed. But  I agree, this is very very basic way of avoiding redundant work.

Secondly,

Why don't we have an IDE plugin for generating the JSPs, DAOs for the given Domain object.
For a POJO like Contact.java if we have an IDE plugin to generate the DAO, JSPs 90% of the redundant work can be eliminated.If there are such a kind of plugins already please point me to those URLs.

Finally I am feeling like by this time we should have a Java framework specifically designed for CRUD kind of applications. I knew that there are some frameworks like OpenXava, Play etc but I haven't used it yet. Can some one tell me are they good for CRUD?It seems OpenXava is heavily depends on JPA.

Your thoughts on this??

 

Thanks,

Siva

Sivaprasadreddy... replied on Tue, 2011/04/05 - 12:56am in response to: David Martin

Hi David,

I played with SpringRoo sometime back and it looks good for creating basic configuration and stuff. But the JSPs it is generating for scaffolding doesn't look good(for me). For a Pojo using reflection we can generate JSPs like the ones which i wrote by hand. 

Werner Keil replied on Fri, 2011/04/08 - 6:19am in response to: Cloves Almeida

If you take a look at Step#7

The example uses JPA, too. The author hasn't bothered to mention, and in many areas framework vendors tend to keep the JPA, CDI or other Java EE parts hidden too deep in the closet (to make their sometimes not so large portions shine brighter ;-) ) while in fact they actually ARE more or less compliant with JavaEE 5 or 6 all together :-)

Liezel Jane Jandayan replied on Thu, 2011/08/25 - 6:47am

Keith has created a special showcase project for the Spring community to download. It includes extensive examples of the different options for web interaction possible with Spring MVC and the short screencast also demonstrates how to get started with the project.-Jonathan Berkowitz

James Kear replied on Tue, 2011/09/06 - 3:44pm

Now I am going to explain how to write a Simple CRUD application using Spring MVC3, Hibernate and MySQL. Our Application is ContactsManagements where you can view or search contacts, create new contacts, edit or delete existing contacts. hire a programmers

Shoaib Almas replied on Sat, 2012/08/25 - 6:01am

Really nice article on spring web mvc 3.0. I need some guidance on converting this application from Spring-Hibernate to Spring-Jdbc. I am not sure how to hook the jdbcTemplate in ContactsDao in spring config files. Your guidance is appreciated.

Java Forum

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.