You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by david b <en...@mail.com> on 2006/02/25 17:45:16 UTC
hibernate with tapestry
Hello,
I starting to make a simple application using Tapestry 3.1 I have tomcat 5.5.7 using JDK 1.5.
My next step was to integrate a call to hibernate but this part is not working yet.
Going to this url: http://localhost:8080//firstApp/app?service=page/Login
I am getting this error: org.apache.tapestry.ApplicationRuntimeException
Unable to invoke method doLogin on com.entercite.finance.model.abstrt.LoginComponent$Enhance_0@b23d12[Login]: null
java.lang.reflect.InvocationTargetException
java.lang.NoClassDefFoundError
org/dom4j/io/SAXReader
Stack Trace:
* org.hibernate.util.XMLHelper.createSAXReader(XMLHelper.java:35)
* org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1218)
* org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
* org.hibernate.cfg.Configuration.configure(Configuration.java:1148)
* com.entercite.finance.persistence.HibernateFactory.buildSessionFactory(HibernateFactory.java:26)
* com.entercite.finance.persistence.abstrt.AbstractDao.<init>(AbstractDao.java:21)
* com.entercite.finance.persistence.LoginDaoImpl.<init>(LoginDaoImpl.java:12)
* com.entercite.finance.model.abstrt.LoginComponent.isValidLogin(LoginComponent.java:52)
* com.entercite.finance.model.abstrt.LoginComponent.doLogin(LoginComponent.java:35)
Here is the development structure and code.
C:\
|-main
|
|-HelloTapestry
| |-ant
| |--build.bat
|
|-build
| |-log
| |-WEB-INF
| |-web.xml
| |-classes
| | |-hibernate.cfg.xml
| |-lib (Copy of all from lib)
| |-web
| |-Home.html
|
|-Config
| |-hibernate.cfg.xml
|
|-deploy (firstApp.war)
|
|-lib
| |-tapestry-3.0.jar, tapestry-contrib-3.0.jar, ognl-2.6.3.jar, log4j-1.2.11.jar
| |-A bunch of apache commons jars
| |-jakarta-oro-2.0.6.jar, javassist-2.5.1.jar, spring.jar, hibernate3.jar, bsf-2.3.0.jar
|
|-src
|
|-context
| |-Login.html
| |-login.page
| |-Main.html
| |
| |-WEB-INF
| |-web.xml
|-java
|-com
|-entercite
|-finance
|
|-model
| |-Login.java
| |-abstrt
| |-LoginComponent.java
|-persistence
|-HibernateFactory.java
|-LoginDaoImpl.java
|
|-abstrt
| |-AbstractDao.java
|-exception
| |-DataAccessLayerException.java
|-intrface
|-ILoginDao.java
web.xml
----------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Tutorial: Test</display-name>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/app</url-pattern>
</servlet-mapping>
</web-app>
----------------------------------------------------------------------------
login.html
----------------------------------------------------------------------------
<html jwcid="@Shell" title="Login">
<body>
<span jwcid="@Conditional" condition="ognl:message">
<font color="red">
<span jwcid="@Insert" value="ognl:message"> Error Message </span>
</font>
</span>
<p/>
<form jwcid="@Form" listener="ognl:listeners.loginComponent">
<table>
<tr>
<th>User Name:</th>
<td>
<input type="text" jwcid="@TextField"
value="ognl:login.userName"
size="30"/>
</td>
</tr>
<tr>
<th>Password:</th>
<td>
<input type="password" jwcid="@TextField"
value="ognl:login.password"
hidden="ognl:true"
size="30"/>
</td>
</tr>
<tr>
<td><input type="submit" value="Login"/></td>
</tr>
</table>
</form>
<hr/>
<p><a href="#" jwcid="@PageLink" page="Home">Return to Home page</a>.</p>
</body>
</html>
----------------------------------------------------------------------------
Login.page
----------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<page-specification class="com.entercite.finance.model.abstrt.LoginComponent">
<property-specification name="message" type="java.lang.String"/>
<property-specification name="login" type="com.entercite.finance.model.Login"/>
</page-specification>
----------------------------------------------------------------------------
login
----------------------------------------------------------------------------
package com.entercite.finance.model;
import java.util.*;
public class Login {
private Integer loginId = new Integer(0);
private String userName = "";
private String password = "";
private Integer permissionType = new Integer(0);
public void setLoginId(Integer loginId){ this.loginId = loginId; }
public Integer getLoginId(){return this.loginId;}
public void setUserName(String userName){ this.userName = userName;}
public String getUserName(){return this.userName;}
public void setPassword(String password){this.password = password;}
public String getPassword(){return this.password;}
public void setPermissionType(Integer permissionType){this.permissionType = permissionType;}
public Integer getPermissionType(){return this.permissionType;}
}
----------------------------------------------------------------------------
LoginComponent
----------------------------------------------------------------------------
package com.entercite.finance.model.abstrt;
import com.entercite.finance.model.Login;
import com.entercite.finance.persistence.intrface.*;
import com.entercite.finance.persistence.LoginDaoImpl;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.html.BasePage;
/**
*
*/
public abstract class LoginComponent extends BasePage {
private Login login = new Login();
public abstract void setMessage(String message);
public LoginComponent() { }
public Login getLogin(){ return this.login; };
public void setLogin(Login login){ this.login = login; };
public void setUserName(String userName){ this.getLogin().setUserName(userName); }
public String getUserName(){ return this.getLogin().getUserName(); }
public void setPassword(String password){ this.getLogin().setPassword(password); }
public String getPassword(){ return this.getLogin().getPassword(); }
public void doLogin(IRequestCycle cycle) {
String u = this.getLogin().getUserName();
String p = this.getLogin().getPassword();
if(isValidLogin(u,p) ) {
System.out.println("push to main");
cycle.activate("Main");
} else {
setMessage("Invalid user name or password.");
}
}
private boolean isValidLogin(String userName, String password) {
System.out.println("Attempt");
com.entercite.finance.persistence.intrface.ILoginDao ldi =
new com.entercite.finance.persistence.LoginDaoImpl(); <-----(call this impl)
System.out.println("Attempt 1");
this.login = ldi.find(userName, password);
System.out.println("Attempt 2");
if(login != null){
System.out.println("Attempt 3");
return true;
} else {
System.out.println("Attempt 4");
return false;
}
}
}
ILoginDao
----------------------------------------------------------------------------
package com.entercite.finance.persistence.intrface;
import java.util.*;
import com.entercite.finance.model.*;
import com.entercite.finance.persistence.exception.*;
public interface ILoginDao {
public void create(Login login) throws DataAccessLayerException;
public Login find(String name, String password) throws DataAccessLayerException;
}
LoginDaoImpl
----------------------------------------------------------------------------
package com.entercite.finance.persistence;
import org.hibernate.HibernateException;
import com.entercite.finance.persistence.abstrt.AbstractDao;
import com.entercite.finance.model.*;
import com.entercite.finance.persistence.intrface.ILoginDao;
import com.entercite.finance.persistence.exception.*;
import java.util.*;
public class LoginDaoImpl extends AbstractDao implements ILoginDao {
<---THEN IT USES THE SUPER CONSTRUCTOR--->
public void create(Login login) throws DataAccessLayerException {
saveOrUpdate(login);
}
public Login find(String name, String password) throws DataAccessLayerException {
return (Login)find(Login.class, name, password);
}
}
AbstractDao
----------------------------------------------------------------------------
package com.entercite.finance.persistence.abstrt;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import java.util.List;
import com.entercite.finance.persistence.*;
import com.entercite.finance.persistence.exception.*;
public abstract class AbstractDao {
private Session session;
private Transaction tx;
public AbstractDao() {
HibernateFactory.buildSessionFactory(); <----(Which calls this)
}
protected void saveOrUpdate(Object obj){
try {
startOperation();
session.saveOrUpdate(obj);
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
}
}
protected void delete(Object obj) {
try {
startOperation();
session.delete(obj);
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
}
}
protected Object find(Class clazz, Integer id){
Object obj = null;
try {
startOperation();
obj = session.load(clazz, id);
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
}
return obj;
}
protected Object find(Class clazz, String value1, String value2){
Object obj = null;
try {
startOperation();
Query query = session.createQuery(
"from " + clazz.getName() +
" where login = " + value1 +
" and password = " + value2 );
obj = query.uniqueResult();
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
}
return obj;
}
/**
* Find all class from one table using the following object
*
*@param Class - this is the table to load data from
*@param Integer - the id to use in the where clause
*
*@return List - containing all objects you were looking for
*/
protected List findAll(Class clazz, Integer id) {
List objects = null;
try {
startOperation();
Query query = session.createQuery("from " + clazz.getName() + " where id = " + id );
objects = query.list();
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
}
return objects;
}
protected void handleException(HibernateException e) throws DataAccessLayerException {
HibernateFactory.rollback(tx);
throw new DataAccessLayerException(e);
}
protected void startOperation() throws HibernateException {
session = HibernateFactory.openSession();
tx = session.beginTransaction();
}
}
HibernateFactory
----------------------------------------------------------------------------
package com.entercite.finance.persistence;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
public class HibernateFactory {
private static SessionFactory sessionFactory;
private static Log log = LogFactory.getLog(HibernateFactory.class);
public static SessionFactory buildSessionFactory() throws HibernateException {
System.out.println("bsf 1");
if(sessionFactory != null){
closeFactory();
}
System.out.println("bsf 2");
Configuration configuration = new Configuration();
System.out.println("bsf 3");
sessionFactory = configuration.configure().buildSessionFactory(); <---IT PUKES HERE IT APPEARS>
System.out.println("bsf 4");
return sessionFactory;
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session openSession() throws HibernateException {
return sessionFactory.openSession();
}
public static void closeFactory() {
if (sessionFactory != null) {
try {
sessionFactory.close();
} catch (HibernateException ignored) {
log.error("Couldn't close SessionFactory", ignored);
}
}
}
public static void close(Session session) {
if (session != null) {
try {
session.close();
} catch (HibernateException ignored) {
log.error("Couldn't close Session", ignored);
}
}
}
public static void rollback(Transaction tx) {
try {
if (tx != null) {
tx.rollback();
}
} catch (HibernateException ignored) {
log.error("Couldn't rollback Transaction", ignored);
}
}
}
hibernate.cfg.xml
----------------------------------------------------------------------------
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.password">xxx</property>
<property name="connection.url">//localhost:3306/budget</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/entercite/finance/model/Login.hbm.xml"/>
</session-factory>
</hibernate-configuration>
--
___________________________________________________
Play 100s of games for FREE! http://games.mail.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: hibernate with tapestry
Posted by David Benoff <db...@gmail.com>.
david b <entercite <at> mail.com> writes:
> java.lang.NoClassDefFoundError
> org/dom4j/io/SAXReader
This is a Hibernate issue. You are missing Dom4j in your web-inf/lib folder.
Put the jar in there (I have dom4j-1.6.jar) and you won't get this.
You are probably also missing other jars as well. Read the stack trace to
identify the missing class.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: hibernate with tapestry
Posted by Konstantin Ignatyev <kg...@yahoo.com>.
Sure, and ask there about Hibernate.....
Ron Piterman <rp...@gmx.net> wrote: damn, and I thought this is a tapestry mailing list...
but I guess I must look for tapestry help at cayene mailing list... *g*
Ron
Konstantin Ignatyev
PS: If this is a typical day on planet earth, humans will add fifteen million tons of carbon to the atmosphere, destroy 115 square miles of tropical rainforest, create seventy-two miles of desert, eliminate between forty to one hundred species, erode seventy-one million tons of topsoil, add 2,700 tons of CFCs to the stratosphere, and increase their population by 263,000
Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools. New York: State University of New York Press, 1997: (4) (5) (p.206)
RE: hibernate with tapestry
Posted by James Carman <ja...@carmanconsulting.com>.
Didn't someone answer your question? I thought they told you to include
dom4j.jar in the WEB-INF/lib directory to fix this.
-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Ron Piterman
Sent: Sunday, February 26, 2006 6:34 PM
To: tapestry-user@jakarta.apache.org
Subject: Re: hibernate with tapestry
damn, and I thought this is a tapestry mailing list...
but I guess I must look for tapestry help at cayene mailing list... *g*
Ron
david b wrote:
> Hello,
>
> I starting to make a simple application using Tapestry 3.1 I have tomcat
5.5.7 using JDK 1.5.
> My next step was to integrate a call to hibernate but this part is not
working yet.
>
> Going to this url: http://localhost:8080//firstApp/app?service=page/Login
>
> I am getting this error: org.apache.tapestry.ApplicationRuntimeException
> Unable to invoke method doLogin on
com.entercite.finance.model.abstrt.LoginComponent$Enhance_0@b23d12[Login]:
null
>
> java.lang.reflect.InvocationTargetException
> java.lang.NoClassDefFoundError
> org/dom4j/io/SAXReader
>
> Stack Trace:
> * org.hibernate.util.XMLHelper.createSAXReader(XMLHelper.java:35)
> * org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1218)
> * org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
> * org.hibernate.cfg.Configuration.configure(Configuration.java:1148)
> *
com.entercite.finance.persistence.HibernateFactory.buildSessionFactory(Hiber
nateFactory.java:26)
> *
com.entercite.finance.persistence.abstrt.AbstractDao.<init>(AbstractDao.java
:21)
> *
com.entercite.finance.persistence.LoginDaoImpl.<init>(LoginDaoImpl.java:12)
> *
com.entercite.finance.model.abstrt.LoginComponent.isValidLogin(LoginComponen
t.java:52)
> *
com.entercite.finance.model.abstrt.LoginComponent.doLogin(LoginComponent.jav
a:35)
>
> Here is the development structure and code.
>
> C:\
> |-main
> |
> |-HelloTapestry
> | |-ant
> | |--build.bat
> |
> |-build
> | |-log
> | |-WEB-INF
> | |-web.xml
> | |-classes
> | | |-hibernate.cfg.xml
> | |-lib (Copy of all from lib)
> | |-web
> | |-Home.html
> |
> |-Config
> | |-hibernate.cfg.xml
> |
> |-deploy (firstApp.war)
> |
> |-lib
> | |-tapestry-3.0.jar, tapestry-contrib-3.0.jar, ognl-2.6.3.jar,
log4j-1.2.11.jar
> | |-A bunch of apache commons jars
> | |-jakarta-oro-2.0.6.jar, javassist-2.5.1.jar, spring.jar,
hibernate3.jar, bsf-2.3.0.jar
> |
> |-src
> |
> |-context
> | |-Login.html
> | |-login.page
> | |-Main.html
> | |
> | |-WEB-INF
> | |-web.xml
> |-java
> |-com
> |-entercite
> |-finance
> |
> |-model
> | |-Login.java
> | |-abstrt
> | |-LoginComponent.java
> |-persistence
> |-HibernateFactory.java
> |-LoginDaoImpl.java
> |
> |-abstrt
> | |-AbstractDao.java
> |-exception
> | |-DataAccessLayerException.java
> |-intrface
> |-ILoginDao.java
>
>
> web.xml
>
----------------------------------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app
> PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd">
>
> <web-app>
> <display-name>Tutorial: Test</display-name>
> <servlet>
> <servlet-name>app</servlet-name>
> <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
> <load-on-startup>0</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>app</servlet-name>
> <url-pattern>/app</url-pattern>
> </servlet-mapping>
> </web-app>
>
>
----------------------------------------------------------------------------
>
> login.html
>
----------------------------------------------------------------------------
> <html jwcid="@Shell" title="Login">
> <body>
>
> <span jwcid="@Conditional" condition="ognl:message">
> <font color="red">
> <span jwcid="@Insert" value="ognl:message"> Error Message </span>
> </font>
> </span>
>
> <p/>
>
> <DEFANGED_form jwcid="@Form" listener="ognl:listeners.loginComponent">
> <table>
> <tr>
> <th>User Name:</th>
> <td>
> <input type="text" jwcid="@TextField"
> value="ognl:login.userName"
> size="30"/>
> </td>
> </tr>
> <tr>
> <th>Password:</th>
> <td>
> <input type="password" jwcid="@TextField"
> value="ognl:login.password"
> hidden="ognl:true"
> size="30"/>
> </td>
> </tr>
> <tr>
> <td><input type="submit" value="Login"/></td>
> </tr>
> </table>
> </form>
>
> <hr/>
> <p><a href="#" jwcid="@PageLink" page="Home">Return to Home page</a>.</p>
> </body>
> </html>
>
----------------------------------------------------------------------------
>
> Login.page
>
----------------------------------------------------------------------------
> <?xml version="1.0"?>
> <!DOCTYPE page-specification PUBLIC
> "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
> "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
>
> <page-specification
class="com.entercite.finance.model.abstrt.LoginComponent">
> <property-specification name="message" type="java.lang.String"/>
> <property-specification name="login"
type="com.entercite.finance.model.Login"/>
> </page-specification>
>
----------------------------------------------------------------------------
>
> login
>
----------------------------------------------------------------------------
> package com.entercite.finance.model;
> import java.util.*;
>
> public class Login {
> private Integer loginId = new Integer(0);
> private String userName = "";
> private String password = "";
> private Integer permissionType = new Integer(0);
>
> public void setLoginId(Integer loginId){ this.loginId = loginId; }
> public Integer getLoginId(){return this.loginId;}
>
> public void setUserName(String userName){ this.userName = userName;}
> public String getUserName(){return this.userName;}
>
> public void setPassword(String password){this.password = password;}
> public String getPassword(){return this.password;}
>
> public void setPermissionType(Integer
permissionType){this.permissionType = permissionType;}
> public Integer getPermissionType(){return this.permissionType;}
> }
>
----------------------------------------------------------------------------
>
>
> LoginComponent
>
----------------------------------------------------------------------------
> package com.entercite.finance.model.abstrt;
>
> import com.entercite.finance.model.Login;
> import com.entercite.finance.persistence.intrface.*;
> import com.entercite.finance.persistence.LoginDaoImpl;
>
> import org.apache.tapestry.IRequestCycle;
> import org.apache.tapestry.html.BasePage;
>
> /**
> *
> */
> public abstract class LoginComponent extends BasePage {
>
> private Login login = new Login();
> public abstract void setMessage(String message);
>
> public LoginComponent() { }
>
> public Login getLogin(){ return this.login; };
> public void setLogin(Login login){ this.login = login; };
>
> public void setUserName(String userName){
this.getLogin().setUserName(userName); }
> public String getUserName(){ return this.getLogin().getUserName(); }
>
> public void setPassword(String password){
this.getLogin().setPassword(password); }
> public String getPassword(){ return this.getLogin().getPassword(); }
>
> public void doLogin(IRequestCycle cycle) {
>
> String u = this.getLogin().getUserName();
> String p = this.getLogin().getPassword();
>
> if(isValidLogin(u,p) ) {
> System.out.println("push to main");
> cycle.activate("Main");
> } else {
> setMessage("Invalid user name or password.");
> }
> }
>
> private boolean isValidLogin(String userName, String password) {
> System.out.println("Attempt");
> com.entercite.finance.persistence.intrface.ILoginDao ldi =
> new com.entercite.finance.persistence.LoginDaoImpl();
<-----(call this impl)
> System.out.println("Attempt 1");
> this.login = ldi.find(userName, password);
> System.out.println("Attempt 2");
> if(login != null){
> System.out.println("Attempt 3");
> return true;
>
> } else {
> System.out.println("Attempt 4");
> return false;
> }
> }
> }
>
> ILoginDao
>
----------------------------------------------------------------------------
> package com.entercite.finance.persistence.intrface;
> import java.util.*;
> import com.entercite.finance.model.*;
> import com.entercite.finance.persistence.exception.*;
>
> public interface ILoginDao {
> public void create(Login login) throws DataAccessLayerException;
> public Login find(String name, String password) throws
DataAccessLayerException;
> }
>
>
> LoginDaoImpl
>
----------------------------------------------------------------------------
> package com.entercite.finance.persistence;
>
> import org.hibernate.HibernateException;
>
> import com.entercite.finance.persistence.abstrt.AbstractDao;
> import com.entercite.finance.model.*;
> import com.entercite.finance.persistence.intrface.ILoginDao;
> import com.entercite.finance.persistence.exception.*;
>
> import java.util.*;
>
> public class LoginDaoImpl extends AbstractDao implements ILoginDao {
>
> <---THEN IT USES THE SUPER CONSTRUCTOR--->
>
> public void create(Login login) throws DataAccessLayerException {
> saveOrUpdate(login);
> }
>
> public Login find(String name, String password) throws
DataAccessLayerException {
> return (Login)find(Login.class, name, password);
> }
> }
>
>
> AbstractDao
>
----------------------------------------------------------------------------
> package com.entercite.finance.persistence.abstrt;
>
> import org.hibernate.HibernateException;
> import org.hibernate.Query;
> import org.hibernate.Session;
> import org.hibernate.Transaction;
>
> import java.util.List;
>
> import com.entercite.finance.persistence.*;
> import com.entercite.finance.persistence.exception.*;
>
> public abstract class AbstractDao {
>
> private Session session;
> private Transaction tx;
>
> public AbstractDao() {
>
> HibernateFactory.buildSessionFactory(); <----(Which calls this)
> }
>
> protected void saveOrUpdate(Object obj){
>
> try {
> startOperation();
> session.saveOrUpdate(obj);
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> }
>
> protected void delete(Object obj) {
>
> try {
> startOperation();
> session.delete(obj);
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> }
>
> protected Object find(Class clazz, Integer id){
>
> Object obj = null;
>
> try {
> startOperation();
> obj = session.load(clazz, id);
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> return obj;
>
> }
>
> protected Object find(Class clazz, String value1, String value2){
>
> Object obj = null;
>
> try {
> startOperation();
> Query query = session.createQuery(
> "from " + clazz.getName() +
> " where login = " + value1 +
> " and password = " + value2 );
>
> obj = query.uniqueResult();
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> return obj;
>
> }
>
>
> /**
> * Find all class from one table using the following object
> *
> *@param Class - this is the table to load data from
> *@param Integer - the id to use in the where clause
> *
> *@return List - containing all objects you were looking for
> */
> protected List findAll(Class clazz, Integer id) {
>
> List objects = null;
>
> try {
>
> startOperation();
> Query query = session.createQuery("from " + clazz.getName() +
" where id = " + id );
> objects = query.list();
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> return objects;
>
> }
>
> protected void handleException(HibernateException e) throws
DataAccessLayerException {
> HibernateFactory.rollback(tx);
> throw new DataAccessLayerException(e);
>
> }
>
> protected void startOperation() throws HibernateException {
> session = HibernateFactory.openSession();
> tx = session.beginTransaction();
>
> }
> }
>
>
>
> HibernateFactory
>
----------------------------------------------------------------------------
> package com.entercite.finance.persistence;
>
> import org.hibernate.SessionFactory;
> import org.hibernate.Session;
> import org.hibernate.Transaction;
> import org.hibernate.HibernateException;
> import org.hibernate.cfg.Configuration;
>
> import org.apache.commons.logging.LogFactory;
> import org.apache.commons.logging.Log;
>
> public class HibernateFactory {
>
> private static SessionFactory sessionFactory;
> private static Log log = LogFactory.getLog(HibernateFactory.class);
>
> public static SessionFactory buildSessionFactory() throws
HibernateException {
>
> System.out.println("bsf 1");
> if(sessionFactory != null){
> closeFactory();
> }
> System.out.println("bsf 2");
> Configuration configuration = new Configuration();
> System.out.println("bsf 3");
> sessionFactory = configuration.configure().buildSessionFactory();
<---IT PUKES HERE IT APPEARS>
> System.out.println("bsf 4");
>
> return sessionFactory;
> }
>
> public static SessionFactory getSessionFactory() {
> return sessionFactory;
> }
>
> public static Session openSession() throws HibernateException {
> return sessionFactory.openSession();
> }
>
> public static void closeFactory() {
> if (sessionFactory != null) {
> try {
> sessionFactory.close();
> } catch (HibernateException ignored) {
> log.error("Couldn't close SessionFactory", ignored);
> }
> }
> }
>
> public static void close(Session session) {
> if (session != null) {
> try {
> session.close();
> } catch (HibernateException ignored) {
> log.error("Couldn't close Session", ignored);
> }
> }
> }
>
> public static void rollback(Transaction tx) {
> try {
> if (tx != null) {
> tx.rollback();
> }
> } catch (HibernateException ignored) {
> log.error("Couldn't rollback Transaction", ignored);
> }
> }
> }
>
>
> hibernate.cfg.xml
>
----------------------------------------------------------------------------
> <!DOCTYPE hibernate-configuration PUBLIC
> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
>
> <hibernate-configuration>
> <session-factory>
>
> <property name="connection.username">root</property>
> <property name="connection.password">xxx</property>
> <property name="connection.url">//localhost:3306/budget</property>
> <property
name="connection.driver_class">com.mysql.jdbc.Driver</property>
> <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
>
> <mapping resource="com/entercite/finance/model/Login.hbm.xml"/>
>
> </session-factory>
> </hibernate-configuration>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: hibernate with tapestry
Posted by Ron Piterman <rp...@gmx.net>.
damn, and I thought this is a tapestry mailing list...
but I guess I must look for tapestry help at cayene mailing list... *g*
Ron
david b wrote:
> Hello,
>
> I starting to make a simple application using Tapestry 3.1 I have tomcat 5.5.7 using JDK 1.5.
> My next step was to integrate a call to hibernate but this part is not working yet.
>
> Going to this url: http://localhost:8080//firstApp/app?service=page/Login
>
> I am getting this error: org.apache.tapestry.ApplicationRuntimeException
> Unable to invoke method doLogin on com.entercite.finance.model.abstrt.LoginComponent$Enhance_0@b23d12[Login]: null
>
> java.lang.reflect.InvocationTargetException
> java.lang.NoClassDefFoundError
> org/dom4j/io/SAXReader
>
> Stack Trace:
> * org.hibernate.util.XMLHelper.createSAXReader(XMLHelper.java:35)
> * org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1218)
> * org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
> * org.hibernate.cfg.Configuration.configure(Configuration.java:1148)
> * com.entercite.finance.persistence.HibernateFactory.buildSessionFactory(HibernateFactory.java:26)
> * com.entercite.finance.persistence.abstrt.AbstractDao.<init>(AbstractDao.java:21)
> * com.entercite.finance.persistence.LoginDaoImpl.<init>(LoginDaoImpl.java:12)
> * com.entercite.finance.model.abstrt.LoginComponent.isValidLogin(LoginComponent.java:52)
> * com.entercite.finance.model.abstrt.LoginComponent.doLogin(LoginComponent.java:35)
>
> Here is the development structure and code.
>
> C:\
> |-main
> |
> |-HelloTapestry
> | |-ant
> | |--build.bat
> |
> |-build
> | |-log
> | |-WEB-INF
> | |-web.xml
> | |-classes
> | | |-hibernate.cfg.xml
> | |-lib (Copy of all from lib)
> | |-web
> | |-Home.html
> |
> |-Config
> | |-hibernate.cfg.xml
> |
> |-deploy (firstApp.war)
> |
> |-lib
> | |-tapestry-3.0.jar, tapestry-contrib-3.0.jar, ognl-2.6.3.jar, log4j-1.2.11.jar
> | |-A bunch of apache commons jars
> | |-jakarta-oro-2.0.6.jar, javassist-2.5.1.jar, spring.jar, hibernate3.jar, bsf-2.3.0.jar
> |
> |-src
> |
> |-context
> | |-Login.html
> | |-login.page
> | |-Main.html
> | |
> | |-WEB-INF
> | |-web.xml
> |-java
> |-com
> |-entercite
> |-finance
> |
> |-model
> | |-Login.java
> | |-abstrt
> | |-LoginComponent.java
> |-persistence
> |-HibernateFactory.java
> |-LoginDaoImpl.java
> |
> |-abstrt
> | |-AbstractDao.java
> |-exception
> | |-DataAccessLayerException.java
> |-intrface
> |-ILoginDao.java
>
>
> web.xml
> ----------------------------------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app
> PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd">
>
> <web-app>
> <display-name>Tutorial: Test</display-name>
> <servlet>
> <servlet-name>app</servlet-name>
> <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
> <load-on-startup>0</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>app</servlet-name>
> <url-pattern>/app</url-pattern>
> </servlet-mapping>
> </web-app>
>
> ----------------------------------------------------------------------------
>
> login.html
> ----------------------------------------------------------------------------
> <html jwcid="@Shell" title="Login">
> <body>
>
> <span jwcid="@Conditional" condition="ognl:message">
> <font color="red">
> <span jwcid="@Insert" value="ognl:message"> Error Message </span>
> </font>
> </span>
>
> <p/>
>
> <form jwcid="@Form" listener="ognl:listeners.loginComponent">
> <table>
> <tr>
> <th>User Name:</th>
> <td>
> <input type="text" jwcid="@TextField"
> value="ognl:login.userName"
> size="30"/>
> </td>
> </tr>
> <tr>
> <th>Password:</th>
> <td>
> <input type="password" jwcid="@TextField"
> value="ognl:login.password"
> hidden="ognl:true"
> size="30"/>
> </td>
> </tr>
> <tr>
> <td><input type="submit" value="Login"/></td>
> </tr>
> </table>
> </form>
>
> <hr/>
> <p><a href="#" jwcid="@PageLink" page="Home">Return to Home page</a>.</p>
> </body>
> </html>
> ----------------------------------------------------------------------------
>
> Login.page
> ----------------------------------------------------------------------------
> <?xml version="1.0"?>
> <!DOCTYPE page-specification PUBLIC
> "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
> "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
>
> <page-specification class="com.entercite.finance.model.abstrt.LoginComponent">
> <property-specification name="message" type="java.lang.String"/>
> <property-specification name="login" type="com.entercite.finance.model.Login"/>
> </page-specification>
> ----------------------------------------------------------------------------
>
> login
> ----------------------------------------------------------------------------
> package com.entercite.finance.model;
> import java.util.*;
>
> public class Login {
> private Integer loginId = new Integer(0);
> private String userName = "";
> private String password = "";
> private Integer permissionType = new Integer(0);
>
> public void setLoginId(Integer loginId){ this.loginId = loginId; }
> public Integer getLoginId(){return this.loginId;}
>
> public void setUserName(String userName){ this.userName = userName;}
> public String getUserName(){return this.userName;}
>
> public void setPassword(String password){this.password = password;}
> public String getPassword(){return this.password;}
>
> public void setPermissionType(Integer permissionType){this.permissionType = permissionType;}
> public Integer getPermissionType(){return this.permissionType;}
> }
> ----------------------------------------------------------------------------
>
>
> LoginComponent
> ----------------------------------------------------------------------------
> package com.entercite.finance.model.abstrt;
>
> import com.entercite.finance.model.Login;
> import com.entercite.finance.persistence.intrface.*;
> import com.entercite.finance.persistence.LoginDaoImpl;
>
> import org.apache.tapestry.IRequestCycle;
> import org.apache.tapestry.html.BasePage;
>
> /**
> *
> */
> public abstract class LoginComponent extends BasePage {
>
> private Login login = new Login();
> public abstract void setMessage(String message);
>
> public LoginComponent() { }
>
> public Login getLogin(){ return this.login; };
> public void setLogin(Login login){ this.login = login; };
>
> public void setUserName(String userName){ this.getLogin().setUserName(userName); }
> public String getUserName(){ return this.getLogin().getUserName(); }
>
> public void setPassword(String password){ this.getLogin().setPassword(password); }
> public String getPassword(){ return this.getLogin().getPassword(); }
>
> public void doLogin(IRequestCycle cycle) {
>
> String u = this.getLogin().getUserName();
> String p = this.getLogin().getPassword();
>
> if(isValidLogin(u,p) ) {
> System.out.println("push to main");
> cycle.activate("Main");
> } else {
> setMessage("Invalid user name or password.");
> }
> }
>
> private boolean isValidLogin(String userName, String password) {
> System.out.println("Attempt");
> com.entercite.finance.persistence.intrface.ILoginDao ldi =
> new com.entercite.finance.persistence.LoginDaoImpl(); <-----(call this impl)
> System.out.println("Attempt 1");
> this.login = ldi.find(userName, password);
> System.out.println("Attempt 2");
> if(login != null){
> System.out.println("Attempt 3");
> return true;
>
> } else {
> System.out.println("Attempt 4");
> return false;
> }
> }
> }
>
> ILoginDao
> ----------------------------------------------------------------------------
> package com.entercite.finance.persistence.intrface;
> import java.util.*;
> import com.entercite.finance.model.*;
> import com.entercite.finance.persistence.exception.*;
>
> public interface ILoginDao {
> public void create(Login login) throws DataAccessLayerException;
> public Login find(String name, String password) throws DataAccessLayerException;
> }
>
>
> LoginDaoImpl
> ----------------------------------------------------------------------------
> package com.entercite.finance.persistence;
>
> import org.hibernate.HibernateException;
>
> import com.entercite.finance.persistence.abstrt.AbstractDao;
> import com.entercite.finance.model.*;
> import com.entercite.finance.persistence.intrface.ILoginDao;
> import com.entercite.finance.persistence.exception.*;
>
> import java.util.*;
>
> public class LoginDaoImpl extends AbstractDao implements ILoginDao {
>
> <---THEN IT USES THE SUPER CONSTRUCTOR--->
>
> public void create(Login login) throws DataAccessLayerException {
> saveOrUpdate(login);
> }
>
> public Login find(String name, String password) throws DataAccessLayerException {
> return (Login)find(Login.class, name, password);
> }
> }
>
>
> AbstractDao
> ----------------------------------------------------------------------------
> package com.entercite.finance.persistence.abstrt;
>
> import org.hibernate.HibernateException;
> import org.hibernate.Query;
> import org.hibernate.Session;
> import org.hibernate.Transaction;
>
> import java.util.List;
>
> import com.entercite.finance.persistence.*;
> import com.entercite.finance.persistence.exception.*;
>
> public abstract class AbstractDao {
>
> private Session session;
> private Transaction tx;
>
> public AbstractDao() {
>
> HibernateFactory.buildSessionFactory(); <----(Which calls this)
> }
>
> protected void saveOrUpdate(Object obj){
>
> try {
> startOperation();
> session.saveOrUpdate(obj);
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> }
>
> protected void delete(Object obj) {
>
> try {
> startOperation();
> session.delete(obj);
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> }
>
> protected Object find(Class clazz, Integer id){
>
> Object obj = null;
>
> try {
> startOperation();
> obj = session.load(clazz, id);
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> return obj;
>
> }
>
> protected Object find(Class clazz, String value1, String value2){
>
> Object obj = null;
>
> try {
> startOperation();
> Query query = session.createQuery(
> "from " + clazz.getName() +
> " where login = " + value1 +
> " and password = " + value2 );
>
> obj = query.uniqueResult();
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> return obj;
>
> }
>
>
> /**
> * Find all class from one table using the following object
> *
> *@param Class - this is the table to load data from
> *@param Integer - the id to use in the where clause
> *
> *@return List - containing all objects you were looking for
> */
> protected List findAll(Class clazz, Integer id) {
>
> List objects = null;
>
> try {
>
> startOperation();
> Query query = session.createQuery("from " + clazz.getName() + " where id = " + id );
> objects = query.list();
> tx.commit();
>
> } catch (HibernateException e) {
> handleException(e);
> } finally {
> HibernateFactory.close(session);
> }
>
> return objects;
>
> }
>
> protected void handleException(HibernateException e) throws DataAccessLayerException {
> HibernateFactory.rollback(tx);
> throw new DataAccessLayerException(e);
>
> }
>
> protected void startOperation() throws HibernateException {
> session = HibernateFactory.openSession();
> tx = session.beginTransaction();
>
> }
> }
>
>
>
> HibernateFactory
> ----------------------------------------------------------------------------
> package com.entercite.finance.persistence;
>
> import org.hibernate.SessionFactory;
> import org.hibernate.Session;
> import org.hibernate.Transaction;
> import org.hibernate.HibernateException;
> import org.hibernate.cfg.Configuration;
>
> import org.apache.commons.logging.LogFactory;
> import org.apache.commons.logging.Log;
>
> public class HibernateFactory {
>
> private static SessionFactory sessionFactory;
> private static Log log = LogFactory.getLog(HibernateFactory.class);
>
> public static SessionFactory buildSessionFactory() throws HibernateException {
>
> System.out.println("bsf 1");
> if(sessionFactory != null){
> closeFactory();
> }
> System.out.println("bsf 2");
> Configuration configuration = new Configuration();
> System.out.println("bsf 3");
> sessionFactory = configuration.configure().buildSessionFactory(); <---IT PUKES HERE IT APPEARS>
> System.out.println("bsf 4");
>
> return sessionFactory;
> }
>
> public static SessionFactory getSessionFactory() {
> return sessionFactory;
> }
>
> public static Session openSession() throws HibernateException {
> return sessionFactory.openSession();
> }
>
> public static void closeFactory() {
> if (sessionFactory != null) {
> try {
> sessionFactory.close();
> } catch (HibernateException ignored) {
> log.error("Couldn't close SessionFactory", ignored);
> }
> }
> }
>
> public static void close(Session session) {
> if (session != null) {
> try {
> session.close();
> } catch (HibernateException ignored) {
> log.error("Couldn't close Session", ignored);
> }
> }
> }
>
> public static void rollback(Transaction tx) {
> try {
> if (tx != null) {
> tx.rollback();
> }
> } catch (HibernateException ignored) {
> log.error("Couldn't rollback Transaction", ignored);
> }
> }
> }
>
>
> hibernate.cfg.xml
> ----------------------------------------------------------------------------
> <!DOCTYPE hibernate-configuration PUBLIC
> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
>
> <hibernate-configuration>
> <session-factory>
>
> <property name="connection.username">root</property>
> <property name="connection.password">xxx</property>
> <property name="connection.url">//localhost:3306/budget</property>
> <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
> <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
>
> <mapping resource="com/entercite/finance/model/Login.hbm.xml"/>
>
> </session-factory>
> </hibernate-configuration>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org