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 SpringDelete 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
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 hibernatedelete 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 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 databaseinsert 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
Delete points from databaseDelete 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 - HibernateHibernate 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
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 rowsqlite
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="
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 - SQLdelete 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
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 rowsAdding 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 - Hibernatedelete 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
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 programHibernate 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 hibernatespring 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 hibernatespring 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 jspdatabase 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.*" %>
<
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