In NetBeans, you can do New >> Entity Classes from Database. I want to create a Java app that will automatically do this instead of using NetBeans.
I seems that org.hibernate.tool.hbm2ddl.SchemaExport might be the thing to use, but I cannot figure out how.
Here's what I have so far:
public static void main(String[] args) { Configuration config = new Configuration(); Properties properties = new Properties(); properties.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect"); properties.put("hibernate.connection.url", "jdbc:sqlserver://localhost;databaseName=mydb"); properties.put("hibernate.connection.username", "username"); properties.put("hibernate.connection.password", "password"); properties.put("hibernate.connection.driver_class", "com.microsoft.sqlserver.jdbc.SQLServerDriver"); properties.put("hibernate.show_sql", "true"); config.setProperties(properties); SchemaExport schemaExport = new SchemaExport(config); schemaExport.create(true, false); }
I need the code to generate the entity classes.
Any help would be much appreciated.
|