@@ -137,11 +137,14 @@ protected final void init(long id, String...fieldNames) throws SQLException {
137137
138138
139139 StringBuilder sql = new StringBuilder ("select " );
140+ boolean addID = true ;
140141 for (int i =0 ; i <fieldNames .length ; i ++){
141142 if (i >0 ) sql .append (", " );
142143 String fieldName = fieldNames [i ];
144+ if (fieldName .equalsIgnoreCase ("id" )) addID = false ;
143145 sql .append (escape (fieldName ));
144146 }
147+ if (addID ) sql .append (", id" );
145148 sql .append (" from " );
146149 sql .append (tableName );
147150 sql .append (" where id=" );
@@ -743,8 +746,8 @@ protected static Connection getConnection(Class c) throws SQLException {
743746 //**************************************************************************
744747 //** init
745748 //**************************************************************************
746- /** Used to associate a model with a database connection pool. This allows
747- * queries and other database metadata to be cached.
749+ /** Used to initialize a Model and associate it with a database connection
750+ * pool. This allows queries and other database metadata to be cached.
748751 <pre>
749752 for (Jar.Entry entry : jar.getEntries()){
750753 String name = entry.getName();
@@ -758,7 +761,7 @@ protected static Connection getConnection(Class c) throws SQLException {
758761 }
759762 </pre>
760763 */
761- public static void init (Class c , ConnectionPool connectionPool ){
764+ public static void init (Class c , ConnectionPool connectionPool ) throws SQLException {
762765
763766 String className = c .getName ();
764767
@@ -796,19 +799,21 @@ public static void init(Class c, ConnectionPool connectionPool){
796799 }
797800 catch (Exception e ){
798801 if (conn !=null ) conn .close ();
799- e .printStackTrace ();
802+ SQLException ex = new SQLException ("Failed to initialize Model: " + className );
803+ ex .setStackTrace (e .getStackTrace ());
804+ throw ex ;
800805 }
801806 }
802807
803808
804809 //**************************************************************************
805810 //** init
806811 //**************************************************************************
807- /** Used to associate all the models found in a JAR file with a database
808- * connection pool. This allows queries and other database metadata to be
809- * cached.
812+ /** Used to initialize all the Models found in a jar file and associate them
813+ * with a database connection pool. This allows queries and other database
814+ * metadata to be cached.
810815 */
811- public static void init (javaxt .io .Jar jar , ConnectionPool connectionPool ){
816+ public static void init (javaxt .io .Jar jar , ConnectionPool connectionPool ) throws SQLException {
812817 for (Class c : jar .getClasses ()){
813818 if (javaxt .sql .Model .class .isAssignableFrom (c )){
814819 init (c , connectionPool );
0 commit comments