Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part III

Seam Tomcat Deployment

In this part III of the tutorial, we’ll build the entity classes from the database we created in Part I and configure the Seam project we created in Part II so as to make it fully compatible with Apache Tomcat.

Creating The Model Layer

We’ll use Hibernate‘s reverse engineering tool (hbm2java) embedded in Seam-gen to create the entity classes from the database we created in part 1.

Seam Generate Entities

Figure 3.1 - Generating entities from database in JBoss Seam

Right-click the project blog in project explorer and select New > Seam Generate Entities.

Reverse Engineering from database

Figure 3.2 - Reverse Engineering from database

Select reverse engineer from database and then click ‘next‘ like shown in figure 3.2.

Reverse engineering from database (2)

Figure 3.3 - Reverse engineering from database (2)

To display the database schema in the first place, you may need to hit the refresh button first. Since we set everything up properly (did you, too? 🙂 in Part II, we don’t need to tackle anything else – just click Finish.

Entity classes and the controller classes

Figure 3.4 - Seam-generated entity classes and controllers

And voilà! After some processing, our entities should show up in the project explorer along with some controller classes as well as the (JSF) xhtml files in the web content as shown in figure 3.4.

The classes with the suffix ‘Home’ such as CategoryHome are some sort of a JSF managed bean + JPA controller combo’s. In fact, these classes extend Seam’s EntityHome class which is pre-built with most of the methods for instantiating the entity object and performing CRUD operations using Seam’s built-in EntityManager. Likewise, the other classes in the session package with the suffix ‘List’ such as CategoryList extend Seam’s EntityQuery class which make it easy to perform certain basic persistence queries on entities without having to write so many lines of code to invoke the EntityManager, start transactions and run queries.

In the next section we’ll do some hacks and mods to the project and make it Tomcat-savvy, so that we can preview what we’ve done so far by running the application and see it in the browser for ourselves.

Configuring the Seam Project for Tomcat Deployment

There are a few articles, blog and forum posts all over the Internet which describe how to deploy a Seam application on Tomcat. But in my experience, none of them alone were accurate for deploying Seam 2.2 apps on Tomcat 6 (and perhaps 7, too) without crashing Tomcat at startup. Either one or more of the required jars were never mentioned, or components.xml modification was not correctly described.

In this part of the tutorial, I will explain step-by-step what exactly is necessary to be done and which versions of which libraries are exactly the ones to be included in the project so that Tomcat won’t crash as soon as started up – and neither your application.

The required library jar files (some of them are already be present in the project as we set up user defined JSF libraries in part II and some of them – and unfortunately not all of them come with recent versions of Seam):

  • antlr.jar
  • asm.jar
  • cglib.jar
  • commons-beanutils.jar
  • common-collections.jar
  • commons-digester.jar
  • commons-lang.jar
  • commons-logging.jar
  • dom4j.jar
  • hibernate-annotations.jar
  • hibernate-commons-annotations.jar
  • hibernate-entitymanager.jar
  • hibernate.jar
  • hibernate-validator.jar
  • javassist.jar
  • jboss-archive-browsing.jar
  • jboss-el.jar
  • jboss-seam-debug.jar
  • jboss-seam.jar
  • jboss-seam-ui.jar
  • jsf-api.jar
  • jsf-facelets.jar
  • jsf-impl.jar
  • jstl.jar
  • jta.jar
  • lucene-core.jar
  • persistence-api.jar
  • richfaces-api.jar
  • richfaces-impl.jar
  • richfaces-ui.jar
  • \test\hibernate-all.jar

You can download all of these necessary files in a zip file here. After downloading, decompress them in a folder on your computer and follow the steps in the next section to import them into your project. Please note that since some of them are already present in your project’s WEB-INF/lib, be sure to uncheck ‘overwrite existing files’ option.

Importing the .jar files into the Eclipse Project

Expand the WebContent folder and then the WEB-INF folder residing inside of it in Eclipse’s package explorer so that you reveal WEB-INF/lib. Then right-click lib, and select ‘Import…’ from the dropdown menu that pops up.

Importing Seam jars into WEB-INF/lib

Figure 3.5 - Importing Seam jars into WEB-INF/lib

Select ‘File System’ as the import source and click ‘Next’. Then select the folder in your file system (i.e. Windows explorer on the PC, or the Finder on the Mac)

Adding external JARs into your Eclipse Project

Figure 3.6 - Copying external JARs into your Eclipse Project from the file system

Refer to figure 3.6 and make sure you tick the checkbox next to the name of the folder containing the jar files to select them all at once (if you don’t want to individually select the checkboxes of the jar files yourself) then make sure of the following:

  • Into folder: blog/WebContent/WEB-INF/lib (importing the jars anywhere outside this path will fail you)
  • Overwrite existing resources without warning had better be unchecked. Why? Because if you try this tutorial with a version of Seam other than 2.2, you probably want to keep the original versions of the duplicate jars that shipped with Seam – for not risking anything to break up.
  • Create selected folders only is as good as checked. (It should be so by default anyway)

Click Finish to start importing the Seam libraries from the file system.

Dealing with duplicate libraries in the import process

Figure 3.7 - Dealing with duplicate Seam libraries in the import process

In case you’re asked what to do about overwriting some of the libraries already existing in your project, go with ‘No to All’. Because if you try this tutorial with a version of Seam other than 2.2, you probably want to keep the original versions of the duplicate jars that shipped with Seam – for not risking anything to break up.

Modifying the data source for Tomcat

Every Seam project created with Seam-Gen or JBoss Tools comes with a datasource definition in XML format called ‘blog-ds.xml’ residing in a folder called ‘resources’ in the project folder. This approach of ‘deploying the datasource to the server’ suits the JBoss AS very well, but in the case of Tomcat, the portable datasource definition file is useless and we need to define the datasource differently on Tomcat so as to have it supply us the database connection when running our application.

Therefore we will now create a file named context.xml in our WebContent/META-INF folder and create a new resource there. Fill the context.xml with the following definitions:

<?xml version="1.0" encoding="UTF-8"?>

<Context docBase="blog" path="/blog" reloadable="true">

  <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
  maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/seamblog"
  password="12345"
  type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/seamblog"
  username="blogger" />

</Context>

Now we need to handle the other configuration files which use this connection. First of them is persistence.xml is which contains the definition of our JPA persistence unit. We need to change the jta-data-source value which is normally intended for a container-managed transaction such as on JBoss AS. Since we’re working for Tomcat deployment here, we need to change the transaction type to the local resource in persistence.xml.

Open persistence.xml (src/main/META-INF/persistence.xml) and modify the persistence unit so as to resemble the following:

<?xml version="1.0" encoding="UTF-8"?>
<persistence-unit name="seamblogPU" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:comp/env/jdbc/seamblog</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>         
         <property name="hibernate.default_catalog" value="seamblog"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/blogEntityManagerFactory"/>
      </properties>
   </persistence-unit>

Here we defined the data-source as java:comp/env/jdbc/seamblog for Tomcat requires all connection JNDI names to be prefixed with java:comp/env.

Finally we will modify the components.xml which holds the definition of certain Seam components and resides in WEB-INF folder.

There are a few things to do in components.xml

First add an XML namespace definition for transaction:

xmlns:transaction="http://jboss.com/products/seam/transaction"

and its

 xsi:schemaLocation = http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd

then add the following line somewhere:

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

Also the persistence-related definitions should be something like:

   <!-- If you are using Tomcat, you need the following to have your PU started -->
  <persistence:entity-manager-factory name="entityManagerFactory"
                     persistence-unit-name="seamblogPU"/>
   <!-- If you are using Tomcat, you need the following as well to have the entityManagerFactory used -->
  <persistence:managed-persistence-context name="entityManager" auto-create="true"
                         entity-manager-factory="#{entityManagerFactory}"/>

   <!-- If you are not using JBoss AS 5 or above, the following should be commented -->
<!--    <persistence:managed-persistence-context name="entityManager" auto-create="true" -->
<!--                            persistence-unit-jndi-name="java:/blogEntityManagerFactory"/> -->

Least but not last, open up your web.xml and add the following:

<resource-ref>
        <res-ref-name>jdbc/seamblog</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
 </resource-ref>

Running the Seam Blog Project for the first time

Now let’s run the project and see what we’ve done.

Right-click the project name and select Run As > Run on Server from the pop-up menu. Remember to choose Tomcat for target server.

If you’ve done everything correctly or at least as instructed in this tutorial, you should be welcomed with Seam’s cute welcome page thanks to its default template as shown in figure 3.7.

Seam Project Successfully Deployed

Figure 3.7 - The Successfully Deployed Seam Blog Project

You can customize the welcome page by modifying home.xhtml at the root of the web content folder.
Now let’s test our new app a little: Go to the menu bar of Seam Blog and click Browse data to pull down a menu from which I want you to select ‘Category List’. Here we will encounter a blank categories list. Click ‘Create Category’ and after a possible user authentication which you may pass just by entering ‘admin’ as the username and leaving the password blank (we haven’t programmed the user authentication yet), you should then encounter a form like the one in figure 3.8:

Creating a new category for the blog

Figure 3.8 - Creating a new category for the blog

I created my first category as ‘General’ and hit ‘Save’. Then I’ll repeat the step to create a few more categories such as ‘IT’, ‘Internet’, ‘Movies’ and ‘Music’.

Category list filled up

Figure 3.9 - Seam Blog category list filled up

Finally I’ll go to Users section, to create the blog’s first user: Me!

Creating blog users

Figure 3.10 - Creating blog's users

The user entry page signals us that the form needs our help with certain aspects such as converting the password field into a real password field hiding the entered characters – i.e. JSF-wise an <h:inputSecret /> and the level field seems to make no sense there and should be worked on.

You could also choose to experiment with the post entry form which I saved for last, but not as best, yet you will probably find out how peculiar it is to select a category and a user from a grid on a separate screen instead of a pop-up menu when entering a blog post – assuming of course you did not get a “duplicate Id for a component selectParent” error which arises due to a Seam-gen 2.2 bug when the generated page of a given entity has more than one other object association – in our case the Post entity has Many-to-One associations of the Category and User entities respectively.

Our project has now some basic CRUD functionality and runs on Tomcat. In Part IV of the tutorial, we will customize the code, correct the buggy code Seam-gen gave us, and add some of our own code, all in JSF.

Be Sociable, Share!

23 thoughts on “Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part III

  1. Very nice. That was very useful I don’t think there is anything else out there on the whole web that goes through the whole process to get a seam app running under tomcat. Much appreciated.

    Doug

    • I’m glad you found it useful. I was suffering the lack of an extensive resource myself, especially getting an up-to-date version of Seam work on an external container such as Tomcat, which is precisely why I went through all the details to be more helpful in the Seam community.

      In part IV, I’ll go to more detail in cutomization via (hands-on) coding.

  2. I did exactly what you said here, but I’m getting

    org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

    although it’s among the library jars in WEB-INF/lib.

    Can you help?

  3. Hi Gokhan. I did exactly what you said but i am confronted to a problem when i have to login.

    When i enter admin and a blank password, nothing changes…

    Can you help?

    • Sure, I’d like to. I need to make sure that you’re referring to MySQL and nned to know on which screen or interface you’re facing this problem. Do you mean Navicat or JBoss Tools’ db connection setup?

  4. I am referring to the page login.seam. Whatever i enter in the fields username and password,, it keep saying me login failed.

    • I have a feeling that you already went through the next chapter (Part IV) and changed the Authenticator.java (Seam) component so that it now authenticates from the users table in the database.

      If this is the case, then enter the username and password of the user you created in part III.

      If this is not the case, I’d need to see the log file or your console output, to understand what the matter is.

  5. When i run the project, i have no errors.

    There is what happened in my console :

    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jboss-seam-excel.jar!/META-INF/seam-excel.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jboss-seam-mail.jar!/META-INF/seam-mail.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jboss-seam-pdf.jar!/META-INF/seam-pdf.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jboss-seam-ui.jar!/META-INF/s.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-core.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-html.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-ui.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-core.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-fn.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/jsf-impl.jar!/META-INF/mojarra_ext.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/richfaces-ui.jar!/META-INF/a4j.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/richfaces-ui.jar!/META-INF/rich.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/richfaces-ui.jar!/META-INF/jsp.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/richfaces-ui.jar!/META-INF/richfaces.taglib.xml
    21 mars 2012 12:46:21 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
    INFO: Added Library from: jar:file:/home/nelson/workspace/WorkSpace%20WebAPP/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/blog/WEB-INF/lib/richfaces-ui.jar!/META-INF/ajax4jsf.taglib.xml
    

    And i havent done part 4 yet. The only difference is that i didnt create a user named blogger on part 1.

  6. How i can i disable the login in order to check if the CRUD application is fine?

    Thanks a lot for your help and time 😉

    • Well, apparently your console output does indeed give no clue.

      You can check Authenticator.java to investigate what’s going on.

      To remove the authentication requirement for editing data (for list views, there’s none anyway) open the .page.xml of the corresponding view (e.g. PostEdit.xhtml must have a corresponding PostEdit.page.xml) and then within the page tag (i.e.

       <page xlmns="http://jboss.com/products/seam/pages" ...> 

      ) set login-required=false .

      Then you should be able to browse any view and perform any CRUD operation without having to be authenticated.

      P.S. If there’s no .page.xml file then the definitions must have been cramped in pages.xml under WEB-INF.

      • Ok thanks a lot. Finally, i have a problem with my database. When i click to search menu or to edit something, this appears to me :

        Error

        Something bad happened :-(

        * Unexpected error, please try again

        In the console :

        ATTENTION: /UserList.xhtml @19,71 value="#{userList.user.name}": Target Unreachable, identifier 'userList' resolved to null
        javax.el.PropertyNotFoundException: /UserList.xhtml @19,71 value="#{userList.user.name}": Target Unreachable, identifier 'userList' resolved to null
        

        I think its the reason why I couldnt login.

  7. Hi Gokhan. firstly thank you for this tutorial, when i run the project, i have these errors :

    org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
    	at org.jboss.seam.Component.newInstance(Component.java:2170)
    	at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
    	at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
    	at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:143)
    	at org.jboss.seam.init.Initialization.init(Initialization.java:744)
    	at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    	at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named seamblogPU
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    	at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:81)
    	at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    	at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
    	at org.jboss.seam.Component.callComponentMethod(Component.java:2283)
    	at org.jboss.seam.Component.callCreateMethod(Component.java:2198)
    	at org.jboss.seam.Component.newInstance(Component.java:2158)
    	... 20 more
    

    Can you help me ?

    • Pedro, sorry for the late reply. You seem to have not successfully included the necessary Hibernate (JPA) libraries. Did you download the jars I included and put them in the class path? Also remember to include the log4j definitions (I also featured as a separate download). You can download all these files in the Downloads section. Hope this helps.

    • Hi, I’m sorry for the delay, some html tag broke up the content of the page which made the instructions for creating the database tables disappear. I fixed it, so you should be able to make some use of it.

      Any other questions & comments appreciated.

  8. Hi,

    I think there’s some text missing where it says “then add the following line somewhere:”.

    Also, what xml tags should i use to add the following to the web.xml file:

    jdbc/seamblog
    javax.sql.DataSource
    Container

    • Hi vitor,

      I’m terribly sorry, due to a WordPress bug, the original content has become corrupted after a few minor edits, and I can’t seem to restore any backup edition of the text.

      I’ll revise from the beginning and rewrite it as soon as I have some free time (hopefully within this week).

      Meanwhile I’d be more than happy to assist you in your Seam project – just share with me some specs.

  9. Hey, thanks for the writing, but I’m getting the following exception when I follow the steps above for deploying a seam 2.2 application on tomcat 7:

    SEVERE: Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
    org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
    	at org.jboss.seam.Component.newInstance(Component.java:2170)
    	at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
    	at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
    	at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:143)
    	at org.jboss.seam.init.Initialization.init(Initialization.java:744)
    	at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: consmanPU] Unable to build EntityManagerFactory
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
    	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    	at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:81)
    	at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    	at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
    	at org.jboss.seam.Component.callComponentMethod(Component.java:2283)
    	at org.jboss.seam.Component.callCreateMethod(Component.java:2198)
    	at org.jboss.seam.Component.newInstance(Component.java:2158)
    	... 15 more
    Caused by: org.hibernate.HibernateException: Could not find datasource
    	at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
    	at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
    	at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
    	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
    	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    	... 29 more
    Caused by: javax.naming.NameNotFoundException: Name [consmanDatasource] is not bound in this Context. Unable to find [consmanDatasource].
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    	at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
    	at javax.naming.InitialContext.lookup(Unknown Source)
    	at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
    	... 36 more
    
    • From the lower pane of Eclipse / JBoss Developer Studio (or whatever IDE you’re using) go to Servers tab, double-click Apache Tomcat v7.0 Server at localhost, and in the Overview sheet under ‘Server Options’ check Publish module contexts to separate XML files. Make sure Tomcat is not running before you save the configuration. Finally republish the project and restart Tomcat. This should solve the problem.

      Tomcat configuration for Seam in Eclipse

Leave a Reply

Your email address will not be published. Required fields are marked *


*