Spring Repository Pattern -- One or zero results are found though tables are populated -
i having these weird problems 'repository' in spring. well, think it's weird, don't know spring @ all.
the problem: though know there's hundreds of rows of data in respective database tables, 1 of repositories returns 1 item (result type list<...>), , other 1 returns nothing @ all, when calling findall().
i suspected there might problems not using standard auto-generated long id, hence second repo, implemented second @entity type auto-generated long id, , populated data in same way.
also tried @query "select f typename f" see if there difference. there not.
so, might problem here?
tried step implementation of interface, it's ridiculous try step through spring invocation handler chain; , maybe code behind generated bytecode or whatever. tips on how debug welcome indeed.
@transactional(propagation = propagation.required) public interface newforumpersistence extends jparepository<syncnewforum, long> { @query("select f syncnewforum f :fromdate <= f.mtime") list<syncnewforum> findsyncforumfromdate(@param("fromdate") date date); @query("select f syncnewforum f '1970-01-01 10:00:01.0' <= f.mtime ") list<syncnewforum> findsyncforumwitholdliteraldate(); @query("select f syncnewforum f ") list<syncnewforum> findallforums(); }
entity:
@entity public class syncnewforum { @id @generatedvalue(strategy = generationtype.auto) @column(name = "id", nullable = false, unique = true) public long id; /** * */ public date mtime = new date(); }
and test code:
@autowired public newforumpersistence itsnewforumpersistence;
test itself:
list<syncnewforum> news = itsnewforumpersistence.findsyncforumwitholdliteraldate(); trace("news.size() = " + news.size()); { list<syncnewforum> = itsnewforumpersistence.findall(); trace("all.size() = " + all.size()); } { list<syncnewforum> = itsnewforumpersistence.findallforums(); trace("all.size() = " + all.size()); } { syncnewforum first = itsnewforumpersistence.findone(1l); trace("first = " + first); }
prints:
news.size() = 0 all.size() = 0 all.size() = 0 first = null
Comments
Post a Comment