从数据库读取用户的问题

发布于 2024-11-27 18:23:42 字数 20720 浏览 1 评论 0原文

您好,我在日志记录方面遇到问题,首先我在数据库中注册了用户,这工作正常!然后,当我尝试使用该用户(用户名和密码)登录时,应用程序抛出异常:

       ` [ERROR] ioc.Registry id to load is required for loading
[ERROR] ioc.Registry Operations trace:
[ERROR] ioc.Registry [ 1] Triggering event 'action' on Login:loginform
[ERROR] ioc.Registry [ 2] Triggering event 'validate' on Login:username
[ERROR] TapestryModule.RequestExceptionHandler Processing of request failed with uncaught exception: id to load is required for loading
org.apache.tapestry5.runtime.ComponentEventException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 7]
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1152)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3000(ComponentPageElementImpl.java:72)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1077)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1074)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1063)
    at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:141)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1073)
    at org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:81)
    at org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42)
    at $ComponentEventRequestHandler_13194654f69.handle($ComponentEventRequestHandler_13194654f69.java)
    at org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
    at $ComponentEventRequestHandler_13194654f69.handle($ComponentEventRequestHandler_13194654f69.java)
    at org.apache.tapestry5.services.TapestryModule$39.handle(TapestryModule.java:2583)
    at $ComponentEventRequestHandler_13194654f69.handle($ComponentEventRequestHandler_13194654f69.java)
    at $ComponentEventRequestHandler_13194654e1b.handle($ComponentEventRequestHandler_13194654e1b.java)
    at org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
    at org.apache.tapestry5.services.InitializeActivePageName.handleComponentEvent(InitializeActivePageName.java:39)
    at $ComponentRequestHandler_13194654e1d.handleComponentEvent($ComponentRequestHandler_13194654e1d.java)
    at $ComponentRequestHandler_13194654e01.handleComponentEvent($ComponentRequestHandler_13194654e01.java)
    at org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
    at $Dispatcher_13194654e03.dispatch($Dispatcher_13194654e03.java)
    at $Dispatcher_13194654dfe.dispatch($Dispatcher_13194654dfe.java)
    at org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:321)
    at org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:984)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:974)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:90)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90)
    at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:80)
    at org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
    at org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at $RequestHandler_13194654df5.service($RequestHandler_13194654df5.java)
    at org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:272)
    at org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
    at $HttpServletRequestHandler_13194654df7.service($HttpServletRequestHandler_13194654df7.java)
    at org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
    at $HttpServletRequestFilter_13194654df4.service($HttpServletRequestFilter_13194654df4.java)
    at $HttpServletRequestHandler_13194654df7.service($HttpServletRequestHandler_13194654df7.java)
    at org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:928)
    at $HttpServletRequestHandler_13194654df7.service($HttpServletRequestHandler_13194654df7.java)
    at $HttpServletRequestHandler_13194654df2.service($HttpServletRequestHandler_13194654df2.java)
    at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:147)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:387)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:880)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 15]
    at org.apache.tapestry5.corelib.components.Form.executeStoredActions(Form.java:681)
    at org.apache.tapestry5.corelib.components.Form._$advised$onAction(Form.java:542)
    at org.apache.tapestry5.corelib.components.Form$onAction$invocation_13194657e97.invokeAdvisedMethod(Form$onAction$invocation_13194657e97.java)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:77)
    at org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvice.java:37)
    at org.apache.tapestry5.internal.transform.LogWorker$1.advise(LogWorker.java:54)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:86)
    at org.apache.tapestry5.corelib.components.Form.onAction(Form.java)
    at org.apache.tapestry5.corelib.components.Form$MethodAccess_onAction_13194654e6d.invoke(Form$MethodAccess_onAction_13194654e6d.java)
    at org.apache.tapestry5.internal.transform.BaseEventHandlerMethodInvoker.invokeEventHandlerMethod(BaseEventHandlerMethodInvoker.java:52)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.invokeEventHandlers(OnEventWorker.java:157)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.advise(OnEventWorker.java:136)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:86)
    at org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:950)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1132)
    ... 65 more
Caused by: org.apache.tapestry5.ioc.internal.OperationException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 15]
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:102)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:69)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1063)
    at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:141)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1073)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerEvent(ComponentPageElementImpl.java:1046)
    at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.triggerEvent(InternalComponentResourcesImpl.java:277)
    at org.apache.tapestry5.internal.services.FieldValidationSupportImpl.validate(FieldValidationSupportImpl.java:164)
    at $FieldValidationSupport_13194654e8f.validate($FieldValidationSupport_13194654e8f.java)
    at org.apache.tapestry5.corelib.base.AbstractTextField.processSubmission(AbstractTextField.java:211)
    at org.apache.tapestry5.corelib.base.AbstractField.processSubmission(AbstractField.java:190)
    at org.apache.tapestry5.corelib.base.AbstractField.access$100(AbstractField.java:38)
    at org.apache.tapestry5.corelib.base.AbstractField$ProcessSubmission.execute(AbstractField.java:95)
    at org.apache.tapestry5.corelib.base.AbstractField$ProcessSubmission.execute(AbstractField.java:89)
    at org.apache.tapestry5.corelib.components.Form.executeStoredActions(Form.java:666)
    ... 80 more
Caused by: org.apache.tapestry5.runtime.ComponentEventException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 15]
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1152)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3000(ComponentPageElementImpl.java:72)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1077)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1074)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
    ... 94 more
Caused by: java.lang.IllegalArgumentException: id to load is required for loading
    at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:74)
    at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:56)
    at org.hibernate.impl.SessionImpl.get(SessionImpl.java:840)
    at org.hibernate.impl.SessionImpl.get(SessionImpl.java:836)
    at $Session_13194654f6e.get($Session_13194654f6e.java)
    at $Session_13194654dd6.get($Session_13194654dd6.java)
    at com.fit.hibernate.UsersServiceHibernate.retriveSingleUser(UsersServiceHibernate.java:41)
    at $Users_13194654f6a.retriveSingleUser($Users_13194654f6a.java)
    at $Users_13194654f6d.retriveSingleUser($Users_13194654f6d.java)
    at $Users_13194654e62.retriveSingleUser($Users_13194654e62.java)
    at com.fit.util.Security.authenticate(Security.java:11)
    at com.fit.pages.Login.onValidate(Login.java:50)
    at com.fit.pages.Login$MethodAccess_onValidate_13194654e64.invoke(Login$MethodAccess_onValidate_13194654e64.java)
    at org.apache.tapestry5.internal.transform.BaseEventHandlerMethodInvoker.invokeEventHandlerMethod(BaseEventHandlerMethodInvoker.java:52)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.invokeEventHandlers(OnEventWorker.java:157)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.advise(OnEventWorker.java:136)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:86)
    at com.fit.pages.Login.dispatchComponentEvent(Login.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:942)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1132)
    ... 98 more

这是我的代码:

@Entity
public class UserBean implements User {

    @Id @GeneratedValue
    private long id;
    @Basic
    private String userName;
    @Basic
    private String fullName;
    @Basic
    private String password;
    @Basic
    private String email;
    @Basic
    private Gender gender;
    @Basic
    private AccountRole role;




    public UserBean() {

    }
    public UserBean( String userName,  String password
            ) {


        this.userName = userName;

        this.password = password;

    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getId()
     */
    public long getId() {
        return id;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setId(long)
     */
    public void setId(long id) {
        this.id = id;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getUserName()
     */
     @Validate("required")
    public String getUserName() {
        return userName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setUserName(java.lang.String)
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getFullName()
     */
     @Validate("required")
    public String getFullName() {
        return fullName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setFullName(java.lang.String)
     */
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getPassword()
     */
     @Validate("required")
    public String getPassword() {
        return password;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setPassword(java.lang.String)
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getEmail()
     */
     @Validate("required")
    public String getEmail() {
        return email;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setEmail(java.lang.String)
     */
    public void setEmail(String email) {
        this.email = email;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getGender()
     */
    public Gender getGender() {
        return gender;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setGender(com.fit.enums.Gender)
     */
    public void setGender(Gender gender) {
        this.gender = gender;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getRole()
     */
    public AccountRole getRole() {
        return role;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setRole(com.fit.enums.AccountRole)
     */
    public void setRole(AccountRole role) {
        this.role = role;
    }


}

登录页面:

public class Login {

    private String userName;

    @Property
    private String password;

    @Inject
    @Property
    private Users users;

    @SessionState
    private User user;

    @Component(id="loginForm")
    private Form loginForm;

    @Inject
    private Messages messages;

    public String getUserName() {
        return userName;
    }



    public void setUserName(String userName) {
        this.userName = userName;

    }
    void onValidate(){
        User authenticatedUser = Security.authenticate(userName, password , users);
        if(authenticatedUser != null){
            user = authenticatedUser;
        }else{
            loginForm.recordError(messages.get("authentication-failed"));
        }
    }

    Object onSuccess()
    {
        return Index.class;
    }

security.java

public class Security {

    public static User authenticate(String userName,String password, Users users ){
        User login = null;

        login = users.retriveSingleUser(userName);
        if(login == null) return null;

        if(login.getPassword().equals(password)){
            return login;
        }

        return null;
    }
}

usersBean.java

public class UsersBean implements Users {

    private Map<String, User> users;

    public UsersBean(Map<String, User> users) {

        this.users = users;
    }

    public UsersBean() {
        users = new HashMap<String, User>();
    }
    /* (non-Javadoc)
     * @see com.fit.service.Users#save(com.fit.interfaces.User)
     */
    @CommitAfter
    public User save(User user){
        return users.put(user.getUserName(), user);
    }

    /* (non-Javadoc)
     * @see com.fit.service.Users#retrive()
     */
    public Collection<User> retrive(){
        return users.values();
    }

    /* (non-Javadoc)
     * @see com.fit.service.Users#retriveSingleUser(java.lang.String)
     */

    public User retriveSingleUser(String userName){
        return users.get(userName);
    }

    /* (non-Javadoc)
     * @see com.fit.service.Users#retriveSingleUser(java.io.Serializable)
     */
//  public User retriveSingleUser(Serializable id){
//      return users.get(id);
//  }

}

usersServiceHibernate.java

public class UsersServiceHibernate implements Users {

    private Session session;



    public UsersServiceHibernate(Session session) {

        this.session = session;
    }

    @Override
    public User save(User user) {
        // TODO Auto-generated method stub
        return (User) session.get(UserBean.class, session.save(user));
    }

    @Override
    public Collection<User> retrive() {
        Criteria criteria = session.createCriteria(UserBean.class);
        return criteria.list();
    }

    @Override
    public User retriveSingleUser(String userName) {
        // TODO Auto-generated method stub
        return (User) session.get(UserBean.class, userName);
    }


//  public User retriveSingleUser(Serializable id) {
//      // TODO Auto-generated method stub
//      return (User) session.get(UserBean.class, id);
//  }

}

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="">
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:mem:name</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>

        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_value">20</property>
        <property name="hibernate.c3p0.timeout">300</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>

        <mapping class="com.fit.beans.UserBean"/>

        <mapping package="com.fit.beans"/>
    </session-factory>
</hibernate-configuration>

如何为休眠读取数据创建方法从数据库???

hi i have problem with logging, first i registered user in database,this works ok! then when i try to logged with that user(username and password),application trhows me exception:

       ` [ERROR] ioc.Registry id to load is required for loading
