Hibernate - Is there a way to join 2 columns against 1?

前端 未结 2 671
清酒与你
清酒与你 2021-01-12 17:41

I\'m developing webapp using Spring & Hibernate.

Table 1: BaseTable

+------------+--------------+------+-----+---------+----------------+
| Fiel         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 17:54

    You need to use native query for this purpose

    String sql = "SELECT A.* FROM Table2 As a INNER JOIN Table1 As b "
               + " ON (a.Serial = b.Serial1 or a.Serial = b.Serial2);";
    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(Table2.class);
    List tableContent  = query.list();
    

提交回复
热议问题