Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process Delete database Table through hibernate and Spring
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Yuvaraj
Delete database Table through hibernate and Spring
0 Answer(s)      3 years and 10 months ago
Posted in : Development process


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.

Advertisement
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
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
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
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
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
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
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
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
JSF+SPRING+HIBERNATE - AOP
JSF+SPRING+HIBERNATE  any form builder is available from database table to UI FORM LIKE list ,add,edit,delete and search
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: Insert Data Delete Data Thanks
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
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
spring with hibernate - Spring
spring with hibernate   Hi, I need the sample code for user registration using spring , hibernate with my sql. Please send the code as soon as possible. I need Spring with Hibernate code not struts. Thanks, Valarmathi
spring hibernate spring
spring hibernate spring  why are all the links in the following page broken. http://www.roseindia.net/struts/hibernate-spring/integrate.shtml... the following link: Spring Hibernate Thanks
spring hibernate
spring hibernate  i need to display many fields( fields are in different tables) in a jsp page....how to implement this using spring hibernate  .../hibernate-spring/index.shtml
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
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
spring hibernate - Hibernate
with hibernate?  Hi friend, For solving the problem Spring with Hibernate visit to : http://www.roseindia.net/spring/index.shtml http://www.roseindia.net/struts/hibernate-spring/index.shtml Thanks
spring with hibernate - Spring
spring with hibernate   Hi, I need the sample code for user registration using spring , hibernate with my sql. Please send the code as soon... the following link: http://www.roseindia.net/struts/hibernate-spring/user-registration
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
Struts Hibernate Spring - Hibernate
Struts Hibernate Spring  HI Deepak, This is reddy.i want expamle for struts hibernate spring example.  Hi Friend, Please visit the following link: http://www.roseindia.net/struts/hibernate-spring/index.shtml
 

 

 

DMCA.com