0

I have set up entities and their relationships with Spring Roo. I am trying to run "perform tests" through Roo but see that corresponding tables for these entities are not created in the datbase that I selected as part of my database setup.

Is there a way to tell Spring Roo to generate database tables, columns too alongside entities and its fields?

Nilesh
  • 4,137
  • 6
  • 39
  • 53
  • It is very strange because default roo setup should create tables on application's run. Please check your log if there are some exceptions you missed. – Constantiner Apr 09 '11 at 20:50
  • @Constantiner: That may be true for in memory database like Hypersonic. Is it also true for MySQL? – Nilesh Apr 10 '11 at 03:25
  • For in memory database tables are created on every run and destroyed after run. If you'll use MySQL tables will be persisted between sessions. – Constantiner Apr 10 '11 at 07:43

3 Answers3

4

You may need to create the database yourself, then Hibernate will create the tables for you. I had the same problem and my db user was root so I just assumed that Hibernate would create the database - but it wasn't. As soon as I created the schema, everything worked fine.

The tables seem to be created during sessionFactory creation according to this answer.

Community
  • 1
  • 1
  • Thanks that worked! I had to create the database and when I fired the perform tests it created the tables on its own. – Nilesh Apr 23 '11 at 06:12
2

Have you done the "persistence setup .." step? If so, you should have a persistence.xml in src/main/resources/META-INF. Do you have a property named "hibernate.hbm2ddl.auto" there? What is its value?

abalogh
  • 8,239
  • 2
  • 34
  • 49
0

You can find an example of filling in memory DB with test data here. Hope this helps.

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • Thanks - I am not looking for in memory solution. I am rather looking for how to achieve it using MYSql? – Nilesh Apr 11 '11 at 09:55
  • Just follow the link above. Filling test data routine checks if data already presents in DB. So it can be used for MySQL too. – Constantiner Apr 11 '11 at 09:59
  • I don't think you get the question. I am not asking about filling data. I am asking about creating schema (tables and columns) when Roo creates entities. Is that possible? – Nilesh Apr 11 '11 at 10:07
  • They are created automatically. By default. – Constantiner Apr 11 '11 at 10:32
  • When? At the time entity is created or during first run? 'co I am not seeing them and when I do perform tests - it complains about not having them. – Nilesh Apr 11 '11 at 10:45
  • Complains? In what form? Any exception? Please post stacktrace. – Constantiner Apr 11 '11 at 12:24