| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, I want to start with my business object model, define the OR-Mapping with JPA-annotations and generate my database tables from there. Is this supported from IntelliJ? I couldn't find anything in the documentation. How are other users accomplishing this task, which tools do you use for this from within IntelliJ? Kind regards and thanks Thomas Gülden Munich, Germany |
|
#2
| |||
| |||
| Hallo Thomas, don't know if there's a better way, but here's what I usually do: Be sure to add both JPA and Hibernate facte to the project - the latter only if you want to use hibernate extensions to JPA, like functions in "order by" clause, like order by lower(name). Write your annotated classes. During development I test with hibernate's auto-schema-creation on and have the import.sql create initial data. Later, I use this helper class to generate the schema's DDL: /** * Generates DDL using the JPA entity definitions. SQL statements are printed to console and saved into a file named * schema.sql (in the current working directory). * BEWARE: Do not directly use the generate table definitions. Please review and at least change foreign keys names * into something more meaningful (like FK_PARAMETER_2_CALC_RULE) than the defaults (like FKDC9142E99711833E). * Note that oracle has length limit for names (columns, tables, foreign keys) of 30 characters. */ public class DbSchemaGenerator { private DbSchemaGenerator() { } public static void main(String[] args) { AnnotationConfiguration configuration = new AnnotationConfiguration(); // Select the dialect matching the selected DBMSs //configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle9Dialect"); // Add all root packages that contain entities configuration.addPackage("com.acme.foo // Add each entity configuration.addAnnotatedClass(Authorization.clas s); ... // Dump formated SQL to console and file SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.setOutputFile("schema.sql"); schemaExport.setFormat(true); schemaExport.setDelimiter(";"); schemaExport.execute(true, // write schema to output false, // do not export to DB false, // no drop statements true // only create statements ); } } Thomas Gülden wrote: > Hi, > > I want to start with my business object model, define the OR-Mapping with JPA-annotations and generate my database tables from there. Is this supported from IntelliJ? I couldn't find anything in the documentation. > > How are other users accomplishing this task, which tools do you use for this from within IntelliJ? > > Kind regards and thanks > > Thomas Gülden > Munich, Germany |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.