My mapping seems to be causing the following error:
Code:
SEVERE: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: Table SUBCATEGORY not found
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.getTableId(JoinedSubclassEntityPersister.java:458)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:237)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
The table is there, so there shouldn't be an error...
The error appeared when I added the class Chapter which extends Category. If I remove it, everything works fine.
If I remove the references:
Code:
@ManyToOne and
@JoinTable(name = "SUBCATEGORY",
joinColumns = {@JoinColumn(name = "CHILDID")},
inverseJoinColumns = {@JoinColumn(name = "PARENTID")})
private Category parent;
@ManyToMany
@JoinTable(name = "SUBCATEGORY",
joinColumns = { @JoinColumn(name = "PARENTID")},
inverseJoinColumns = { @JoinColumn(name = "CHILDID")})
it works fine too... Could somebody please help?
sql
Code:
CREATE TABLE IF NOT EXISTS Category(
CategoryId bigint(4) NOT NULL auto_increment,
Title varchar(30) NOT NULL,
CategoryLevel bigint(1) NOT NULL DEFAULT '1',
CategoryType varchar(20) NOT NULL DEFAULT 'Category',
PRIMARY KEY (CategoryId)
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS Chapter(
ChapterId bigint(4) NOT NULL auto_increment,
ChapterOrder int(4) NOT NULL DEFAULT '0',
BookId bigint(4) NOT NULL,
PRIMARY KEY (ChapterId),
FOREIGN KEY (ChapterId) REFERENCES Category(CategoryId) ON UPDATE CASCADE,
FOREIGN KEY (BookId) REFERENCES Book(BookId) ON UPDATE CASCADE
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS SubCategory(
SubCategoryId bigint(4) NOT NULL auto_increment,
ParentId bigint(4) NOT NULL,
ChildId bigint(4) NOT NULL,
PRIMARY KEY (SubCategoryId),
FOREIGN KEY (ParentId) REFERENCES Category(CategoryId) ON UPDATE CASCADE,
FOREIGN KEY (ChildId) REFERENCES Category(CategoryId) ON UPDATE CASCADE
) ENGINE=INNODB;
Enitity Chapter
Code:
@Entity
@Table(name = "CHAPTER")
@PrimaryKeyJoinColumn(name="CHAPTERID", referencedColumnName="CATEGORYID")
public class Chapter extends Category {
@Column(name = "CHAPTERORDER")
private Long chapterOrder;
@ManyToOne
@JoinColumn(name = "BOOKID")
private Book book;
public Chapter() {super();}
Entity CAtegory
Code:
@Entity
@Table(name = "CATEGORY")
@Inheritance(strategy=InheritanceType.JOINED)
public class Category implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "CATEGORYID")
private Long categoryId;
@Column(name = "TITLE")
private String title;
@Column(name = "CATEGORYLEVEL")
private Long categoryLevel;
@Column(name = "CATEGORYTYPE")
private String categoryType;
@ManyToOne
@JoinTable(name = "SUBCATEGORY",
joinColumns = {@JoinColumn(name = "CHILDID")},
inverseJoinColumns = {@JoinColumn(name = "PARENTID")})
private Category parent;
@ManyToMany
@JoinTable(name = "SUBCATEGORY",
joinColumns = { @JoinColumn(name = "PARENTID")},
inverseJoinColumns = { @JoinColumn(name = "CHILDID")})
private Set<Category> subCategoryList;
Entity SubCAtegory
Code:
@Entity
@Table(name = "SUBCATEGORY")
public class SubCategory implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "SUBCATEGORYID")
private Long subCategoryId;
@Column(name = "PARENTID")
private Long parentId;
@Column(name = "CHILDID")
private Long childId;