Hello, I'm splitting this thread into two, it will be easier for future readers to follow the discussion. This thread will deal with the NullPointerException
2014-03-09 23:06 GMT+01:00 Stargate <[email protected]>: > Hi, > > i use the codegenerator to generate from a postgresDB my model and POJO > objects.. > > I have created a simple account table with id,username,password and so i > have an automatic generated Account POJO.. > At the moment there are 3 entries in my DB with id 1 to 3 > > if i execute the following query : Account ac= > createFactory().selectFrom(ACCOUNT).where(ACCOUNT.ACCOUNT_ID.equal(4)).fetchOne().into(Account.class); > > with id=4(ID 4 is not in my table) then it comes a NullPointerException, > ist this ´normal? why ist "ac" not null ? if i do the same query with a > AccountRecord the AccountRecord is simply null.. and i want not an > exception i want that the object is simply null. > This is how fetchOne() works: http://www.jooq.org/javadoc/3.3.x/org/jooq/ResultQuery.html#fetchOne() Returns: The resulting record or null if the query returns no records. If you want a more general, null-save behaviour, you could use fetch(), which guarantees to return a non-null org.jooq.Result. List<Account> ac= createFactory().selectFrom(ACCOUNT).where(ACCOUNT.ACCOUNT_ID.equal(4)).fetch().into(Account.class); You will still have to write a check for Result emptiness before accessing the first element, though. -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
