小编Rom*_*ain的帖子

休眠和继承(TABLE_PER_CLASS)

我使用Hibernate来持久化继承的对象,但是当我尝试在数据库中持久保存对象时,我得到了这条消息:

org.springframework.dao.InvalidDataAccessResourceUsageException: Could not execute
JDBC batch update; SQL [update Widget set CONTAINER_ID=? where WIDGET_ID=?]; nested 
exception is org.hibernate.exception.SQLGrammarException: 
Could not execute JDBC batch update (...) Caused by: java.sql.BatchUpdateException: Table 
'schema.widget' doesn't exist
Run Code Online (Sandbox Code Playgroud)

这是我用来生成表的类:

@Entity
@Table(name="CONTAINER")
public class Container {
     (...)
     private Set<Widget> widgets;

     @OneToMany(targetEntity = Widget.class)
     @JoinColumn(name="CONTAINER_ID", nullable=true)
     public Set<Widget> getWidgets() {
         return widgets;
     }

     public void setWidgets(Set<Widget> widgets) {
         this.widgets = widgets;
     }
}


@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class Widget {
     private long id;
     private int position;

     @Id …
Run Code Online (Sandbox Code Playgroud)

java orm inheritance annotations hibernate

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

annotations ×1

hibernate ×1

inheritance ×1

java ×1

orm ×1