[ERROR] ioc.Registry Operations trace:
[ERROR] ioc.Registry [ 1] Triggering event 'action' on Login:loginform
[ERROR] ioc.Registry [ 2] Triggering event 'validate' on Login:username
[ERROR] TapestryModule.RequestExceptionHandler Processing of request failed with uncaught exception: id to load is required for loading
org.apache.tapestry5.runtime.ComponentEventException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 7]
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1152)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3000(ComponentPageElementImpl.java:72)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1077)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1074)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1063)
    at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:141)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1073)
    at org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:81)
    at org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42)
    at $ComponentEventRequestHandler_13194654f69.handle($ComponentEventRequestHandler_13194654f69.java)
    at org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
    at $ComponentEventRequestHandler_13194654f69.handle($ComponentEventRequestHandler_13194654f69.java)
    at org.apache.tapestry5.services.TapestryModule$39.handle(TapestryModule.java:2583)
    at $ComponentEventRequestHandler_13194654f69.handle($ComponentEventRequestHandler_13194654f69.java)
    at $ComponentEventRequestHandler_13194654e1b.handle($ComponentEventRequestHandler_13194654e1b.java)
    at org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
    at org.apache.tapestry5.services.InitializeActivePageName.handleComponentEvent(InitializeActivePageName.java:39)
    at $ComponentRequestHandler_13194654e1d.handleComponentEvent($ComponentRequestHandler_13194654e1d.java)
    at $ComponentRequestHandler_13194654e01.handleComponentEvent($ComponentRequestHandler_13194654e01.java)
    at org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
    at $Dispatcher_13194654e03.dispatch($Dispatcher_13194654e03.java)
    at $Dispatcher_13194654dfe.dispatch($Dispatcher_13194654dfe.java)
    at org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:321)
    at org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:984)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:974)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:90)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90)
    at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:80)
    at org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
    at org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103)
    at $RequestHandler_13194654dff.service($RequestHandler_13194654dff.java)
    at $RequestHandler_13194654df5.service($RequestHandler_13194654df5.java)
    at org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:272)
    at org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
    at $HttpServletRequestHandler_13194654df7.service($HttpServletRequestHandler_13194654df7.java)
    at org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
    at $HttpServletRequestFilter_13194654df4.service($HttpServletRequestFilter_13194654df4.java)
    at $HttpServletRequestHandler_13194654df7.service($HttpServletRequestHandler_13194654df7.java)
    at org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:928)
    at $HttpServletRequestHandler_13194654df7.service($HttpServletRequestHandler_13194654df7.java)
    at $HttpServletRequestHandler_13194654df2.service($HttpServletRequestHandler_13194654df2.java)
    at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:147)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:387)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:880)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 15]
    at org.apache.tapestry5.corelib.components.Form.executeStoredActions(Form.java:681)
    at org.apache.tapestry5.corelib.components.Form._$advised$onAction(Form.java:542)
    at org.apache.tapestry5.corelib.components.Form$onAction$invocation_13194657e97.invokeAdvisedMethod(Form$onAction$invocation_13194657e97.java)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:77)
    at org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvice.java:37)
    at org.apache.tapestry5.internal.transform.LogWorker$1.advise(LogWorker.java:54)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:86)
    at org.apache.tapestry5.corelib.components.Form.onAction(Form.java)
    at org.apache.tapestry5.corelib.components.Form$MethodAccess_onAction_13194654e6d.invoke(Form$MethodAccess_onAction_13194654e6d.java)
    at org.apache.tapestry5.internal.transform.BaseEventHandlerMethodInvoker.invokeEventHandlerMethod(BaseEventHandlerMethodInvoker.java:52)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.invokeEventHandlers(OnEventWorker.java:157)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.advise(OnEventWorker.java:136)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:86)
    at org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:950)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1132)
    ... 65 more
Caused by: org.apache.tapestry5.ioc.internal.OperationException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 15]
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:102)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:69)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1063)
    at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:141)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1073)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerEvent(ComponentPageElementImpl.java:1046)
    at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.triggerEvent(InternalComponentResourcesImpl.java:277)
    at org.apache.tapestry5.internal.services.FieldValidationSupportImpl.validate(FieldValidationSupportImpl.java:164)
    at $FieldValidationSupport_13194654e8f.validate($FieldValidationSupport_13194654e8f.java)
    at org.apache.tapestry5.corelib.base.AbstractTextField.processSubmission(AbstractTextField.java:211)
    at org.apache.tapestry5.corelib.base.AbstractField.processSubmission(AbstractField.java:190)
    at org.apache.tapestry5.corelib.base.AbstractField.access$100(AbstractField.java:38)
    at org.apache.tapestry5.corelib.base.AbstractField$ProcessSubmission.execute(AbstractField.java:95)
    at org.apache.tapestry5.corelib.base.AbstractField$ProcessSubmission.execute(AbstractField.java:89)
    at org.apache.tapestry5.corelib.components.Form.executeStoredActions(Form.java:666)
    ... 80 more
Caused by: org.apache.tapestry5.runtime.ComponentEventException: id to load is required for loading [at classpath:com/fit/pages/Login.tml, line 15]
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1152)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3000(ComponentPageElementImpl.java:72)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1077)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$7.invoke(ComponentPageElementImpl.java:1074)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
    ... 94 more
Caused by: java.lang.IllegalArgumentException: id to load is required for loading
    at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:74)
    at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:56)
    at org.hibernate.impl.SessionImpl.get(SessionImpl.java:840)
    at org.hibernate.impl.SessionImpl.get(SessionImpl.java:836)
    at $Session_13194654f6e.get($Session_13194654f6e.java)
    at $Session_13194654dd6.get($Session_13194654dd6.java)
    at com.fit.hibernate.UsersServiceHibernate.retriveSingleUser(UsersServiceHibernate.java:41)
    at $Users_13194654f6a.retriveSingleUser($Users_13194654f6a.java)
    at $Users_13194654f6d.retriveSingleUser($Users_13194654f6d.java)
    at $Users_13194654e62.retriveSingleUser($Users_13194654e62.java)
    at com.fit.util.Security.authenticate(Security.java:11)
    at com.fit.pages.Login.onValidate(Login.java:50)
    at com.fit.pages.Login$MethodAccess_onValidate_13194654e64.invoke(Login$MethodAccess_onValidate_13194654e64.java)
    at org.apache.tapestry5.internal.transform.BaseEventHandlerMethodInvoker.invokeEventHandlerMethod(BaseEventHandlerMethodInvoker.java:52)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.invokeEventHandlers(OnEventWorker.java:157)
    at org.apache.tapestry5.internal.transform.OnEventWorker$4.advise(OnEventWorker.java:136)
    at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:86)
    at com.fit.pages.Login.dispatchComponentEvent(Login.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:942)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1132)
    ... 98 more

