java - What exactly does the persistence API do and what are the advantages of using it? -
is persistence api similar jdbc? in other words, purpose connecting database? also, use sql? , advantage using persistence have on using jdbc? why not use jdbc? i've looked @ number of websites persistence yet still little confused , why using provide programmer advantage.
short answers:
the api referenced typically called "jpa" - that'll useful term search when have questions.
yes, jpa replacement for/complement jdbc. typically you'll using jpa calls, can jdbc connection jpa implementations , use if need to.
yes, uses sql under covers - it's client-layer abstraction around raw sql calls.
the advantage allows use object-style interface when interacting database, , skip long, error-prone code related mapping db result columns fields in objects.
myobject obj = em.find(somekey, ...); obj.getfoo(); obj.getbar();
is lot more maintainable
string query = "select foo, bar, baz, wibble, whomp myobject_table pk_field = somekey"; statement stmt = con.createstatement(); resultset rs = stmt.executequery(query); rs.next(); rs.get("foo"); rs.get("bar");
Comments
Post a Comment