JBoss Community

Re: Simple Seam app configured for Tomcat

created by Philippe Leménager in JBoss Tools - View the full discussion

OK, here is the detail of the operations I've done.

 

1) File / New / Seam Web Project

1.1) Window "Seam Web Project"

Project name : stamas

Project contents : Use default

Target Runtime : Apache Tomcat v6.0

Dynamic web module version : 2.5
Target Server : Tomcat v6.0 at localhost
Configuration : Default Configuration for Apache Tomcat v6.0

=> Clic on Modify + Java Persistence, Java Server Faces and Seam

=> Save As "Seam + Tomcat"

=> OK

Configuration : Seam + Tomcat

Next >

 

1.2) Window "Java"

Next >

 

1.3) Window "Web module"

Next >

 

1.4) Window "JPA Facet"

Platform : Hibernate (défaut)
JPA Implementation :
    Type : EclipseLink 1.1.x
    Include libraries with this application is selected

Connection : MySQL Stamas

Clic on Connect => "Override default schema from connection" option appears

Add driver library to buid path : selected

Driver : MySQL JDBC Driver

Override default schema from connection : selected

Schema : stamas

Persistent class management : Discover annotated classes automatically

Create orm.xml : not selected

Next >

 

1.5) Window "JSF Capabilities"
JSF implementation library
    Type : User Library

     I've created a library called seam-jsf with jsf-api.jar and jsf-impl.jar from jboss-seam-2.2.0.GA/lib

     The new library seam-jsf is selected

     Include librairies with this application is selected

Other params by default.

Next >

 

1.6) Window "Seam Facets"
Seam runtime : jboss-seam-2.2.0.GA
Deploy as : WAR
Database type : MySQL5 (InnoDB)
DB Tables already exists in database : selected

Recreate database tables and data on deploy : not selected

Other params by default.

Finish >

 

2) Tries of lauching the project

I've tried several times to launch the default application created by JBoss Tools, by right click on the project then Run As / Run on server, and I had many successive errors that I've fixed by these operations :

2.1) Concole message : "INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:..."

Ignored

 

2.2) Console message : INFO: The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.

Open stamas/WebContent/WEB-INF/web.xml and comment :

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

 

 

2.3) Adding jars

In order to fix the java.lang.ClassNotFoundException errors, I've copied these jars from jboss-seam-2.2.0.GA/lib to stamas/WebContent/WEB-INF/lib/

commons-collections.jar
commons-logging.jar
dom4j.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-core.jar
hibernate-entitymanager.jar
hibernate-validator.jar
javassist.jar
jta.jar
log4j.jar
slf4j-api.jar
slf4j-log4j12.jar

 

2.4) Console message : ATTENTION: no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required.

Ignored for the moment. My test app is OK with this message.

 

2.5) Box message : "Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are blocked."

Open stamas/WebContent/WEB-INF/components.xml and erase the params in tag <core>

Original : <core:init debug="true" jndi-pattern="@jndiPattern@"/>

Becomes : <core:init />

 

Open stamas/WebContent/WEB-INF/pages.xml and comment the last exception tag :

<exception>
    <redirect view-id="/error.xhtml">
        <message severity="error">Unexpected error, please try again</message>
    </redirect>
</exception>

 

The "Welcome to Seam!" page appears but many groups of two errors in the console :

 

2.6) GRAVE: swallowing exception
java.lang.RuntimeException: exception invoking: getTransaction
Caused by: javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.TransactionFactory.getObjectInstance(TransactionFactory.java:113)

 

ATTENTION: uncaught exception, passing to exception handler
java.lang.IllegalStateException: Could not commit transaction
    at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:625)
Caused by: java.lang.RuntimeException: exception invoking: getTransaction
    at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154)
Caused by: javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.TransactionFactory.getObjectInstance(TransactionFactory.java:113)

 

Open stamas/WebContent/WEB-INF/components.xml

Add this :

xmlns:transaction="http://jboss.com/products/seam/transaction"
http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd
<transaction:entity-transaction entity-manager="#{entityManager}"/>

 

There is the begining of the file :

<?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"
            xmlns:transaction="http://jboss.com/products/seam/transaction"
            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
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd">

 

   <core:init />

 

   <core:manager concurrent-request-timeout="500"
                 conversation-timeout="120000"
                 conversation-id-parameter="cid"
                 parent-conversation-id-parameter="pid"/>

 

   <transaction:entity-transaction entity-manager="#{entityManager}"/>

 

