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)
      (persistence-unit name="joms")
      (provider>org.hibernate.ejb.HibernatePersistence</provider)
      (jta-data-source>java:/DefaultDS</jta-data-source)
      (properties>
      (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"/);
      (/properties)
      (/persistence-unit)
      (/persistence)




      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;

      @Entity
      @Name("node")
      @Scope(SESSION)
      @Table(name="nodes")
      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
      }

      @NotNull
      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
      s:ear=jboss-seam-nodes.ear,jar=jboss-seam-nodes.jar,unitName=joms
      java.lang.RuntimeException: java.lang.NoSuchMethodError: org.hibernate.cfg.Annot
      ationConfiguration.setEntityNotFoundDelegate(Lorg/hibernate/proxy/EntityNotFound
      Delegate;)V







      At runtime I can get to my data entry page via



      http://localhost:8080/seam-nodes/nodes.seam




      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
      0:_id5
      at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
      nListenerImpl.java:74)
      at javax.faces.component.UICommand.broadcast(UICommand.java:106)
      at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:9
      0)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1
      64)
      at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(Lifecycl
      eImpl.java:316)
      at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java
      :86)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      icationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      ilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
      lter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      icationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      ilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
      alve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
      alve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
      yAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
      e.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
      ava:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
      ava:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
      ve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
      a:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
      :869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
      rocessConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
      int.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
      kerThread.java:112)
      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
      :165)
      at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
      nListenerImpl.java:63)
      ... 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
      esolver.java:44)
      at org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVari
      able(ValueBindingImpl.java:569)
      at org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
      at org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(Value
      BindingImpl.java:450)
      at org.apache.myfaces.el.MethodBindingImpl.resolveToBaseAndProperty(Meth
      odBindingImpl.java:180)
      at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
      :114)
      ... 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?

      thanks

      jim s






        • 1. Re: Seam and Hibernate
          Justin Newbie

           

          13:38:54,018 WARN [ServiceController] Problem starting service persistence.unit
          s:ear=jboss-seam-nodes.ear,jar=jboss-seam-nodes.jar,unitName=joms
          java.lang.RuntimeException: java.lang.NoSuchMethodError: org.hibernate.cfg.Annot
          ationConfiguration.setEntityNotFoundDelegate(Lorg/hibernate/proxy/EntityNotFound
          Delegate;)V


          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



            (local-tx-datasource>
            (jndi-name>WorkDS</jndi-name>
            (connection-url>jdbc:mysql://localhost:3306/joms</connection-url>
            (driver-class>com.mysql.jdbc.Driver</driver-class>
            (user-name>xxxxxx</user-name>
            (password>xxxxxx
            (connection-property name="autoReconnect">true</connection-property>
            (metadata>
            (type-mapping>mySQL</type-mapping>
            (/metadata>
            (/local-tx-datasource>
            (/datasources>

            But how to I do the same it in Seam?


            jim

            • 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
              urceConnectionProvider
              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
              tory
              23:46:54,093 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBoss
              TransactionManagerLookup
              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,

              Sean

              • 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.

                  Thanks

                  :-)

                  • 6. Re: Seam and Hibernate
                    jim shirreffs Newbie

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

                    jim