User: dsundstrom
  Date: 02/03/12 14:25:51

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge
                        JDBCCMRFieldBridge.java
  Log:
  Fixed bug that when loading a foreign-key mapped relation in which the
  entites use custom primary key types JBossCMP would try to load the value
  of the fk into the wrong type (the type of the current entity's pk).
  
  Revision  Changes    Path
  1.26      +30 -2     
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java
  
  Index: JDBCCMRFieldBridge.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- JDBCCMRFieldBridge.java   26 Feb 2002 23:28:55 -0000      1.25
  +++ JDBCCMRFieldBridge.java   12 Mar 2002 22:25:50 -0000      1.26
  @@ -55,7 +55,7 @@
    *      One for each role that entity has.       
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.25 $
  + * @version $Revision: 1.26 $
    */                            
   public class JDBCCMRFieldBridge implements JDBCFieldBridge, CMRFieldBridge {
      // ------ Invocation messages ------
  @@ -1012,18 +1012,46 @@
      public int loadArgumentResults(
            ResultSet rs,
            int parameterIndex,
  -         Object[] argumentRef) {
  +         Object[] fkRef) {
   
         if(!hasForeignKey()) {
            return parameterIndex;
         }
   
  +      // value of this field,  will be filled in below
  +      Object[] argumentRef = new Object[1];
         for(Iterator fields = foreignKeyFields.iterator(); fields.hasNext();) {
            JDBCCMPFieldBridge field = (JDBCCMPFieldBridge)fields.next();
            parameterIndex = field.loadArgumentResults(
                  rs,
                  parameterIndex,
                  argumentRef);
  +      
  +         if(field.getMetaData().getPrimaryKeyField() != null) {
  +            // if we are tring to set a null value 
  +            // into a null pk, we are already done.
  +            if(argumentRef[0] != null || fkRef[0] != null) {
  +            
  +               // if we don't have a pk object yet create one
  +               if(fkRef[0] == null) {
  +                  fkRef[0] = relatedEntity.createPrimaryKeyInstance();
  +               }
  +            
  +               try {
  +                  // Set this field's value into the primary key object.
  +                  field.getMetaData().getPrimaryKeyField().set(
  +                        fkRef[0],
  +                        argumentRef[0]);
  +               } catch(Exception e) {
  +                  // Non recoverable internal exception
  +                  throw new EJBException("Internal error setting foreign-key " +
  +                        "field " + getFieldName(), e);
  +               }
  +            }
  +         } else {
  +            // This field is the primary key, so no extraction is necessary.
  +            fkRef[0] = argumentRef[0];
  +         }
         }
         return parameterIndex;
      }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to