以下行返回空值:
List accountList = hibernateTemplate.find("from Accounts a where a.userId=?",userId);
我在控制台中收到以下信息:
2013-04-03 21:09:48 DEBUG Loader:1197 - 结果行:null
2013-04-03 21:09:48 DEBUG Loader:1197 - 结果行:null
这是我的实体类:
@Repository
@Entity
@Table(name = "ACCOUNTS")
public class Accounts {
@Column(name="ACCOUNT_ID")
@Id
@GeneratedValue
private int accountId;
@Column(name="ACCOUNT_NUMBER")
private String accountNumber;
@Column(name="ACCOUNT_TYPE_CODE")
private String accountTypeCode;
@Column(name="USER_ID")
private String userId;
@Column(name="ACCOUNT_NAME")
private String accountName;
@Column(name="DATE_OPENED")
private Date dateOpened;
@Column(name="DATE_CLOSED")
private Date dateClosed;
@Column(name="CURRENT_BALANCE")
private double currentBalance;
@Column(name="OTHER_ACCOUNT_DETAILS")
private String otherAccountDetails;
@Column(name="ADD_TS")
private Date addTimestamp;
@Column(name="ADD_USR")
private String addUser;
@Column(name="UPDT_TS")
private Date updateTimestamp;
@Column(name="UPDT_USR")
private String updateUser;
@ManyToOne
private Customer customer;
任何人都可以帮我这个吗?我真的很感激。
这是Hibernate生成的查询
Hibernate:选择accounts0_.ACCOUNT_ID为ACCOUNT1_23_,accounts0_.ACCOUNT_NAME为ACCOUNT2_23_,accounts0_.ACCOUNT_NUMBER为ACCOUNT3_23_,accounts0_.ACCOUNT_TYPE_CODE为ACCOUNT4_23_,accounts0_.ADD_TS为ADD5_23_,accounts0_.ADD_USR为ADD6_23_,accounts0_.CURRENT_BALANCE为CURRENT7_23_,accounts0_。 customer_CUSTOMER_ID as customer14_23_,accounts0_.DATE_CLOSED as DATE8_23_,accounts0_.DATE_OPENED as DATE9_23_,accounts0_.OTHER_ACCOUNT_DETAILS as OTHER10_23_,accounts0_.UPDT_TS as UPDT11_23_,accounts0_.UPDT_USR as UPDT12_23_,accounts0_.USER_ID as USER13_23_ from ACCOUNTS accounts0_ where accounts0_.USER_ID =?
查询中有什么问题吗?或域配置?
请帮帮我。
答案 0 :(得分:0)
我有点不明白为什么要设置USER_ID String(varchar)类型的列,但是关于你的情况,你可以像这样写:
hibernateTemplate.find("from Accounts a where a.userId='" + userId + "'");
它会很好用,也许可以帮助你:)。