6 Replies Latest reply on Aug 10, 2006 9:06 AM by jim shirreffs

    Seam and Hibernate

    jim shirreffs Newbie

      Hi, again.

      I am trying to clone the register example and make it work with one of my beans that uses hibernate for persistance (mySql). So far without success. I was wondering if anyone has a roadmap on how to do that? I have an up and runing JBoss/EBJ3/Hibernate web application I am trying to see how dificult and what advantages I get by porting to Seam. My appliactions contains hundred of beans and many dozens of actions. I am just trying to get one simple little bean and once fetch action going.

      Here is what the table looks like

      | Field | Type | Null | Key | Default | Extra |
      | node_id | varchar(180) | | PRI | | |
      | node_name | varchar(80) | | | | |
      | description | varchar(240)| | | | |
      | vault_id | int(11) | | | 0 | |
      | security_model_id | int(11) | | | 0 | |

      Here is my persistance.xml

      ( = < and ) = > since I can't turn html off.

      (persistence-unit name="joms")
      (property name ="hibernate.show_sql" value="true"/)
      (property name ="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/)
      (property name ="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/)
      (property name ="hibernate.dialect" value="org.hibernate.dialect.MySQLMyISAMDialect"/)
      (property name ="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/)
      (property name ="hibernate.connection.username" value="xxxxxx"/)
      (property name ="hibernate.connection.password" value="xxxxxx"/)
      (property name ="hibernate.connection.url" value="jdbc:mysql:///joms"/);

      Here is what the bean looks like, (clone of user.java in register example.

      //$Id: User.java,v 1.9 2005/09/10 19:08:01 gavin Exp $
      package org.jboss.seam.example.nodes;

      import static org.jboss.seam.ScopeType.SESSION;

      import java.io.Serializable;

      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;

      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;

      public class Node implements Serializable
      private static final long serialVersionUID = 1881413500711441951L;

      private String nodeId;
      private String nodeName;

      public Node(String id, String name)
      this.nodeId = id;
      this.nodeName = name;

      public Node()
      //do nothing

      public String getNodeName()
      return nodeName;

      public void setNodeName(String s)
      this.nodeName = s;

      @Id @NotNull @Length(min=2, max=16)
      public String getNodeId()
      return nodeId;

      public void setNodeId(String s)
      this.nodeId = s;
      public String toString()
      return "Node(" + nodeId + ")";

      Evedrything else is a clone of registration except I replace register with nodes every where it occured.

      At service startup I get this warning

      13:38:54,018 WARN [ServiceController] Problem starting service persistence.unit
      java.lang.RuntimeException: java.lang.NoSuchMethodError: org.hibernate.cfg.Annot

      At runtime I can get to my data entry page via


      But on submit I get

      13:43:24,002 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet
      threw exception
      javax.faces.FacesException: Error calling action method of component with id _id
      at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
      at javax.faces.component.UICommand.broadcast(UICommand.java:106)
      at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:9
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1
      at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(Lifecycl
      at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
      at java.lang.Thread.run(Unknown Source)
      Caused by: javax.faces.el.EvaluationException: Exception while invoking expressi
      on #{nodes.node}
      at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
      at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
      ... 24 more
      Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam com
      ponent: nodes
      at org.jboss.seam.Component.newInstance(Component.java:735)
      at org.jboss.seam.Component.newInstance(Component.java:1308)
      at org.jboss.seam.Component.getInstance(Component.java:1263)
      at org.jboss.seam.Component.getInstance(Component.java:1246)
      at org.jboss.seam.jsf.SeamVariableResolver.resolveVariable(SeamVariableR
      at org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVari
      at org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
      at org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(Value
      at org.apache.myfaces.el.MethodBindingImpl.resolveToBaseAndProperty(Meth
      at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
      ... 25 more
      Caused by: javax.naming.NameNotFoundException: jboss-seam-nodes not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at org.jboss.seam.Component.instantiate(Component.java:774)
      at org.jboss.seam.Component.newInstance(Component.java:731)
      ... 34 more

      I am pretty sure I have a configuration problem. Anyone have any pointers, examples, anything that might help me get going?


      jim s

        • 1. Re: Seam and Hibernate


          13:38:54,018 WARN [ServiceController] Problem starting service persistence.unit
          java.lang.RuntimeException: java.lang.NoSuchMethodError: org.hibernate.cfg.Annot

          Looks like you have a class/jar incompatibility issue. Did you download and install the ejb3 version of the jboss JEMS as documented in the installation page of the wiki? http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamInstallation

          • 2. Re: Seam and Hibernate
            jim shirreffs Newbie

            Re class/jar imcompatability

            I will check that out. I did not suspect that might be a problem since most (but not all) of the examples are working fine. I think my problem is that my back end is an Entity Bean so the conatiner is handling persistant. In the real world I will make the backend bean a POJO and handle persistant myself, but before I go there I want to be able to understand how to configure JBoss/Seams to use Hibernate/MySql for entity beans.

            I am trying to understand JSF, so I can evaluate it usefulness. I really like EJB3 now that Hibernate is good at Object to Relation modeling. But the User Interface guys/gals think the JSF MVC framework is better then EJB MVC framework. I am not comvinced but I am willing to have a look. But unless I can get something, even a trivial something, real world like working it will be dificult to form an opiniun one way or the other.

            This is the second attempt at getting a little prototype going, the first attempt was made by someone else, and the results did not match expectations.

            The idea of an event driven UI is fine, I was one of the first to use XWindows long ago. So I like event driven UIs like Swing, but in a GET POST world how heavily a price am I going to have to paid?

            I am rambling, sorry. Well I hope someone can let me know how to configure this monter to use Hibernate/MySql for container managed persistance instead of the build in Hypersonic database. In EJB3 I would define a datasource like this

            (connection-property name="autoReconnect">true</connection-property>

            But how to I do the same it in Seam?


            • 3. Re: Seam and Hibernate
              Sean Radford Novice

              Anyone have an answer to this. I'm trying to simple take one of the example applications (seam-messages) and use MySql instead of HQL, but in the log on server start-up I get:

              23:46:53,140 INFO [Version] Hibernate EntityManager 3.2.0.CR1
              23:46:53,140 INFO [Version] Hibernate Annotations 3.2.0.CR1
              23:46:53,187 INFO [Ejb3Configuration] found EJB3 Entity bean: org.jboss.seam.example.messages.Message
              23:46:53,187 WARN [Ejb3Configuration] Persistence provider caller does not implements the EJB3 spec correctly. PersistenceU
              nitInfo.getNewTempClassLoader() is null.
              23:46:53,250 INFO [Configuration] Reading mappings from resource: META-INF/orm.xml
              23:46:53,250 INFO [Ejb3Configuration] [PersistenceUnit: messageDatabase] no META-INF/orm.xml found
              23:46:53,281 INFO [AnnotationBinder] Binding entity from annotated class: org.jboss.seam.example.messages.Message
              23:46:53,375 INFO [EntityBinder] Bind entity org.jboss.seam.example.messages.Message on table Message
              23:46:53,484 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSo
              23:46:53,484 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
              23:46:54,078 INFO [SettingsFactory] RDBMS: MySQL, version: 5.0.20-nt
              23:46:54,078 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-1
              1-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
              23:46:54,093 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
              23:46:54,093 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFac
              23:46:54,093 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBoss
              23:46:54,093 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
              23:46:54,093 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
              23:46:54,093 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
              23:46:54,093 INFO [SettingsFactory] JDBC batch size: 15
              23:46:54,093 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
              23:46:54,093 INFO [SettingsFactory] Scrollable result sets: enabled
              23:46:54,093 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
              23:46:54,093 INFO [SettingsFactory] Connection release mode: auto
              23:46:54,093 INFO [SettingsFactory] Maximum outer join fetch depth: 2
              23:46:54,093 INFO [SettingsFactory] Default batch fetch size: 1
              23:46:54,093 INFO [SettingsFactory] Generate SQL with comments: disabled
              23:46:54,093 INFO [SettingsFactory] Order SQL updates by primary key: disabled
              23:46:54,093 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
              23:46:54,093 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
              23:46:54,093 INFO [SettingsFactory] Query language substitutions: {}
              23:46:54,093 INFO [SettingsFactory] Second-level cache: enabled
              23:46:54,093 INFO [SettingsFactory] Query cache: disabled
              23:46:54,093 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
              23:46:54,093 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
              23:46:54,093 INFO [SettingsFactory] Structured second-level cache entries: disabled
              23:46:54,093 INFO [SettingsFactory] Echoing all SQL to stdout
              23:46:54,093 INFO [SettingsFactory] Statistics: disabled
              23:46:54,093 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
              23:46:54,093 INFO [SettingsFactory] Default entity-mode: pojo
              23:46:54,093 INFO [SessionFactoryImpl] building session factory
              23:46:54,109 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
              23:46:54,109 INFO [SchemaExport] Running hbm2ddl schema export
              23:46:54,109 INFO [SchemaExport] exporting generated schema to database
              23:46:54,125 ERROR [SchemaExport] Unsuccessful: create table Message (id bigint not null auto_increment, read bit not null,
              text text not null, title varchar(100) not null, datetime datetime not null, primary key (id))
              23:46:54,125 ERROR [SchemaExport] You have an error in your SQL syntax; check the manual that corresponds to your MySQL serv
              er version for the right syntax to use near 'read bit not null, text text not null, title varchar(100) not null, datetime da
              t' at line 1
              23:46:54,125 INFO [SchemaExport] Executing import script: /import.sql
              23:46:54,125 ERROR [SchemaExport] schema export unsuccessful
              org.hibernate.JDBCException: Error during import script execution
              at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:256)
              at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:190)

              Any help MUCH appreciated,


              • 4. Re: Seam and Hibernate
                Raja Master


                create table Message (id bigint not null auto_increment, read bit not null,
                text text not null, title varchar(100) not null, datetime datetime not null, primary key (id))

                The "read bit not null" is the problem. "read" is a function in mysql and it wont let you create a field with that. Try renaming your model's field name to be something like readMessage and it should work . This should effectively translate your SQL to be
                create table Message (id bigint not null auto_increment, readMessage bit not null,
                text text not null, title varchar(100) not null, datetime datetime not null, primary key (id))

                • 5. Re: Seam and Hibernate
                  Sean Radford Novice

                  Just got this working (and now see that raja has also posted the answer).

                  I worked out that the 'read' is an invalid name for a MySql column and so added the @Column(name="viewed") attribute to the Message.read property.



                  • 6. Re: Seam and Hibernate
                    jim shirreffs Newbie

                    M ind posting your persistance.xml, I like to get mine working too.