我是 hibernate 初学者,我的代码中有 1 个错误,我不知道如何解决它。为什么我不能在 foreach 中使用我的实体。 Error in foreach
这是由idea创建的BookEntity类。
hibernate 版本5.0.1; java SDK版本10.0.1
@Entity
@Table(name = "book", schema = "library")
public class BookEntity {
private boolean edit;
private long id;
private String name;
private long author;
private int publishYear;
private long publisherId;
public boolean isEdit(){return edit; }
public void setEdit(boolean edit){this.edit = edit;}
@Id
@Column(name = "id", nullable = false)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Basic
@Column(name = "author_id", nullable = false, length = 20)
public long getAuthor() {return author; }
public void setAuthor(long author) {this.author = author;}
@Basic
@Column(name = "name", nullable = false, length = 45)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Basic
@Column(name = "publish_year", nullable = false)
public int getPublishYear() {
return publishYear;
}
public void setPublishYear(int publishYear) {
this.publishYear = publishYear;
}
@Basic
@Column(name = "publisher_id", nullable = false)
public long getPublisherId() {
return publisherId;
}
public void setPublisherId(long publisherId) {
this.publisherId = publisherId;
}
}
我将非常感谢您的帮助
最佳答案
可能是因为您没有定义 bookList
以正确的方式。
如果您有以下情况之一:
-
List bookList = new ArrayList();
-
List<Object> bookList = new ArrayList<>();
将其更改为 List<BookEntity> booklist = new ArrayList<>();
它会工作得很好。
关于java - 无法在 foreach 中使用 hibernate 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51143262/