+-------+---------+----------+----------+------------+--------+----------------------+-----+-------+
| id    | address | bankAccN | clientId | contactTel | isLeaf | name                 | zip | pid   |
+-------+---------+----------+----------+------------+--------+----------------------+-----+-------+
|     1 | NULL    | NULL     | NULL     |          0 |        |                      |   0 |  NULL |
| 10000 | NULL    | NULL     | NULL     |          0 | N      | 所有分销商           |   0 |     1 |
| 10001 | NULL    | NULL     | A0001    |          0 | Y      | 北京医药股份有限公司 |   0 | 10000 |
| 10002 | NULL    | NULL     | B0001    |          0 | Y      | 北京中医医院         |   0 | 10000 |
+-------+---------+----------+----------+------------+--------+----------------------+-----+-------+

解决方案 »

  1.   

    你在hibernateTemplate.get(Client.class, id);这句之前对id进行赋值为10001试试还报这个错不
      

  2.   

    有人说,是没有数据,
    有人说是下标越界,
    我查了原码:
       public char charAt(int index) {
            if ((index < 0) || (index >= value.length)) {
                throw new StringIndexOutOfBoundsException(index);
            }
            return value[index];
        }
    我不明白,它为什么会跑到这里,
    我换了多种hql写法,比如:
         String hql= "select c1.client from Clevel c1 where c1.client.id=?";
        Client client =(Client)session.createQuery(hql)
    .setParameter(0, id)
    .uniqueResult();
    都出现:
    java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:658)
    我的数据库也有数据啊!以下是我的Client类:
    @Entity
    @Component
    public class Client {
    @Id
    @GeneratedValue(generator="assigned")
    @GenericGenerator(name = "assigned", strategy = "assigned")
    private int id;


    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="pid")
    private Client clientN;
    @OneToMany(mappedBy="clientN")
    private Set<Client> clients;
    private String clientId;

    private String name;

    @OneToOne(cascade=CascadeType.ALL,mappedBy="clientRegion")
    private Region region;
    @OneToMany(mappedBy="client")
    private Set<Clevel> clevels=new HashSet<Clevel>();

    private String bankAccN;
    private int contactTel;
    private String address;
    private int zip;
    private char isLeaf; public int getId() {
    return id;
    }
    public void setId(int id) {
    this.id = id;
    } public String getClientId() {
    return clientId;
    }
    public void setClientId(String clientId) {
    this.clientId = clientId;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public Region getRegion() {
    return region;
    }
    public void setRegion(Region region) {
    this.region = region;
    }

    public String getBankAccN() {
    return bankAccN;
    }
    public void setBankAccN(String bankAccN) {
    this.bankAccN = bankAccN;
    }
    public int getContactTel() {
    return contactTel;
    }
    public void setContactTel(int contactTel) {
    this.contactTel = contactTel;
    }
    public String getAddress() {
    return address;
    }
    public void setAddress(String address) {
    this.address = address;
    }
    public int getZip() {
    return zip;
    }
    public void setZip(int zip) {
    this.zip = zip;
    }
    public Set<Client> getClients() {
    return clients;
    }
    public void setClients(Set<Client> clients) {
    this.clients = clients;
    }
    public char getIsLeaf() {
    return isLeaf;
    }
    public void setIsLeaf(char isLeaf) {
    this.isLeaf = isLeaf;
    }
    public Client getClientN() {
    return clientN;
    }
    public void setClientN(Client clientN) {
    this.clientN = clientN;
    }
    public Set<Clevel> getClevels() {
    return clevels;
    }
    public void setClevels(Set<Clevel> clevels) {
    this.clevels = clevels;
    } public Client(int id, String clientId, String name, Region region,
    String bankAccN, int contactTel,
    String address, int zip,Set<Clevel> clevels) {
    super();
    this.id = id;
    this.clientId = clientId;
    this.name = name;
    this.region = region;
    this.bankAccN = bankAccN;
    this.contactTel = contactTel;
    this.address = address;
    this.zip = zip;
    this.clevels = clevels;
    }
    public Client() {
    super();
    }}