Charles
Charles

Reputation: 685

Hibernate cannot create joined sub-class table while using annotation

I am new to Hibernate and I cannot create joined sub-class table while using Hibernate annotation.

Here is my code.

This is the main class.

@Entity
@Table(name="CRM_User")
@Inheritance(strategy=InheritanceType.JOINED)
public class UserImp extends BaseModel implements IUser, Serializable
{
  ... ...

And Staff class extends User class.

@Entity
@Table(name="CRM_Staff") 
@PrimaryKeyJoinColumn(name="Id")
public class StaffImp extends UserImp implements IStaff, Serializable
{
  ... ...   

And when I run the unit test, I get the error.

/* Test get all User */
@Test
public void testGetAllUser()
{
    List<IUser> users = (List<IUser>) this.userDAO.getAll("UserImp");
    assertEquals(2, users.size());
}

This is the error.

......
19:31:04,880  INFO SchemaExport:281 - schema export complete
19:31:04,918  INFO DefaultTraversableResolver:81 - Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
19:31:05,158  WARN JDBCExceptionReporter:233 - SQL Error: 1146, SQLState: 42S02
19:31:05,158 ERROR JDBCExceptionReporter:234 - Table 'test.crm_staff' doesn't exist  
... ...

Thanks so much!

Upvotes: 1

Views: 1398

Answers (1)

Stijn Geukens
Stijn Geukens

Reputation: 15628

Your annotations seem to be correct so: does table 'crm_staff' exist? Did you create a database with this table or (if hibernate should create this when running the test) did you set hibernate.hbm2ddl.auto to create-drop?

Upvotes: 1

Related Questions