1 Reply Latest reply on Mar 1, 2006 6:14 PM by gavin.king

    Composite Ids

    rengar

      I make mini example seams app (typical user-rol tables).

      The source code was generated with hibernate-tools beta4
      and was fixed some errors of generator.

      usuario (usuario,password) --> Id (usuario)
      rol(rol) --> Id (rol)
      usuario_rol(usuario, rol) --> Composite id (usuario, rol)


      Jboss throws this error when I go to "http://localhost:8080/seamapp/editUsuarioRol.jsf" :


      10:29:27,361 ERROR [[/seamapp]] Cannot set value for expression '#{usuariorolEditor.instance.id}' to a new value of type java.lang.String
      javax.faces.el.EvaluationException: Cannot set value for expression '#{usuariorolEditor.instance.id}' to a new value of type java.lang.String
       at org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java
      :304)
      .
      .
      Caused by: java.lang.IllegalArgumentException: argument type mismatch
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.apache.myfaces.el.PropertyResolverImpl.setProperty(PropertyResolv
      erImpl.java:368)
       ... 33 more


      The source code composite id :

      // Generated 23-feb-2006 17:09:37 by Hibernate Tools 3.1.0.beta4
      
      import javax.persistence.Column;
      import javax.persistence.Embeddable;
      
      
      /**
       * UsuarioRolId generated by hbm2java
       */
      @Embeddable
      
      public class UsuarioRolId implements java.io.Serializable {
      
      
       // Fields
      
       private String usuario;
       private String rol;
      
      
       // Constructors
      
       /** default constructor */
       public UsuarioRolId() {
       }
      
      
       /** full constructor */
       public UsuarioRolId(String usuario, String rol) {
       this.usuario = usuario;
       this.rol = rol;
       }
      
      
      
       // Property accessors
       @Column(name="usuario", unique=false, nullable=false, insertable=true, updatable=true, length=20)
      
       public String getUsuario() {
       return this.usuario;
       }
      
       public void setUsuario(String usuario) {
       this.usuario = usuario;
       }
       @Column(name="rol", unique=false, nullable=false, insertable=true, updatable=true, length=20)
      
       public String getRol() {
       return this.rol;
       }
      
       public void setRol(String rol) {
       this.rol = rol;
       }
      
      
      
      
       public boolean equals(Object other) {
       if ( (this == other ) ) return true;
       if ( (other == null ) ) return false;
       if ( !(other instanceof UsuarioRolId) ) return false;
       UsuarioRolId castOther = ( UsuarioRolId ) other;
      
       return ( (this.getUsuario()==castOther.getUsuario()) || ( this.getUsuario()!=null && castOther.getUsuario()!=null && this.getUsuario().equals(castOther.getUsuario()) ) )
       && ( (this.getRol()==castOther.getRol()) || ( this.getRol()!=null && castOther.getRol()!=null && this.getRol().equals(castOther.getRol()) ) );
       }
      
       public int hashCode() {
       int result = 17;
      
       result = 37 * result + ( getUsuario() == null ? 0 : this.getUsuario().hashCode() );
       result = 37 * result + ( getRol() == null ? 0 : this.getRol().hashCode() );
       return result;
       }
      
      }
      



      This error is throwing when i select one rol for one user.

      I have in "editUsuarioRol.jsf" one inputText box for id.

      How introduce "id" in this box if "id" is a object not a String ???