Announcement Announcement Module
Collapse
No announcement yet.
My first Roo app Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • My first Roo app

    Hi guys,
    When I saw the Roo presentation "Extreme Productivity in 10 Minutes" I thought "Yes! That's what I need", so I went ahead, made grabbed Roo 1.0.0.RELEASE and made my first test.

    My app was nice and easy:

    Code:
    project --topLevelPackage com.saers.butcher   
    enum type --class com.saers.butcher.enums.MeatType    
    persistence setup --provider HIBERNATE --database MYSQL --userName butcher --password jim
    
    entity --class ~.entities.Saussage --identifierType java.lang.Long --testAutomatically   
    field string --fieldName name --notNull             
    field string --fieldName description --notNull
    field enum --fieldName meatType --type com.saers.butcher.enums.MeatType       
    
    finder add --class com.saers.butcher.entities.Saussage --finderName findTemperamentsByNameLike
    
    controller all --package com.saers.butcher.web   
    security setup
    logging setup --level INFO
    
    perform test
    However, perform test didn't perform:

    Code:
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running com.saers.butcher.entities.SaussageIntegrationTest
    Tests run: 9, Failures: 0, Errors: 8, Skipped: 0, Time elapsed: 2.221 sec <<< FAILURE!
    
    Results :
    
    Tests in error: 
      testCountSaussages(com.saers.butcher.entities.SaussageIntegrationTest)
      testFindSaussage(com.saers.butcher.entities.SaussageIntegrationTest)
      testFindAllSaussages(com.saers.butcher.entities.SaussageIntegrationTest)
      testFindSaussageEntries(com.saers.butcher.entities.SaussageIntegrationTest)
      testFlush(com.saers.butcher.entities.SaussageIntegrationTest)
      testMerge(com.saers.butcher.entities.SaussageIntegrationTest)
      testPersist(com.saers.butcher.entities.SaussageIntegrationTest)
      testRemove(com.saers.butcher.entities.SaussageIntegrationTest)
    
    Tests run: 9, Failures: 0, Errors: 8, Skipped: 0
    I suspect this is because no database schema is generated. Is there a schema generator I can use or add? Because when I dropped MySQL and went with

    Code:
    persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
    it all works. But, I must admit, I'm a bit picky: I want my data to persist. ;-)

    Next I went to STS 2.3.0, did a "New Project", "Spring Template", but there's no Roo option there like in the presentation. Is there something I need to do to add it? I've already added ROO 1.0.0-RELEASE instead of RC4.

    Apart from that, it looks really nice so far, and I'm looking forward to posting lots of questions as I learn more :-)

    Cheers

    Nik

  • #2
    Quick update

    When I do 'mvn tomcat:run' I get a bit, though:

    Code:
    2010-01-10 18:06:07,769 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
    2010-01-10 18:06:07,770 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
    2010-01-10 18:06:07,779 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table saussage (id bigint not null auto_increment, version integer, description varchar(255), meat_type integer, name varchar(255), primary key (id))
    2010-01-10 18:06:07,779 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - No database selected
    2010-01-10 18:06:07,779 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
    and when I go to roo and do:

    database properties set --key 'database.url' --value 'jdbc:mysql://localhost:3306/butcher'
    database properties list

    database.url is still jdbc:mysql://localhost:3306
    but now I also had: 'database.url' = 'jdbc:mysql:

    Editing the file was fine, though. ;-) And of course I did a 'mysqladmin create butcher' as well, and now it all works fine together. Was there a parameter I should know about how to set initially?

    Cheers

    Nik

    Comment


    • #3
      I suggest changing the log level to debug, that way you probably get more information on what is wrong. It might be a missing driver or the fact that the schema isn't updated but only created once (that way it works with an in-memory database but not with mysql because as you stated it is persisted ).

      Comment


      • #4
        Thanks, Marten. Any suggestions on what this driver may be called and how I should add it?

        One more question: When I do a thing such as:

        field set --fieldName ingredients --element ~.entities.Ingredient

        How do I map the reverse relation? I was looking for something like

        field set --fieldName ingredients --element ~.entities.Ingredient --reverseFieldName saussages --relation manyToMany

        or something like that. Am I very wrong? :-) I'm use to mapping these by hand in Spring, but I'm looking forward to learning how to do this the Roo way :-)

        Cheers

        Nik

        Comment


        • #5
          Also, one more question: the Roo project I've created drops all MySQL tables and then recreates them when starting Tomcat through "mvn tomcat:run". This is both when I have done no changes to the entities, or when I've added a field to a single table. I thought the "version" field that's added to all my tables was going to help me through a less "violent" migration. Is there any way I can get it to issue "alter table" commands instead when it detects that the database is running an older schema?

          Comment


          • #6
            persistence.xml?

            Nik,
            1. for our mysql connection I think we have to correct it manually
              https://jira.springsource.org/browse/ROO-501
            2. in src/main/resources/META-INF/persistence.xml you can disable creating your database every time you launch tomcat:

              Code:
              <!--            <property name="hibernate.hbm2ddl.auto" value="create"/>-->


            may be it'll help you.

            Comment


            • #7
              Yes, the issue with the database.url is indeed a bug in the Roo shell. It has also been reported in ROO-517. We are going to fix this soon, in the meantime you will need to enter the correct URL in database.properties by hand.

              If you want to retain your test data you should set the following:

              Code:
              <property name="hibernate.hbm2ddl.auto" value="update"/>
              Mind you that your domain / table model should be pretty stable when using update as structural table changes may cause havoc between your DB and the ORM.

              Comment


              • #8
                Thanks a bunch for all your answers :-)

                Comment


                • #9
                  We are here to help

                  Comment


                  • #10
                    Hi all,

                    Now i'm facing the same issue. I'm beginner in spring roo and created a small phonebook application.
                    Code:
                    project phonebook
                    jpa setup --provider HIBERNATE --database MYSQL 
                    entity jpa --class ~.model.Contact
                    field string --fieldName name
                    field string --fieldName mobile
                    web mvc setup
                    web mvc all --package ~.web
                    quit
                    when i run the application using mvn tomcat:run command gives a error.

                    2012-04-18 15:56:28,383 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table contact (id bigint not null auto_increment, mobile varchar(255), name varchar(255), version integer, primary key (id)) ENGINE=InnoDB 2012-04-18 15:56:28,383 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - No database selected

                    But this works fine when i use HYPERSONIC_IN_MEMORY instead of MYSQL. Can you please tell me the reason for this error.

                    Comment

                    Working...
                    X