primefaces - create native query JSF -


i got error in codes :

javax.persistence.persistenceexception: exception [eclipselink-4002] (eclipse persistence services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.databaseexception internal exception: java.sql.sqlsyntaxerrorexception: syntax error: encountered ":" @ line 1, column 42. error code: -1 call: select userlevelid users id = :id query: datareadquery(sql="select userlevelid users id = :id ")

and code :

        public string cek() { if (tmp.equals(tmp2)) {           y =1;           level = getitems().tostring(); }            .....           .....         }          public list<users> getitems() {          if (y.equals(1)) {          y=0;          tmp = tmp.trim();          return em.createnativequery("select userlevelid users id = :id")          .setparameter("id", tmp).getresultlist(); }     } 

so where's fault ? can me ? thx b4

main problem

  • native queries don't use named parameter syntax (:id). use prepared statement syntax ?. use. setparameter( indexof?, value ) . example

    ...("select userlevelid users id = ?") ...setparameter(1, tmp) 

other notes

  • don't querying in getter if getter part of property binding. instance if have list<user> items bean property, don't business logic or in case querying in getter. getter may called few number of reason, apart expect. instead can initialize in @postconstruct method or in constructor. if need update list, have listener method update it, , directly call that method

  • a common practice separate business layer , web layer (the managed bean). business layer can ejb in inject managed bean


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -