HibernateTemplate に問題があり、どこが間違っているのかわかりません。Hibernate3 と Tomcat6 を使用しています。私のDAOには、文字列を使用してデータベースにクエリを実行しようとする関数があり、正常に動作しているようです。このような
public AppUser getUserByUserName(String username){
HibernateTemplate template=new HibernateTemplate(sessionFactory);
try{
List<AppUser> appList = template.find(" from AppUser as au where au.username=?", username);
tempUser = appList.get(0);
return tempUser;
} catch(Exception e){
System.out.println("Problem in AppUserDao--get byUsername: " + e.toString());
return null;
}
}
それでも、整数を使用してクエリを実行しようとすると。お気に入り:
public List<AppUser> getAllMerchants(){
HibernateTemplate template=new HibernateTemplate(sessionFactory);
try{
List<AppUser> appList = template.find(" from appuser as au where au.securityLevel!=?", 112);
if(appList.size() > 0)
return appList;
else
return null;
} catch(Exception e){
System.out.println("Problem in AppUserDao--getAllMerchants: " + e.toString());
return null;
}
}
次のエラーが表示されます。
org.springframework.orm.hibernate3.HibernateQueryException: appuser がマップされていません [from appuser as au where au.securityLevel!=?]; ネストされた例外は org.hibernate.hql.ast.QuerySyntaxException: appuser がマップされていません [from appuser as au where au.securityLevel!=?]
私のエンティティには必要な注釈があるようです。最初の機能で機能するので、2番目の機能で機能しない理由がわかりません。
@実在物
@Table(name="appuser")
パブリック クラス AppUser {
プライベート int id;
プライベート文字列のユーザー名。
プライベート文字列パスワード;
プライベート文字列 firstName;
プライベート文字列の secondName;
プライベート int 状態。
プライベート int securityLevel;
@ID
@GeneratedValue(strategy = GenerationType.AUTO, generator= "idSeq")
@SequenceGenerator(name="idSeq",sequenceName="app_user_seq_id")
public int getId() {
ID を返します。
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
ユーザー名を返します。
}
public void setUsername(String ユーザー名) {
this.username = ユーザー名;
}
@Column(name="password_2")
public String getPassword() {
パスワードを返します。
}
public void setPassword(文字列パスワード) {
this.password = パスワード;
}
public String getFirstName() {
最初の名前を返します。
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSecondName() {
セカンドネームを返します。
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public int getState() {
状態を返します。
}
public void setState(int 状態) {
this.state = 状態;
}
public int getSecurityLevel() {
securityLevel を返します。
}
public void setSecurityLevel(int securityLevel) {
this.securityLevel = securityLevel;
}
}