In this section, we will delete a table row from the CATALOG
table. Perform the following steps to accomplish this:
Create a HQL query
String
for theCatalog
instance to delete the table row using the following line of code:String hqlQuery = "from Catalog as catalog WHERE catalog.edition='March-April 2005'";
As in
find.jsp
andupdate.jsp
, getList
forCatalog
instances. As only oneCatalog
instance hasedition
set toMarch-April 2005
, we only need to get the firstCatalog
instance fromList
. To do so, use the following code:Catalog catalog = (Catalog) list.get(0);
Create a
Transaction
object withbeginTransaction()
.Delete the
Catalog
instance from theSession
with thedelete
method, which doesn't delete theCatalog
instance from the database. Invoke thecommit()
method of theTransaction
object to save theSession
state in the database, which deletes the corresponding table row from theCATALOG
table.Optionally, using the following code, output a message to indicate deletion...