开发者

Hibernate cannot create joined sub-class table while using annotation

开发者 https://www.devze.com 2023-02-25 17:24 出处:网络
I am new to Hibernate and I cannot create joined sub-class table while using Hibernate annotation. Here is my code.

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")
p开发者_Python百科ublic 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!


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消