2.7) [EL Severe]: 2010-10-13 10:28:38.958--ServerSession(1872202644)--Local Exception Stack:
Exception [EclipseLink-4021] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null].  Verify that you have set the expected driver class and URL.  Check your login, persistence.xml or sessions.xml resource.  The jdbc.driver property should be set to a class that is compatible with your database platform
    at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:375)

 

Modifiy stamas/src/META-INF/persistence.xml like this :

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    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"
>
    <persistence-unit name="stamas" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>java:comp/env/jdbc/stamasDatasource</non-jta-data-source>
        <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_catalog" value="stamas"/>
        </properties>
    </persistence-unit>
</persistence>

 

2.8) Console message : log4j:WARN No appenders could be found for logger (javax.servlet.ServletContextListener).
log4j:WARN Please initialize the log4j system properly.

 

Copy jboss-seam-2.2.0.GA/examples/jpa/resources-tomcat/WEB-INF/classes/logj4.xml in stamas/WebContent/WEB-INF/classes/

 

2.9) Console message : ERROR [DatasourceConnectionProvider] Could not find datasource: java:comp/env/jdbc/stamasDatasource
javax.naming.NameNotFoundException: Le Nom jdbc n'est pas lié à ce Contexte (=> translate : JDBC name is not linked to this context)

 

Create file stamas/WebContent/META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?> 
<Context crossContext="true" 
  debug="5" 
  docBase="stamas" 
  path="/stamas" 
  reloadable="true"> 
  <Resource auth="Container" 
  driverClassName="com.mysql.jdbc.Driver" 
  maxActive="20" 
  maxIdle="10" 
  maxWait="-1" 
  name="jdbc/stamasDatasource" 
  type="javax.sql.DataSource" 
  url="jdbc:mysql://localhost:3306/stamas" 
  username="root" 
  password="***" /> 
</Context>

 

Copy tag <Resource> from this file in apache-6.0.29/conf/Catalina/localhost/stamas.xml. It looks like this :
<?xml version="1.0" encoding="UTF-8"?>
<Context crossContext="true"
        debug="5"
        docBase="/usr/local/apache-tomcat-6.0.29/wtpwebapps/stamas"
        reloadable="true"
        source="org.eclipse.jst.jee.server:stamas">
        <Resource auth="Container"
                driverClassName="com.mysql.jdbc.Driver"
                maxActive="20"
                maxIdle="10"
                maxWait="-1"
                name="jdbc/stamasDatasource"
                password="***"
                type="javax.sql.DataSource"
                url="jdbc:mysql://localhost:3306/stamas"
                username="root"/>
</Context>

 

=> The app start without errors but there is still a WARN message in the console :

WARN  [PersistentPermissionResolver] no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required.

 

The app works properly with this message. I can use the Login option and log with admin and no password like suggested by the app.

=> Warn message ignored.

 

3) Generate Entities

I've created the database with tables, herited tables and views. There are the first ones I've tried to import in my app...

