简体   繁体   English

Hibernate不要在数据库中创建我的表

[英]Hibernate don't create my tables in the database

In my spring project, I have a service class to create my database and tables. 在我的春季项目中,我有一个服务类来创建数据库和表。 After create the database (which is being done successfully), this method is called: 创建数据库后(成功完成),此方法称为:

public void create_tables(String maquina, String usuario, String senha) {
    System.out.println("create_tables");
    create_properties(maquina, usuario, senha);

    Configuration config = new Configuration();
    Properties props = new Properties();
    FileInputStream fos;
    try {
        fos = new FileInputStream( "database.properties" );
        props.load(fos);
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    config.setProperties(props);

    try {
        String url = props.getProperty("jdbc.url");
        Connection conn = DriverManager.getConnection(url,usuario,senha);
        SchemaExport schema = new SchemaExport(config, conn);
        schema.create(true, true);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    insert_default_values();
}

But, despite in the Eclipse console display that the schema was exported successfully, no table is created in my database. 但是,尽管在Eclipse控制台显示中已成功导出模式,但在我的数据库中未创建任何表。

Anyone can see what's wrong here? 有人看到这里有什么问题吗?

UPDATE 更新

database.properties database.properties

#propriedades
#Sat May 10 12:52:57 BRT 2014
jdbc.url=jdbc\:postgresql\://localhost\:5432/horario
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=false
jdbc.user=<<my database user>>
jdbc.Classname=org.postgresql.Driver
hibernate.hbm2ddl.auto=update
jdbc.pass=<<my password>>

HibernateConfig.java -> https://github.com/klebermo/webapp_horario_livre/blob/master/src/com/horariolivre/resources/HibernateConfig.java HibernateConfig.java-> https://github.com/klebermo/webapp_horario_livre/blob/master/src/com/horariolivre/resources/HibernateConfig.java

Entity classes -> https://github.com/klebermo/webapp_horario_livre/tree/master/src/com/horariolivre/entity 实体类-> https://github.com/klebermo/webapp_horario_livre/tree/master/src/com/horariolivre/entity

Dao classes -> https://github.com/klebermo/webapp_horario_livre/tree/master/src/com/horariolivre/dao 道类-> https://github.com/klebermo/webapp_horario_livre/tree/master/src/com/horariolivre/dao

Try adding following code snippet: 尝试添加以下代码片段:

config.addAnnotatedClass(com.horariolivre.entity.Atributo.class);
config.addAnnotatedClass(com.horariolivre.entity.Autorizacao.class);
...

Is this what you are looking for? 这是你想要的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM