4 Replies Latest reply on Jul 8, 2010 8:04 AM by bat-orgil khashbaatar

    Connect to MySQL problem

    bat-orgil khashbaatar Newbie

      Hey guy...


      Help me.I have a some questions. I need to JBoss Seam Login form example that connect to MySQL 5.1..I have deployed our JBoss login form project which is a error that mean transaction and login failed...I found to check errors...I don't understood..


        HELP ME...I NEED A LOGIN FORM CONNECT TO MYSQL 5.1



        • 1. Re: Connect to MySQL problem
          bat-orgil khashbaatar Newbie

          It's my code follow it:


          Interface Authenticator.java
          package org.domain.alpha.session;


          import javax.ejb.Local;
          
          @Local
          public interface Authenticator {
                  
                  public boolean authenticate();
          
          } 
          



          So AuthenticatorAction.java  SESSION BEAN




          
          
          
          
          package org.domain.alpha.session;
          
          import static org.jboss.seam.ScopeType.SESSION;
          
          import java.util.List;
          
          import javax.ejb.Stateful;
          import javax.ejb.Stateless;
          import javax.persistence.EntityManager;
          import javax.persistence.PersistenceContext;
          
          import org.domain.alpha.entity.User;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Out;
          
          /**
           * Session Bean implementation class AuthenticatorAction
           */
          @Stateless
          @Name("authenticator")
          public class AuthenticatorAction implements Authenticator {
                  
                  
                  @PersistenceContext
                  private EntityManager em;
                  
                  @Out(required=false, scope = SESSION)
                  private User user;
                  
                  public boolean authenticate() {
                  
                          List results = em.createQuery("select u from User u where u.username = #{user.username} and u.password = #{user.password}").getResultList();
                          if( results.size() == 0 ){
                  
                                  return false;
                          }
                          else{
                                  
                                  user = (User) results.get(0);
                                  return true;
                          }
                                  
                  }
          
          }
          
          



          Entity Bean User.java




          
          
          package org.domain.alpha.entity;
          
          // Generated Jul 8, 2010 4:16:21 AM by Hibernate Tools 3.3.0.GA
          
          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.GeneratedValue;
          import static javax.persistence.GenerationType.IDENTITY;
          import javax.persistence.Id;
          import javax.persistence.Table;
          import org.hibernate.validator.Length;
          import org.hibernate.validator.NotNull;
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          
          /**
           * User generated by hbm2java
           */
          @Entity
          @Scope(ScopeType.SESSION)
          @Name("user")
          @Table(name = "user", catalog = "test")
          public class User implements java.io.Serializable {
          
                  private Integer id;
                  private String username;
                  private String password;
          
                  public User() {
                  }
          
                  public User(String username, String password) {
                          this.username = username;
                          this.password = password;
                  }
          
                  @Id
                  @GeneratedValue(strategy = IDENTITY)
                  @Column(name = "id", unique = true, nullable = false)
                  public Integer getId() {
                          return this.id;
                  }
          
                  public void setId(Integer id) {
                          this.id = id;
                  }
          
                  @Column(name = "username", nullable = false, length = 30)
                  @NotNull
                  @Length(max = 30)
                  public String getUsername() {
                          return this.username;
                  }
          
                  public void setUsername(String username) {
                          this.username = username;
                  }
          
                  @Column(name = "password", nullable = false, length = 30)
                  @NotNull
                  @Length(max = 30)
                  public String getPassword() {
                          return this.password;
                  }
          
                  public void setPassword(String password) {
                          this.password = password;
                  }
          
          }
          
          



          Persistence.xml





          
          
          <?xml version="1.0" encoding="UTF-8"?>
          <!-- Persistence deployment descriptor for dev profile -->
          <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                       version="1.0">
                       
             <persistence-unit name="Alpha">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>java:/AlphaDatasource</jta-data-source>
                <!-- The <jar-file> element is necessary if you put the persistence.xml in the WAR and the classes in the JAR -->
                <!--
                <jar-file>../../vehicles.jar</jar-file>
                -->
                <properties>
                   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
                   <property name="hibernate.hbm2ddl.auto" value="update"/>
                   <property name="hibernate.show_sql" value="true"/>
                   <property name="hibernate.format_sql" value="true"/>
                   <property name="hibernate.default_schema" value="test"/>
                   <property name="jboss.entity.manager.factory.jndi.name" value="java:/AlphaEntityManagerFactory"/>
                </properties>
             </persistence-unit>
              
          </persistence>
          




          component.xml


           
          
          
          
          
          <?xml version="1.0" encoding="UTF-8"?>
          <components xmlns="http://jboss.com/products/seam/components"
                      xmlns:core="http://jboss.com/products/seam/core"
                      xmlns:persistence="http://jboss.com/products/seam/persistence"
                      xmlns:drools="http://jboss.com/products/seam/drools"
                      xmlns:bpm="http://jboss.com/products/seam/bpm"
                      xmlns:security="http://jboss.com/products/seam/security"
                      xmlns:mail="http://jboss.com/products/seam/mail"
                      xmlns:web="http://jboss.com/products/seam/web"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation=
                          "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                           http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                           http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
                           http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
                           http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                           http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
                           http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                           http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd">
          
             <core:init debug="true" jndi-pattern="@jndiPattern@"/>
          
             <core:manager concurrent-request-timeout="500"
                           conversation-timeout="120000"
                           conversation-id-parameter="cid"
                           parent-conversation-id-parameter="pid"/>
          
             <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
             <web:hot-deploy-filter url-pattern="*.seam"/>
          
             <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                persistence-unit-jndi-name="java:/AlphaEntityManagerFactory"/>
          
             <drools:rule-base name="securityRules">
                <drools:rule-files>
                   <value>/security.drl</value>
                </drools:rule-files>
             </drools:rule-base>
          
             <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
          
             <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
          
             <event type="org.jboss.seam.security.notLoggedIn">
                <action execute="#{redirect.captureCurrentView}"/>
             </event>
             <event type="org.jboss.seam.security.loginSuccessful">
                <action execute="#{redirect.returnToCapturedView}"/>
             </event>
          
             <mail:mail-session host="localhost" port="25"/>
          
             <!-- For use with jBPM pageflow or process management -->
             <!--
             <bpm:jbpm>
                <bpm:process-definitions></bpm:process-definitions>
                <bpm:pageflow-definitions></bpm:pageflow-definitions>
             </bpm:jbpm>
             -->
          
          </components>
          
          



          UI login.xhtml




          
          
          <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich"
              template="layout/template.xhtml">
          
          <ui:define name="body">
          
              <h:form id="loginForm">
          
                  <rich:panel>
                      <f:facet name="header">Login</f:facet>
          
                      <p>Please login here</p>
          
                      <div class="dialog">
                          <h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value">
                              <h:outputLabel for="username">Username</h:outputLabel>
                              <h:inputText id="username"
                                        value="#{identity.username}"/>
                              <h:outputLabel for="password">Password</h:outputLabel>
                              <h:inputSecret id="password"
                                          value="#{identity.password}"/>
                              <h:outputLabel for="rememberMe">Remember me</h:outputLabel>
                              <h:selectBooleanCheckbox id="rememberMe"
                                                    value="#{rememberMe.enabled}"/>
                          </h:panelGrid>
                      </div>
          
                    
          
                  </rich:panel>
          
                  <div class="actionButtons">
                      <h:commandButton id="submit" value="Login" action="#{identity.login}"/>
                  </div>
          
              </h:form>
          
           </ui:define>
          </ui:composition>
          
          



          Help!!!!!!

          • 2. Re: Connect to MySQL problem
            bat-orgil khashbaatar Newbie

            Some body here...I'm waiting for your idea and resolution

            • 3. Re: Connect to MySQL problem
              Michael Wohlfart Expert

              Providing some stacktrace with the actual error message might help to identify your problem.


              "error that mean transaction and login failed"
              might be an indication that your AlphaDatasource is not configured correctly

              • 4. Re: Connect to MySQL problem
                bat-orgil khashbaatar Newbie

                Michael Wohlfart wrote on Jul 08, 2010 06:36:


                Providing some stacktrace with the actual error message might help to identify your problem.

                "error that mean transaction and login failed"
                might be an indication that your AlphaDatasource is not configured correctly


                tnx...I'l see