Paginación con DisplayTag & Hibernate error 500 Hola,
Sigo con los problemas, no se solucionan solos. He encontrado un ejemplo de lo que quiero hacer, una paginación cogiendo datos de una query.
Me he basado en un ejemplo de esta web
Solo he modificado el metodo loadData() de ForbesData
Código:
@SuppressWarnings("unchecked")
public ArrayList<ForbesData> loadData() {
ArrayList<ForbesData> userList = new ArrayList<ForbesData>();
Session hibernateSession;
try {
hibernateSession = HibernateUtil.getSessionFactory().openSession();
hibernateSession.beginTransaction();
String queryBusqueda = "FROM forbes";
userList= (ArrayList<ForbesData>) hibernateSession.createQuery(queryBusqueda).list();
} catch (HibernateException e) {
e.printStackTrace();
}
return userList;
}
Original
Código:
public ArrayList<ForbesData> loadData() {
ArrayList<ForbesData> userList = new ArrayList<ForbesData>();
userList.add(new ForbesData(1, "William Gates III", 53, 40.0));
userList.add(new ForbesData(2, "Warren Buffett", 78, 37));
userList.add(new ForbesData(3, "Carlos Slim Helu & family", 69, 35));
userList.add(new ForbesData(4, "Lawrence Ellison", 64, 22.5));
userList.add(new ForbesData(5, "Ingvar Kamprad & family", 83, 22));
userList.add(new ForbesData(6, "Karl Albrecht", 89, 21.5));
userList.add(new ForbesData(7, "Mukesh Ambani", 51, 19.5));
userList.add(new ForbesData(8, "Lakshmi Mittal", 58, 19.3));
userList.add(new ForbesData(9, "Theo Albrecht", 87, 18.8));
userList.add(new ForbesData(10, "Amancio Ortega", 73, 18.3));
userList.add(new ForbesData(11, "Jim Walton", 61, 17.8));
userList.add(new ForbesData(12, "Alice Walton", 59, 17.6));
userList.add(new ForbesData(13, "Christy Walton & family", 54, 17.6));
userList.add(new ForbesData(14, "S Robson Walton", 65, 17.6));
userList.add(new ForbesData(15, "Bernard Arnault", 60, 16.5));
userList.add(new ForbesData(16, "Li Ka-shing", 80, 16.2));
userList.add(new ForbesData(17, "Michael Bloomberg", 67, 16));
userList.add(new ForbesData(18, "Stefan Persson", 61, 14.5));
userList.add(new ForbesData(19, "Charles Koch", 73, 14));
userList.add(new ForbesData(20, "David Koch", 68, 14));
userList.add(new ForbesData(21, "Liliane Bettencourt", 86, 13.4));
userList.add(new ForbesData(22, "Prince Alwaleed Bin Talal Alsaud", 54, 13.3));
return userList;
}
El archivo de mapeo es este el ForbesData.hbn.xml
Código:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 28, 2012 4:05:29 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="net.viralpatel.struts.displaytag.ForbesData" table="forbes" catalog="bbw">
<id name="rank" type="int">
<column name="rank" />
<generator class="assigned" />
</id>
<property name="name" type="string">
<column name="name" length="45" />
</property>
<property name="age" type="int">
<column name="age" length="11" />
</property>
<property name="nombre" type="string">
<column name="nombre" length="15" />
</property>
<property name="netWorth" type="double">
<column name="netWorth" />
</property>
</class>
</hibernate-mapping>
El de configuración de hibernate es hibernate.cfg.xml
Código:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bbw</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class">thread</property>
<!--Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Transaction properties -->
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- Echo all executed SQL to stdout
<property name="show_sql">true</property> -->
<!-- Drop and re-create the database schema on startup
<property name="hbm2ddl.auto">update</property>-->
<mapping resource="ForbesData.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Pongo los script de la base de datos, por si podeis probar
DDL ( en ocasiones se han de cambiar el tipo de comilals no se el porque)
Código:
CREATE TABLE `bbw`.`forbes` (
`rank` int(11) NOT NULL,
`name` varchar(45) NOT NULL,
`age` int(11) NOT NULL,
`networth` double NOT NULL,
PRIMARY KEY (`rank`),
UNIQUE KEY `rank_UNIQUE` (`rank`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$
DML
Código:
INSERT INTO `bbw`.`forbes`
(`rank`,`name`,`age`,`networth`)VALUES(`1`, "William Gates III", 53, 40.0);
(`rank`,`name`,`age`,`networth`)VALUES(`2`, `Warren Buffett`,`78`, `37`);
(`rank`,`name`,`age`,`networth`)VALUES(`3`, `Carlos Slim Helu & family`, `69`, `35`);
(`rank`,`name`,`age`,`networth`)VALUES(`4`, `Lawrence Ellison`,`64`,`22.5`));
(`rank`,`name`,`age`,`networth`)VALUES(`5`, `Ingvar Kamprad & family`,`83`,`22`);
(`rank`,`name`,`age`,`networth`)VALUES(`6`, `Karl Albrecht`, `89`, `21.5`);
(`rank`,`name`,`age`,`networth`)VALUES(`7`, `Mukesh Ambani`, `51`, `19.5`);
(`rank`,`name`,`age`,`networth`)VALUES(`8`, `Lakshmi Mittal`, `58`, `19.3`);
(`rank`,`name`,`age`,`networth`)VALUES(`9`, `Theo Albrecht`, `87`, `18.8`);
(`rank`,`name`,`age`,`networth`)VALUES(`10`, `Amancio Ortega`, `73`, `18.3`);
(`rank`,`name`,`age`,`networth`)VALUES(`11`, `Jim Walton`, `61`, `17.8`);
(`rank`,`name`,`age`,`networth`)VALUES(`12`, `Alice Walton`, `59`, `17.6`);
(`rank`,`name`,`age`,`networth`)VALUES(`13`, `Christy Walton & family`, `54`, `17.6`);
(`rank`,`name`,`age`,`networth`)VALUES(`14`, `S Robson Walton`, `65`, `17.6');
(`rank`,`name`,`age`,`networth`)VALUES(`15`, `Bernard Arnault`, `60`, `16.5`);
(`rank`,`name`,`age`,`networth`)VALUES(`16`, `Li Ka-shing`, `80`, `16.2`);
(`rank`,`name`,`age`,`networth`)VALUES(`17`, `Michael Bloomberg`, `67`, `16`);
(`rank`,`name`,`age`,`networth`)VALUES(`18`, `Stefan Persson`, `61`, `14.5`);
(`rank`,`name`,`age`,`networth`)VALUES(`19`, `Charles Koch`, `73`, `14`);
El error que me da es parecido al anterior, pero se centra en el hibernate y eso que tengo los jar's cargados. Es el siguiente.
Código:
type Informe de Excepción
mensaje javax.servlet.ServletException: La ejecución del Servlet lanzó una excepción
descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.
excepción
org.apache.jasper.JasperException: javax.servlet.ServletException: La ejecución del Servlet lanzó una excepción
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
causa raíz
javax.servlet.ServletException: La ejecución del Servlet lanzó una excepción
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
causa raíz
java.lang.NoClassDefFoundError: org/hibernate/HibernateException
net.viralpatel.struts.displaytag.UserAction.execute(UserAction.java:17)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(
Las librerias son las de la imagen
Os doy las gracias de antemano. |