许多关系的声明在哪里休眠

时间:2015-12-03 06:17:26

标签: java hibernate

我有一个数据库显示这种关系更像这样 enter image description here 我想从两个表格gmail和bloggerwith条件获取信息博客[blogger]和用户[gmail]值存在于表md_parse_blogger中  我想知道如何制作正确的语法,请帮助我

public List showDatawebA(String blog, String url) {
        String sql = "FROM MdParse g,MdBlogger b,MdParseBlogger pb"
                + " WHERE pb.mdBlogger=:blog and pb.mdParse=:url";
        Query createQuery = currentSession.createQuery(sql);
        createQuery.setParameter("blog", blog);
        createQuery.setParameter("url", url);
        return createQuery.list();
    }

使用mdBlogger,mdGmail是属性类MdParseBlogger,

public class MdParseBlogger  implements java.io.Serializable {
     private MdParseBloggerId id;
     private MdBlogger mdBlogger;
     private MdParse mdParse;
     ...........
    }

ERROR

Exception in thread "main" org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 2
    at org.hibernate.engine.query.spi.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:89)
    at org.hibernate.engine.query.spi.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:109)
    at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:507)
    at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:479)
    at dbUtility.DBTable.showDataweb(DBTable.java:76)
    at dbUtility.DBTable.main(DBTable.java:83)
Picked up _JAVA_OPTIONS: -Xmx512M

1 个答案:

答案 0 :(得分:1)

您混合了命名和序数参数。它应该是

   String sql ="FROM MdGmail g,MdBlogger b,MdParseBlogger pb"
            + " WHERE pb.mdBlogger=? and pb.mdGmail=?";
    Query createQuery = currentSession.createQuery(sql);
    createQuery.setParameter(1, blog);
    createQuery.setParameter(2, url);

   String sql ="FROM MdGmail g,MdBlogger b,MdParseBlogger pb"
            + " WHERE pb.mdBlogger=:blog and pb.mdGmail=:url";
    Query createQuery = currentSession.createQuery(sql);
    createQuery.setParameter("blog", blog);
    createQuery.setParameter("url", url);