Hibernate无法区分具有相同名称的列

时间:2014-04-25 08:35:29

标签: java mysql sql hibernate

我有一张叫做电影院的桌子,上面有一个列ipaddress。

我有一个名为tms的表,其中包含列ipaddress。

当我执行下面指定的查询时,t.ipaddress返回c.ipaddress的值。我该怎么做才能解决这个问题?

        sqlStatement1 = 
                  "select c.IpAddress,        "
                + "       c.User,             "
                + "       c.Password,         "
                + "       c.connectionType,   "
                + "       c.NominalBandwidth, "
                + "       t.ipaddress ,       "
                + "       t.user,             "
                + "       t.password,         "
                + "       t.direction,        "
                + "       t.ftp_script,       "
                + "       t.bandwidth,        "
                + "       t.tmsId,             " 
                + "       d.assetFilePath,     " 
                + "       bt.status     "
                + "from   "
                + ConfigurationParametersHelper.getInstance()
                        .getConfValidated("DBASE_SCHEMA")
                + ".booking b,     "
                + "       "
                + ConfigurationParametersHelper.getInstance()
                        .getConfValidated("DBASE_SCHEMA")
                + ".bookingtms bt, "
                + "       "
                + ConfigurationParametersHelper.getInstance()
                        .getConfValidated("DBASE_SCHEMA")
                + ".dcp d,         "
                + "       "
                + ConfigurationParametersHelper.getInstance()
                        .getConfValidated("DBASE_SCHEMA")
                + ".cinema c,      "
                + "       "
                + ConfigurationParametersHelper.getInstance()
                        .getConfValidated("DBASE_SCHEMA")
                + ".tms t          "
                + "where  b.IdKey          = "
                + booking.getIdKey()
                + " "
                + "and    bt.booking_IdKey = b.IdKey "
                + "and    b.dcp_id         = d.id "
                + "and    c.Id             = b.cinema_Id "
                + "and    t.cinema_id      = c.Id "
                + "and    t.tmsid          = bt.tms_tmsid "
                + "order  by bt.id asc";

UPDATE1:如果我在查询中指定c.ipaddress之前的t.ipaddress,则c.ipaddress会被t.ipaddress覆盖,反之亦然。

1 个答案:

答案 0 :(得分:1)

以下是重写查询

的一个小相关部分
          "select c.IpAddress cIpAddress,        "
        + "       c.User,             "
        + "       c.Password,         "
        + "       c.connectionType,   "
        + "       c.NominalBandwidth, "
        + "       t.ipaddress tIpAddress,       "
        + "       t.user,             "
        + "       t.password,         "
        + "       t.direction,        "
        + "       t.ftp_script,       "
        + "       t.bandwidth,        "
        + "       t.tmsId,             " 
        + "       d.assetFilePath,     " 
        + "       bt.status     "
        + "from   "

请注意别名cIpAddresstIpAddress