Get the table name from the model in Hibernate

前端 未结 8 1871
名媛妹妹
名媛妹妹 2020-12-05 04:33

How do I get the table name for a model in Hibernate?

Apparently there used to be a getTableName() method in ClassMetadata, but it\'s been removed.

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 05:07

    Configuration cfg = new Configuration().configure();    
    cfg.addResource("com/struts/Entities/User.hbm.xml");
    cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    Mappings m=cfg.createMappings();
    System.out.println(">> class: "+m.getClass(className));
    System.out.println("User table name:: "+m.getClass("User").getTable().getName());
    

提交回复
热议问题