日期:2014-05-20  浏览次数:20852 次

急急急!!hibernate发出sql语句出错 列名出错'trade0_.accountID_accountID'
数据库中两个表关联Account Trade
Trade表中的AccountID是外键 是Account表的主键
实体类设置的是多对一  
hibernate的sql语句发出出错了 'trade0_.accountID_accountID' 应为'trade0_.accountID 现在多了个ccountID

给为GGMM求解啊 帮帮小弟吧 错误及主要代码已贴在下面  

  
错误代码22:58:06,272 DEBUG SQL:111 - select trade0_.ID as ID1_, trade0_.accountID_accountID as accountID6_1_, trade0_.tradeDigest as tradeDig2_1_, trade0_.tradeMoney as tradeMoney1_, trade0_.tradeTime as tradeTime1_, trade0_.tradeType as tradeType1_ from Trade trade0_ where trade0_.accountID_accountID='123456'
Hibernate: select trade0_.ID as ID1_, trade0_.accountID_accountID as accountID6_1_, trade0_.tradeDigest as tradeDig2_1_, trade0_.tradeMoney as tradeMoney1_, trade0_.tradeTime as tradeTime1_, trade0_.tradeType as tradeType1_ from Trade trade0_ where trade0_.accountID_accountID='123456'
22:58:06,301 WARN JDBCExceptionReporter:233 - SQL Error: 1054, SQLState: 42S22
22:58:06,301 ERROR JDBCExceptionReporter:234 - Unknown column 'trade0_.accountID_accountID' in 'field list'


实体类Trade
Java code
package com.hyb.bank.model;

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

@Entity
public class Trade {
    private int ID;
    private Account accountID;
    private String tradeType;
    private double tradeMoney;
    private Date tradeTime;
    private String tradeDigest;
    
    @Id
    @GeneratedValue
    public int getID() {
        return ID;
    }
    public void setID(int iD) {
        ID = iD;
    }
    
    @ManyToOne
    public Account getAccountID() {
        return accountID;
    }
    public void setAccountID(Account accountID) {
        this.accountID = accountID;
    }
    public String getTradeType() {
        return tradeType;
    }
    public void setTradeType(String tradeType) {
        this.tradeType = tradeType;
    }
    public double getTradeMoney() {
        return tradeMoney;
    }
    public void setTradeMoney(double tradeMoney) {
        this.tradeMoney = tradeMoney;
    }
    public Date getTradeTime() {
        return tradeTime;
    }
    public void setTradeTime(Date tradeTime) {
        this.tradeTime = tradeTime;
    }
    public String getTradeDigest() {
        return tradeDigest;
    }
    public void setTradeDigest(String tradeDigest) {
        this.tradeDigest = tradeDigest;
    }
    
    
}



Dao
Java code
package com.hyb.bank.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.hyb.bank.model.Account;
import com.hyb.bank.model.Trade;


@Component
public class TradeDao {
    private HibernateTemplate hibernateTemplate;
    

    public List<Trade> loadReamining(String accountID){
        List<Trade> trades = hibernateTemplate.find
        ("from Trade t where t.accountID='"+accountID+"'");
        return trades;
    }
    
    public HibernateTemplate getHibernateTemplate() {
        return hibernateTemplate;
    }
    @Resource
    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }
    
}



------解决方案--------------------
@ManyToOne的配置不全吧,加上@JoinColumn看看
------解决方案--------------------
映射文件配置错误?
注解的方式,还没用过,帮不了你
------解决方案--------------------
哦,又要接楼主送的分了