Tuesday, 15 September 2015

spring - Column querying from connection not working for Postgresql but not for Hsql in Java -



spring - Column querying from connection not working for Postgresql but not for Hsql in Java -

i encountering weird behavior integration tests jpa configuration failing postgresql passing hsql. there no code changes test , assertion method.

i have verified table , columns beingness added appropriately database. verification table existence passes ok, column check fails unexpectedly.

what root cause of this? there workaround or prepare issue?

test:

@runwith(springjunit4classrunner.class) @contextconfiguration(classes=persistenceconfig.class) @transactional @transactionconfiguration(defaultrollback=true) public class usermappingintegrationtest { @autowired entitymanager manager; @test public void thatusermappingworks() { asserttableexists(manager, "user_table"); asserttablehascolumn(manager, "user_table", "name"); } }

assertion method:

public static void asserttablehascolumn(entitymanager manager, final string tablename, final string columnname) { sessionimpl session = (sessionimpl) manager.unwrap(session.class); final resultcollector rc = new resultcollector(); session.dowork(connection -> { resultset columns = connection.getmetadata().getcolumns(null, null, tablename.touppercase(), null); while (columns.next()) { if (columns.getstring(4).touppercase() .equals(columnname.touppercase())) { rc.found = true; } } }); if (!rc.found) { fail("column [" + columnname + "] not found on table : " + tablename); } }

java spring postgresql hsqldb

No comments:

Post a Comment