Delete database Table through hibernate and Spring

Delete database Table through hibernate and Spring

Hi, I am using Spring,Hibernate and Tapestry to save and also fetch data simultaneously from mysql database.I am facing a problem,whenever i refresh the number of data saved and fetched is repeated all the time.Please give me a solution to get data only once without repetation,or Detete table after data is fetched.

Here is UserManagerImpl code: package tuto.webssh.service.impl;

import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import tuto.webssh.domain.dao.UserDao; import tuto.webssh.domain.model.Info; import tuto.webssh.service.UserManager;

public class UserManagerImpl implements UserManager {

  private final Log logger = LogFactory.getLog(UserManagerImpl.class);
  private UserDao userDao = null;

/**
  * setter to allows spring to inject userDao implementation
  * @param userDao : object (implementation of UserDao interface) to inject.
 */
   public void setUserDao(UserDao userDao) {
      this.userDao = userDao;
    }


public void getSave(Info info) {
   userDao.getSave(info);

}

 public List<Info> toRetrieve() {
   return userDao.getRetrieve();

} }

Here is class to Fetch data: package tuto.webssh.web.pages;

import java.util.List; import tuto.webssh.domain.model.Info; import tuto.webssh.service.UserManager; import org.apache.tapestry.annotations.Inject; import org.apache.tapestry.annotations.Persist; import org.apache.tapestry.annotations.Service;

public class Fetch { @Inject @Service("userManager") private UserManager userManager;

@Persist
private List<Info> info;

 public List<Info> getInfo() {
        fetch();
        return info;
    }

    public void setInfo(List info) {
        this.info = info;
        }

    public void fetch()
    {
        String str="fetched data";
        List<Info> tempInfo = userManager.toRetrieve(); 
        info=tempInfo;
    }

}

Here is UserDaoImpl code: package tuto.webssh.domain.dao.hibernate3; import java.util.List;

import tuto.webssh.domain.model.Info; import tuto.webssh.domain.dao.UserDao; import org.hibernate.Session; import org.hibernate.Criteria; import org.hibernate.Transaction; import org.springframework.dao.DataAccessException; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

public UserDaoImpl() { // TODO Auto-generated constructor stub } public void getSave(Info info) { try{ Session sess = getHibernateTemplate().getSessionFactory().getCurrentSession(); Transaction tx = sess.beginTransaction(); sess.save(info); tx.commit(); }

      catch(DataAccessException e)
      {
          e.printStackTrace();
      }

} public List<Info> getRetrieve(){

            Session  session = getHibernateTemplate().getSessionFactory().getCurrentSession();
             session.beginTransaction();
             Criteria crit = session.createCriteria(Info.class);
             List<Info> info=crit.list();
             return info;    
                            }

}

Here is class for Table(Info) in MySQL database with database name Json: package tuto.webssh.domain.model;

// Generated Feb 23, 2011 5:19:45 PM by Hibernate Tools 3.4.0.CR1

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

/** * Info generated by hbm2java */ @Entity @Table(name = "info", catalog = "json") public class Info implements java.io.Serializable {

private Integer id;
private String names;
private String images;
private String heading;
private String type;

public Info() {
}

public Info(String names, String images, String heading, String type) {
    this.names = names;
    this.images = images;
    this.heading = heading;
    this.type = type;
}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
    return this.id;
}

public void setId(Integer id) {
    this.id = id;
}

@Column(name = "names", nullable = false, length = 25)
public String getNames() {
    return this.names;
}

public void setNames(String names) {
    this.names = names;
}

@Column(name = "images", nullable = false, length = 25)
public String getImages() {
    return this.images;
}

public void setImages(String images) {
    this.images = images;
}

@Column(name = "heading", nullable = false, length = 25)
public String getHeading() {
    return this.heading;
}

public void setHeading(String heading) {
    this.heading = heading;
}

@Column(name = "type", nullable = false, length = 25)
public String getType() {
    return this.type;
}

public void setType(String type) {
    this.type = type;
}
}

This fetch and save is called by index.java and index.html pages to display.

Thank you,
With regards,
Yuvaraj.
View Answers