here is my code:

@Entity
public class UserBean implements User {

    @Id @GeneratedValue
    private long id;
    @Basic
    private String userName;
    @Basic
    private String fullName;
    @Basic
    private String password;
    @Basic
    private String email;
    @Basic
    private Gender gender;
    @Basic
    private AccountRole role;




    public UserBean() {

    }
    public UserBean( String userName,  String password
            ) {


        this.userName = userName;

        this.password = password;

    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getId()
     */
    public long getId() {
        return id;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setId(long)
     */
    public void setId(long id) {
        this.id = id;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getUserName()
     */
     @Validate("required")
    public String getUserName() {
        return userName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setUserName(java.lang.String)
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getFullName()
     */
     @Validate("required")
    public String getFullName() {
        return fullName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setFullName(java.lang.String)
     */
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getPassword()
     */
     @Validate("required")
    public String getPassword() {
        return password;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setPassword(java.lang.String)
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getEmail()
     */
     @Validate("required")
    public String getEmail() {
        return email;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setEmail(java.lang.String)
     */
    public void setEmail(String email) {
        this.email = email;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getGender()
     */
    public Gender getGender() {
        return gender;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setGender(com.fit.enums.Gender)
     */
    public void setGender(Gender gender) {
        this.gender = gender;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#getRole()
     */
    public AccountRole getRole() {
        return role;
    }
    /* (non-Javadoc)
     * @see com.fit.beans.User#setRole(com.fit.enums.AccountRole)
     */
    public void setRole(AccountRole role) {
        this.role = role;
    }


}

login page:

public class Login {

    private String userName;

    @Property
    private String password;

    @Inject
    @Property
    private Users users;

    @SessionState
    private User user;

    @Component(id="loginForm")
    private Form loginForm;

    @Inject
    private Messages messages;

    public String getUserName() {
        return userName;
    }



    public void setUserName(String userName) {
        this.userName = userName;

    }
    void onValidate(){
        User authenticatedUser = Security.authenticate(userName, password , users);
        if(authenticatedUser != null){
            user = authenticatedUser;
        }else{
            loginForm.recordError(messages.get("authentication-failed"));
        }
    }

    Object onSuccess()
    {
        return Index.class;
    }

security.java

public class Security {

    public static User authenticate(String userName,String password, Users users ){
        User login = null;

        login = users.retriveSingleUser(userName);
        if(login == null) return null;

        if(login.getPassword().equals(password)){
            return login;
        }

        return null;
    }
}

usersBean.java

public class UsersBean implements Users {

    private Map<String, User> users;

    public UsersBean(Map<String, User> users) {

        this.users = users;
    }

    public UsersBean() {
        users = new HashMap<String, User>();
    }
    /* (non-Javadoc)
     * @see com.fit.service.Users#save(com.fit.interfaces.User)
     */
    @CommitAfter
    public User save(User user){
        return users.put(user.getUserName(), user);
    }

    /* (non-Javadoc)
     * @see com.fit.service.Users#retrive()
     */
    public Collection<User> retrive(){
        return users.values();
    }

    /* (non-Javadoc)
     * @see com.fit.service.Users#retriveSingleUser(java.lang.String)
     */

    public User retriveSingleUser(String userName){
        return users.get(userName);
    }

    /* (non-Javadoc)
     * @see com.fit.service.Users#retriveSingleUser(java.io.Serializable)
     */
//  public User retriveSingleUser(Serializable id){
//      return users.get(id);
//  }

}

usersServiceHibernate.java

public class UsersServiceHibernate implements Users {

    private Session session;



    public UsersServiceHibernate(Session session) {

        this.session = session;
    }

    @Override
    public User save(User user) {
        // TODO Auto-generated method stub
        return (User) session.get(UserBean.class, session.save(user));
    }

    @Override
    public Collection<User> retrive() {
        Criteria criteria = session.createCriteria(UserBean.class);
        return criteria.list();
    }

    @Override
    public User retriveSingleUser(String userName) {
        // TODO Auto-generated method stub
        return (User) session.get(UserBean.class, userName);
    }


//  public User retriveSingleUser(Serializable id) {
//      // TODO Auto-generated method stub
//      return (User) session.get(UserBean.class, id);
//  }

}

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="">
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:mem:name</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>

        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_value">20</property>
        <property name="hibernate.c3p0.timeout">300</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>

        <mapping class="com.fit.beans.UserBean"/>

        <mapping package="com.fit.beans"/>
    </session-factory>
</hibernate-configuration>

how to make method for hibernate read data from database???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏月而来 2024-12-04 18:23:42

我缺少您的用户的代码,并且您的异常中很可能会出现一堆“由”堆栈跟踪引起的,这将向您指出问题(检查您的日志而不仅仅是挂毯错误页面)。您似乎将服务层、DAO 层和模型层混合在一起。此外,您还在地图中缓存您的用户,我似乎无法找到您实际的休眠会话调用的跟踪。我正在尝试追踪这些问题,因为很确定您的问题就在那里。

session.get(UserBean.class, userName); 采用 UserBean 的主键,但在您的情况下,UserBean 似乎是一个没有任何关联映射的服务。此外,通常主键都是Long。要通过用户名检索 UserBean,请查看 hiberante标准文档

当您使用空主键调用 get 时,可能会发生您看到的异常。但您需要为我发布完整的堆栈跟踪才能确定。

我建议您在进行设置时仔细查看 tapestry hibernate 示例像这样一个不可读的项目。

祝你好运,
乔斯特

I'm missing the code for your User and there will very likely be a bunch of "caused by" stacktraces in your exception which will point you to the problem (check your logs and not just the tapestry error page). You seem to be mixing your Service layer, DAO layer and model layer all into one here. Also you are caching your users in a Map and I can't seem to find the trace to you actual hibernate session calls. I'm trying to trace those as pretty certain your problem lies there.

The session.get(UserBean.class, userName); takes the primary key of the UserBean, but in your case UserBean seems to be a Service without any mapping associated with it. Also, generally primary keys are Long's. To retrieve a UserBean by its username have a look at the hiberante criteria documentation.

The exception you are seeing might happen when you call get with a null primary key. But you'll need to post the full stacktrace for me to be sure.

I would advice you to have a good look at the tapestry hibernate examples as you are setting yourself up for quite an unreadable project like this.

Good luck,
Joost

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文