Get the table name from the model in Hibernate

前端 未结 8 1865
名媛妹妹
名媛妹妹 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:06

    Since getClassMetadata method is deprecated. Try something like this.

       Configuration configuration = new Configuration();
        configuration.configure();
        
        StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure().build();
        
        Metadata = new MetadataSources(standardRegistry).getMetadataBuilder().build();
        SessionFactory sessionFactory = configuration.buildSessionFactory();
        
        String tableName=Metadata.getEntityBinding(entityName).getQualifiedTableName().toString();
    
    0 讨论(0)
  • 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());
    
    0 讨论(0)
提交回复
热议问题