Dan Ch, Was this part of the 2.2.2 release. I actually had issues with the load [it was screwing up the columns] because their order in the resultset and in the iterator for getCMPFields was different. Actually got all that to work when I saw this update from you! Anyway, just wanted to confirm that this issue is NOT there in the standard 2.2.2 release. Vinay ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, June 06, 2001 2:07 AM Subject: [JBoss-dev] CVS update: jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc JDBCCommand.java JDBCLoadEntityCommand.java > User: danch > Date: 01/06/05 18:07:40 > > Modified: src/main/org/jboss/ejb/plugins/jaws/jdbc JDBCCommand.java > JDBCLoadEntityCommand.java > Log: > Fixed bug caused by change in load operation associated with finder optimization. > > Revision Changes Path > 1.32 +4 -3 jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.java > > Index: JDBCCommand.java > =================================================================== > RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.ja va,v > retrieving revision 1.31 > retrieving revision 1.32 > diff -u -r1.31 -r1.32 > --- JDBCCommand.java 2001/05/30 23:00:42 1.31 > +++ JDBCCommand.java 2001/06/06 01:07:40 1.32 > @@ -57,7 +57,7 @@ > * > * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a> > * @author <a href="mailto:[EMAIL PROTECTED]">Dirk Zimmermann</a> > - * @version $Revision: 1.31 $ > + * @version $Revision: 1.32 $ > */ > public abstract class JDBCCommand > { > @@ -386,6 +386,7 @@ > protected Object getResultObject(ResultSet rs, int idx, Class destination) > throws SQLException{ > > +log.debug("getting a "+destination.getName()+" from resultset at index "+idx); > Object result = null; > > Method method = (Method)rsTypes.get(destination.getName()); > @@ -484,9 +485,9 @@ > } catch (RemoteException e) { > throw new SQLException("Unable to load EJBObject back from Handle: " +e); > } catch (IOException e) { > - throw new SQLException("Unable to load a ResultSet column into a variable of type '"+destination.getName()+"': "+e); > + throw new SQLException("Unable to load a ResultSet column "+idx+" into a variable of type '"+destination.getName()+"': "+e); > } catch (ClassNotFoundException e) { > - throw new SQLException("Unable to load a ResultSet column into a variable of type '"+destination.getName()+"': "+e); > + throw new SQLException("Unable to load a ResultSet column "+idx+" into a variable of type '"+destination.getName()+"': "+e); > } > } > > > > > 1.10 +55 -10 jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCLoadEntityCommand.java > > Index: JDBCLoadEntityCommand.java > =================================================================== > RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCLoadEntity Command.java,v > retrieving revision 1.9 > retrieving revision 1.10 > diff -u -r1.9 -r1.10 > --- JDBCLoadEntityCommand.java 2001/05/27 00:49:15 1.9 > +++ JDBCLoadEntityCommand.java 2001/06/06 01:07:40 1.10 > @@ -11,6 +11,8 @@ > import java.lang.reflect.Method; > > import java.util.Iterator; > +import java.util.ArrayList; > +import java.util.List; > import java.util.HashMap; > > import java.rmi.NoSuchObjectException; > @@ -36,12 +38,28 @@ > * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a> > * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a> > * @author <a href="mailto:[EMAIL PROTECTED]">Dirk Zimmermann</a> > - * @version $Revision: 1.9 $ > + * @author <a href="mailto:[EMAIL PROTECTED]">danch (Dan Christopherson)</a> > + * @version $Revision: 1.10 $ > */ > public class JDBCLoadEntityCommand > extends JDBCQueryCommand > implements JPMLoadEntityCommand > { > + /**what is the position of each cmp field in the generated select statement? > + * this simply maps the position of the field in the CMP list to its position > + * in the generated select statement. This is neccessary because of the variable > + * number of key columns (which are skipped in a load) and because there can > + * be overlap between the two: pkfields and cmpfields are neither disjoint sets > + * nor is the cmpfields a subset of pkfields (not that that makes sense to > + * me right now, but I'll roll with it until I have more chance to analyse - danch) > + */ > + int [] cmpFieldPositionInSelect = null; > + > + /** This const is used in places where I need to add an offset to a count > + * to account for the fact that JDBC counts from one whilst every other > + * damn thing in the languase starts at 0, the way God intended! > + */ > + private static final int JDBC_WART_OFFSET = 1; > // Constructors -------------------------------------------------- > > public JDBCLoadEntityCommand(JDBCCommandFactory factory) > @@ -62,27 +80,47 @@ > String sql = "SELECT "; > HashMap alreadyListed = new HashMap(); > // put the key fields in first > + // we'll stash the column names here so that we can later map an overlapped > + // column (overlap between PK and CMP) into its spot in the select statement. > + String[] pkColumnNames = new String[jawsEntity.getNumberOfPkFields()]; > Iterator keyIt = jawsEntity.getPkFields(); > - boolean first = true; > + int fieldCount = 0; > while (keyIt.hasNext()) > { > PkFieldMetaData pkField = (PkFieldMetaData)keyIt.next(); > > - sql += (first ? "" : ",") + > - pkField.getColumnName(); > + sql += ((fieldCount==0) ? "" : ",") + pkField.getColumnName(); > alreadyListed.put(pkField.getColumnName().toUpperCase(), pkField); > - first = false; > + pkColumnNames[fieldCount]=pkField.getColumnName(); > + fieldCount++; > } > > + cmpFieldPositionInSelect = new int[jawsEntity.getNumberOfCMPFields()]; > Iterator it = jawsEntity.getCMPFields(); > - > + int cmpFieldCount = 0; > while (it.hasNext()) > { > CMPFieldMetaData cmpField = (CMPFieldMetaData)it.next(); > if (alreadyListed.get(cmpField.getColumnName().toUpperCase()) == null) { > sql += "," + cmpField.getColumnName(); > - alreadyListed.put(cmpField.getColumnName().toUpperCase(), cmpField); > + cmpFieldPositionInSelect[cmpFieldCount] = fieldCount+JDBC_WART_OFFSET; > + fieldCount++;//because this was another field in the select > + } else { > + //DO NOT increment field count, this isn't another in the select. > + //linear search (yech!) of the pkColumnNames - we only do this once per bean, however > + for (int i=0;i<pkColumnNames.length;i++) { > + if (pkColumnNames[i].equalsIgnoreCase(cmpField.getColumnName())) { > + cmpFieldPositionInSelect[cmpFieldCount] = i+JDBC_WART_OFFSET; > + break; > + } > + } > + if (cmpFieldPositionInSelect[cmpFieldCount] < 1) { > + log.error("Error: Can't find first occurence of repeated column "+ > + cmpField.getName()+" when building CMP load SQL for "+ > + jawsEntity.getName()); > + } > } > + cmpFieldCount++; > } > > sql += " FROM " + jawsEntity.getTableName(); > @@ -127,7 +165,6 @@ > } > > // Set values > -System.out.print("!"); > loadOneEntity(rs, ctx); > > return null; > @@ -135,7 +172,14 @@ > > protected void loadOneEntity(ResultSet rs, EntityEnterpriseContext ctx) throws Exception { > int idx = 1; > - > + // skip the PK fields at the beginning of the select. > + Iterator keyIt = jawsEntity.getPkFields(); > + while (keyIt.hasNext()) { > + keyIt.next(); > + idx++; > + } > + > + int fieldCount = 0; > Iterator iter = jawsEntity.getCMPFields(); > while (iter.hasNext()) > { > @@ -143,7 +187,8 @@ > > setCMPFieldValue(ctx.getInstance(), > cmpField, > - getResultObject(rs, idx++, cmpField)); > + getResultObject(rs, cmpFieldPositionInSelect[fieldCount], cmpField)); > + fieldCount++; > } > > // Store state to be able to do tuned updates > > > > > _______________________________________________ > Jboss-development mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-development _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-development