Related Tutorials/Questions & Answers:
Delete database Table through hibernate and Spring
Delete database Table through hibernate and Spring  Hi, I am using Spring,Hibernate and Tapestry to save and also fetch data simultaneously from... once without repetation,or Detete table after data is fetched. Here
delete row from a table in hibernate
delete row from a table in hibernate  is there method to delete row in a table using hibernate like save(-) to insert row
Advertisements
Delete a Column from a Database Table
Delete a Column from a Database Table   ... to delete a column from a database table. We are not going to create a new table... the already created table in the specific database. Now if we want to delete
delete row from a table using hibernate
delete row from a table using hibernate  //code in java file String hql="delete from CONTACT c where ID=6"; Query query=session.createQuery... [delete from CONTACT] int i=query.executeUpdate
Delete row and column from table through java code
Delete row and column from table through java code... will see how to delete row and column from given table through java code. Java code...' and a table 'stu_info' in same database. Structure of table 'stu_info
how to make JTable to add delete and update sql database table
how to make JTable to add delete and update sql database table  Hello all I want to know how to make JTable to act actively to add delete and update database table. i am struck ed here from long time please help me
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
solution for mapping hibernate and pojos from net beans through database
solution for mapping hibernate and pojos from net beans through database ... application Employee . i am using hibernate to connect to database which i have... database but netbeans is not creating Domain code(.java) Hibernate xml mapping
how to send email list of email address through in database table list
how to send email list of email address through in database table list  package com.com; import java.io.IOException; import java.io.PrintWriter; import java.sql.PreparedStatement; import java.sql.ResultSet; import
How to delete a table in mysql
How to Delete a Table in MySQL       Consider a situation where we need to delete a table from a database.  To delete a table from the database firstly we need
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 Insert Data Delete Data ThanksADS_TO_REPLACE_2
How can I paginate a table which has shown in a div through Ajax in client side without using database
How can I paginate a table which has shown in a div through Ajax in client side without using database   The table is shown by calculation in a PHP... the table
Delete points from database
Delete points from database  I have a polygon on a web page and a delete button. The polygon is saved in the database in one table and in another table, the coordinates of polygon (latitude,longitude) are saved. When I click
Hibernate delete HQL - Hibernate
Hibernate delete HQL  Hi I am trying hibernate tutorial. But delete HQL tutorial not working properly. It gives null pointer exception. Query class has method executeUpate() & not executeUpdate
delete an item from database
delete an item from database  how to delete an item from the database using jsp
Hibernate Delete Query
database using the hibernate. Lets first write a java class to delete a row from... Hibernate Delete Query      ... (DeleteHQLExample.java), which we will delete a row from the insurance table using the query
Delete a Specific Row from a Database Table
Delete a Specific Row from a Database Table   ... from a specific database table. Here is an example with code which provides the facility for deleting specific row in a database table. Sometimes, you want
sqlite database delete row
sqlite database delete row  How to delete row from SQLite Database?    NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM aListDB WHERE id='%@'",details.ids
Delete a Records in Database
from the table. The generalized Syntax  used for delete query in database are as : delete from table name;ADS_TO_REPLACE_1 The above syntax is used to delete... Delete a Records in Database   
Navigation in a database table through jsp
Navigation in a database table through jsp  ... a table named 'stu_info' in the same database through following sql query... in a Database Table </TITLE> </HEAD> <BODY bgcolor="
delete() method of hibernate
delete() method of hibernate  Define the use of delete() method of hibernate? Example
Hibernate criteria delete Example
Hibernate criteria delete Example  How to use the delete criteria in Hibernate? thanks
Deleting All Rows From the database Table
helps us to write on the browser. To delete all the rows from our database table... From the database Table      ... after sometime . Rather than go through with that data its better to delete
Connecting to a database through the Proxy.
Connecting to a database through the Proxy.  Connecting to a database through the Proxy I want to connect to remote database using a program that is running in the local network behind the proxy. Is that possible
delete data from database - SQL
delete data from database  HOw to delete specific data from table> I want to delete one record from database. Thnx  Hi friend, -------------------------------------------- Visit for more information
How properties of a class are mapped to the columns of a database table in Hibernate?
of a database table in Hibernate? Hibernate 5 is very powerful yet flexible ORM... properties to database table Hibernate 5 is mostly using the annotations... to database table. There are two ways you can map Java Object to database table
How properties of a class are mapped to the columns of a database table in Hibernate?
of a database table in Hibernate? Hibernate 5 is very powerful yet flexible ORM... properties to database table Hibernate 5 is mostly using the annotations... to database table. There are two ways you can map Java Object to database table
How properties of a class are mapped to the columns of a database table in Hibernate?
of a database table in Hibernate? Hibernate 5 is very powerful yet flexible ORM... to map Java properties to database table Hibernate 5 is mostly using... to database table. There are two ways you can map Java Object to database table
How properties of a class are mapped to the columns of a database table in Hibernate?
of a database table in Hibernate? Hibernate 5 is very powerful yet flexible ORM... properties to database table Hibernate 5 is mostly using the annotations... to database table. There are two ways you can map Java Object to database table
Use of delete() method in hibernate.
Use of delete() method in hibernate.  Define the use of delete() method of hibernate?   Hibernate provide the facility to delete one row... department0_ where department0_.id=? Hibernate: delete from department where id
Deleting a Table from Database
database. But how we can delete the table using java methods and API. In this section we are describing, how to delete a table from database using java methods... the connection we will delete a table from specific database. If the table
Adding checkbox in table using that delete table rows
Adding checkbox in table using that delete table rows  I need coding for how to add checkbox in table,the table data from database.Using that checkbox select more than than one rows,and using delete button i want to delete
delete query problem - Hibernate
delete query problem  SessionFactory fact = new Configuration... = sess. beginTransaction(); String hql = "delete from STUDENT where name = 'mitha... system properly. STUDENT is not mapped. [delete from STUDENT where name = 'mitha
JDBC Video tutorial - How to delete Data in a MySQL Database?
are not required in the database and there is a requirement to delete the record... to write program in Java for deleting the data in a MySQL database table. We have used the delete statement to delete the data into the table. JDBC allows
PHP WHERE clause example to fetch records from Database Table
the data within the MYSQL database table. You can also fetch the results using... on the MYSQL Server and will fetch the results from the database table employee...) To test the code we are using existing database table. You can create your own
Hibernate delete example program
Hibernate delete example program  How to delete an object in Hibernate? In my program I have to write program to delete the data using Hibernate framework. I want to delete one row of data who's primary key is known to me. What
How to delete objects using Hibernate?
How to delete objects using Hibernate?  Hi, How to delete objects using Hibernate? I want to delete an object (record) in table. Thanks   Hi, Hibernate Session API provides function to delete object. For deleting
spring hibernate
spring hibernate  I need to save registration details in a database table through jsp using spring an hibernate....and the fields in the registration... the following link: http://www.roseindia.net/hibernate/HibernateSpring.shtml
spring hibernate
spring hibernate  I need to save registration details in a database table through jsp using spring an hibernate....and the fields in the registration... the following link: http://www.roseindia.net/hibernate/HibernateSpring.shtml
database through jsp
database through jsp  sir actually i want to retrieve the data from database dynamically.because i dont know how many records... database and display it in html table. <%@ page import="java.sql.*" %> <
Spring MVC and Hibernate with DWR 3 -- Configuration Using MySQL Database
Spring MVC and Hibernate with DWR 3 -- Configuration Using MySQL Database  How to configure Spring MVC and Hibernate with DWR 3, Simple example -- reading a table, editing-deleting and adding new rows
Create a Table in Mysql database through SQL Query in JSP
Create a Table in Mysql database through SQL Query in JSP...; This is detailed java code to connect a jsp page to mysql database and create a table of given... for processing the table creation. 1. welcome_to_database_query.jsp 2.create
hibernate delete query :
hibernate delete query :   Hi, I m using Hibernate 3 + javadb my table is like: CREATE table APP.BIDS ( BID_ID INTEGER NOT NULL... NOT NULL , ITEM_ID INTEGER NOT NULL ) I want to delete a row from table
Migrating sql database to Access through coding
Migrating sql database to Access through coding  How can i migrate SQL database(table) to My access through coding
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse  please help me i have to submit this soon
How to Delete a column and Add a new column to database
How to Delete a column and Add a new column to database   How to Delete a column and Add a new column to database   Hi, The following query is executed for add and delete a column in a table-ADS_TO_REPLACE_1 for drop

Ads