我是Hibernate中的新成員。我成功檢索單列和完整的表,但是當我嘗試在表中的特定列它給我錯誤。 以下是錯誤休眠:無法檢索多個字段值
[Ljava.lang.Object;@2c7d121c, [Ljava.lang.Object;@65aa6596, [Ljava.lang.Object;@67389cb8, [Ljava.lang.Object;@419a20a6
這裏是實體:MovieRatings.java
package com.hibernate.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "movie_ratings")
public class MovieRatings {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "movie_id")
private int user_id;
@Column(name = "user_id")
private int movie_id;
@Column(name = "rating")
private int rating;
public MovieRatings()
{
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUser_id() {
return user_id;
}
public void setUser_id(int user_id) {
this.user_id = user_id;
}
public int getMovie_id() {
return movie_id;
}
public void setMovie_id(int movie_id) {
this.movie_id = movie_id;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
@Override
public String toString() {
return "MovieRatings [id=" + id + ", user_id=" + user_id + ", movie_id=" + movie_id + ", rating=" + rating
+ "]";
}
}
這裏的主要功能是
package com.hibernate.getdata;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.hibernate.entity.MovieRatings;;
public class GetMovieInfo {
public static void main(String[] args) {
// TODO Auto-generated method stub
SessionFactory factory = new Configuration().configure().addAnnotatedClass(MovieRatings.class).buildSessionFactory();
Session session = factory.getCurrentSession();
try {
session.beginTransaction();
String hql="select E.user_id, E.rating from MovieRatings as E";
System.out.println(hql);
@SuppressWarnings({ "deprecation", "unchecked" })
List<MovieRatings> theRatings = session.createQuery(hql).list();
System.out.println(theRatings);
/*for(MovieRatings tempRatings:theRatings)
{
System.out.println(tempRatings.getUser_id());
System.out.println(tempRatings.getRating());
}*/
session.getTransaction().commit();
} catch (Exception e) {
// TODO: handle exception
}
}
}
這是不是一個錯誤,但陣列輸出。 – davidxxx