CREATE TABLE `t_e_personne_prs` (
  `prs_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifiant de la personne',
  `prs_nom` varchar(30) COLLATE utf8_bin NOT NULL COMMENT 'Nom de la personne',
  `prs_prenom` varchar(30) COLLATE utf8_bin NOT NULL COMMENT 'Prénom de la personne    ',
  `prs_adrel` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'Adresse électronique  de la personne',
  `prs_telephone` char(10) COLLATE utf8_bin DEFAULT NULL COMMENT 'Numéro de téléphone de la personne',
  PRIMARY KEY (`prs_id`),
  KEY `x_prs_nom_prenom` (`prs_nom`,`prs_prenom`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Table des personnes.';

 

CREATE TABLE `t_e_fonction_fct` (
  `fct_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifiant de la fonction logicielle',
  `fct_libelle` varchar(45) COLLATE utf8_bin NOT NULL COMMENT 'Libelle de la fonction logicielle',
  PRIMARY KEY (`fct_id`),
  KEY `x_fct_libelle` (`fct_libelle`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Table des fonctions du logiciel';

 

CREATE TABLE `t_e_type_utilisateur_tu` (
  `tu_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifiant du type d''utilisateur',
  `tu_libelle` varchar(45) COLLATE utf8_bin NOT NULL COMMENT 'Libellé du type d''utilisateur',
  PRIMARY KEY (`tu_id`),
  UNIQUE KEY `x_tu_libelle` (`tu_libelle`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Table des types d''utilisateurs';

 

CREATE TABLE `t_j_uti_acceder_fct_uaf` (
  `uaf_id_type_utilisateur` tinyint(3) unsigned NOT NULL COMMENT 'Identifiant du type d''utilisateur',
  `uaf_id_fonction` tinyint(3) unsigned NOT NULL COMMENT 'Identifiant de la fonction logicielle',
  PRIMARY KEY (`uaf_id_type_utilisateur`,`uaf_id_fonction`),
  KEY `c_fk_uaf_id_fonction` (`uaf_id_fonction`),
  CONSTRAINT `c_fk_uaf_id_fonction` FOREIGN KEY (`uaf_id_fonction`)  REFERENCES `t_e_fonction_fct` (`fct_id`) ON DELETE CASCADE ON UPDATE NO  ACTION,
  CONSTRAINT `c_fk_uaf_id_type_utilisateur` FOREIGN KEY  (`uaf_id_type_utilisateur`) REFERENCES `t_e_type_utilisateur_tu`  (`tu_id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Table associative des accès aux fonctions par les types d''ut';

 

CREATE TABLE `t_h_utilisateur_uti` (
  `uti_id_personne` int(10) unsigned NOT NULL,
  `uti_id_type_utilisateur` tinyint(3) unsigned NOT NULL,
  `uti_login` varchar(20) COLLATE utf8_bin NOT NULL COMMENT 'Nom d''utilisateur',
  `uti_mot_passe` varchar(10) COLLATE utf8_bin NOT NULL COMMENT 'Mot de passe de l''utilisateur',
  PRIMARY KEY (`uti_id_personne`),
  KEY `x_uti_login` (`uti_login`),
  KEY `c_fk_uti_id_personne` (`uti_id_personne`),
  KEY `c_fk_uti_id_type_utilisateur` (`uti_id_type_utilisateur`),
  KEY `FKD5A26A0C856BF70A` (`uti_id_type_utilisateur`),
  CONSTRAINT `c_fk_uti_id_personne` FOREIGN KEY (`uti_id_personne`)  REFERENCES `t_e_personne_prs` (`prs_id`) ON DELETE CASCADE ON UPDATE NO  ACTION,
  CONSTRAINT `c_fk_uti_id_type_utilisateur` FOREIGN KEY  (`uti_id_type_utilisateur`) REFERENCES `t_e_type_utilisateur_tu`  (`tu_id`) ON UPDATE NO ACTION,
  CONSTRAINT `FKD5A26A0C856BF70A` FOREIGN KEY (`uti_id_type_utilisateur`) REFERENCES `t_e_type_utilisateur_tu` (`tu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Table des utilisateurs de l''application. Hérite de la table ';

 

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY  DEFINER VIEW `v_utilisateur_personne_type` AS select  `u`.`uti_id_personne` AS `uti_id_personne`,`u`.`uti_login` AS  `uti_login`,`u`.`uti_mot_passe` AS `uti_mot_passe`,`p`.`prs_nom` AS  `prs_nom`,`p`.`prs_prenom` AS `prs_prenom`,`p`.`prs_adrel` AS  `prs_adrel`,`p`.`prs_telephone` AS `prs_telephone`,`tu`.`tu_id` AS  `id_type_utilisateur`,`tu`.`tu_libelle` AS `type_utilisateur` from  ((`t_e_personne_prs` `p` join `t_h_utilisateur_uti` `u`  on((`u`.`uti_id_personne` = `p`.`prs_id`))) join  `t_e_type_utilisateur_tu` `tu` on((`tu`.`tu_id` =  `u`.`uti_id_type_utilisateur`)));

 

Then, File / New / Seam Generate Entities

 

3.1) Window "Generate Seam Entities

Seam Project : stamas
Hibernate console configuration : stamas
Generation mode : Reverse engineer from database
=> Next >

 

3.2) Generate Seam Entities Select Tables

Clic on Refresh, browse the catalog and select tables.

Clic on Include, the tables appear in the right part of the window.

Finish

 

The tables are already imported and the CRUD xhtml pages are created.

 

When I restart the app and try to Browse Data / TEPersonnePrs or any other table, I have the error explained in my previous message.

 

Thank you for your help.

Reply to this message by going to Community

Start a new discussion in JBoss Tools at Community