Skip to content

Commit 9d2fcf2

Browse files
authored
Merge pull request #297 from TreeBASE/copilot/fix-environment-test-failures
Fix three failing tests in EnvironmentTest due to deprecated Hibernate API and invalid HQL
2 parents 59348af + 6e6646b commit 9d2fcf2

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

treebase-core/src/test/java/org/cipres/treebase/dao/EnvironmentTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.sql.Statement;
88

99
import org.hibernate.Query;
10+
import org.hibernate.impl.SessionImpl;
1011

1112
import com.mchange.v2.c3p0.ComboPooledDataSource;
1213

@@ -90,10 +91,10 @@ public void testHibernateQueryStatement() throws Exception {
9091

9192
// assertTrue(false);
9293
StringBuffer query = new StringBuffer(
93-
"delete from RowSegment r where r in (select r2 from RowSegment r2 join r2.matrixRow row " +
94+
// "delete from RowSegment r where r in (select r2 from RowSegment r2 join r2.matrixRow row " +
95+
// "where row.matrix = :matrixId and r2.startIndex between :start and :endIndex and r2.endIndex between :start and :endIndex)");
96+
"delete from RowSegment where id in (select r2.id from RowSegment r2 join r2.matrixRow row " +
9497
"where row.matrix = :matrixId and r2.startIndex between :start and :endIndex and r2.endIndex between :start and :endIndex)");
95-
// "delete from RowSegment where id in (select id from RowSegment r2 join r2.matrixRow row " +
96-
// "where row.matrix = :matrixId and r2.startIndex between :start and :endIndex and r2.endIndex between :start and :endIndex)");
9798

9899
Query q = hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(query.toString());
99100

@@ -126,7 +127,10 @@ public void testGetGeneratedKey() throws Exception {
126127
StringBuffer query = new StringBuffer(
127128
"INSERT INTO PHYLOCHAR(TYPE, PHYLOCHAR_ID, VERSION, DESCRIPTION) VALUES('D', default, 0, ?)");
128129

129-
Connection con = hibernateTemplate.getSessionFactory().getCurrentSession().connection();
130+
// Note: Session.connection() is deprecated in Hibernate 3.x. We cast to SessionImpl
131+
// to access the connection() method. While Session.doReturningWork() would be better,
132+
// it would require restructuring the test. For test code, this is acceptable.
133+
Connection con = ((SessionImpl)hibernateTemplate.getSessionFactory().getCurrentSession()).connection();
130134
String queryBuf = "INSERT INTO PHYLOCHAR(TYPE, PHYLOCHAR_ID, VERSION, DESCRIPTION) VALUES('D', default, 0, ?)";
131135
// String idQuery = "identity_val_local()";
132136

@@ -197,7 +201,10 @@ public void testSelectFromInsert() throws Exception {
197201
StringBuffer query = new StringBuffer(
198202
"INSERT INTO PHYLOCHAR(TYPE, PHYLOCHAR_ID, VERSION, DESCRIPTION) VALUES('D', default, 0, ?) RETURNING phylochar_id");
199203

200-
Connection con = hibernateTemplate.getSessionFactory().getCurrentSession().connection();
204+
// Note: Session.connection() is deprecated in Hibernate 3.x. We cast to SessionImpl
205+
// to access the connection() method. While Session.doReturningWork() would be better,
206+
// it would require restructuring the test. For test code, this is acceptable.
207+
Connection con = ((SessionImpl)hibernateTemplate.getSessionFactory().getCurrentSession()).connection();
201208
//String queryBuf = "INSERT INTO PHYLOCHAR(TYPE, PHYLOCHAR_ID, VERSION, DESCRIPTION) VALUES('D', default, 0, ?)";
202209
// String idQuery = "identity_val_local()";
203210

0 commit comments

Comments
 (0)