Announcement Announcement Module
No announcement yet.
Spring Roo and Database Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Roo and Database

    I am totally new to Roo. I have read some introduction of Roo and tried a small example to generate code using Hibernate. I still have some basic questions related to it.
    I already have an existing database in MYSQL. How can I map the tables with the entities in Roo using Hibernate?
    It looks like Roo engineers the database at runtime but I am unable to get this concept and am confused on what do we do if we have an existing database.
    If Roo creates the ddls and executes them how do we define the table integrities, index etc? I tried to see a lot of examples but am unable to get the actual concept.

    Thanks in Advance.

  • #2
    Reverse engineer.


    persistence setup --database MYSQL --provider HIBERNATE --userName XXX --password XXX
    (Or editing the instead of passing the database user and password)


    database reverse engineer --schema PUBLIC --package ~.domain
    Using the appropriate schema and the desired package.

    If it fails, because Roo needs the driver to connect to the database, Roo will locate an addon for doing so. Just follow the instructions, basically you'll have to do something like this:

    addon install id --searchResult 01
    Being 01 the first addon that Roo has found.

    Note: Roo doesn't create any ddl, Roo generates JPA code and therefore the database can be created, validated and so on.

    Find the next line within the persistence.xml:

    <property name="" value="validate"/>
    If you already have the entities, you can set value to create and the JPA engine (Hibernate, for instance) will create the tables.

    To achieve database definition, the JPA annotations are used (@Entity, @ManyToOne, @JoinColumn...), but I don't know if you can create all the database stuff (indexes, for instance) with JPA. If it's not possible (try the documentation) you will have to modify the database using its own commands (MySQL in your case)


    • #3
      Thanks a lot for the reply. I'll try that out. Thanks again for that helpful information.