Results 1 to 6 of 6

Thread: Roo approach parent child relationships

  1. #1
    Join Date
    Nov 2010
    Location
    Santo Domingo, Albay Philippines
    Posts
    158

    Default Roo approach parent child relationships

    Ok I have an application where there are many relationships of many kinds.

    I have successfully use Roo to create the application and model the database with field reference and field set declarations.

    I have created finders for single field and multiple fields.

    I don't see how to create a finder that gets entities from two tables in a parent child relationship with field values from both tables.

    Example.

    Entity Events with children Entities Actions. One or more Actions for every Event.

    Events has a field set --fieldname relatedActions
    Actions has a field reference --fieldname relatedEvent

    I want a finder that gives me all the Events and Actions where event.type = "gui" and action.type = "java".

    I want to use Roo so I can recreate the application multiple times from one script with as little hand coding as possible.

    Can I do this with Roo without dropping down to java?

  2. #2
    Join Date
    Dec 2005
    Posts
    930

    Default

    There are more finders if you specify the --depth on the finder list command. This may help you
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  3. #3
    Join Date
    Nov 2010
    Location
    Santo Domingo, Albay Philippines
    Posts
    158

    Default

    Quote Originally Posted by Alan Stewart View Post
    There are more finders if you specify the --depth on the finder list command. This may help you
    Ya, tried that but didn't see any that matched up. The first time I tried --depth 3 and got a flood. Then tried --depth 2 and that cut down on it but didn't find anything that fit.

    The closest was on the Event Entity, where it said findEventbyrelatedAction. As I showed in my example I want to find based on an attribute of the parent and attribute of the child.

    What about creating an Entity for a View? The View would join the Event(parent) and Actions(children) and perhaps a generated finder then could have both action.type and event.type?

  4. #4
    Join Date
    Nov 2010
    Location
    Santo Domingo, Albay Philippines
    Posts
    158

    Default

    I see that Roo DBRE can work with --enableViews true to generate entities from sql views in the schema, but I don't see how to generate a view entity with the Roo Shell.

  5. #5
    Join Date
    Nov 2010
    Location
    Santo Domingo, Albay Philippines
    Posts
    158

    Default finder list after DBRE returns nothing on a View Entity

    I used Roo to create the rules and actions entities, and setup a MANY TO MANY relationship. That worked great. Not seeing any way to create the View Entity in Roo, I used Toad to create the view...

    Code:
    CREATE VIEW RuleActionsView AS
      SELECT r.id as rid, r.rule_description, r.rule_name, r.version as rversion, 
      r.related_application, r.related_event, r.rule_type,
      a.id as aid, a.action_attachment_file_name, a.action_attachment_file_path, 
      a.action_description, a.action_name, a.action_script, a.attachment_type, 
      a.builder_widgetswcpath, a.version as aversion FROM rules r, actions a, rules_related_actions rr 
      WHERE rr.related_actions = a.id and rr.rules = r.id;
    Then I used...

    Code:
    roo> database reverse engineer --schema no-schema-required --package ~.model --testAutomatically false --enableViews true --includeNonPortableAttributes false
    And that did great too....at least it crawled the schema and created all the entities including the Ruleactionsview and its classes and aspects...

    Code:
    Created SRC_MAIN_JAVA\com\corenttech\roo\dbretest\model\RuleactionsviewPK.java
    Created SRC_MAIN_JAVA\com\corenttech\roo\dbretest\model\Ruleactionsview.java
    Created SRC_MAIN_JAVA\com\corenttech\roo\dbretest\model\RuleactionsviewPK_Roo_Json.aj
    Created SRC_MAIN_JAVA\com\corenttech\roo\dbretest\model\RuleactionsviewPK_Roo_Serializable.aj
    Created SRC_MAIN_JAVA\com\corenttech\roo\dbretest\model\RuleactionsviewPK_Roo_Configurable.aj
    Created SRC_MAIN_JAVA\com\corenttech\roo\dbretest\model\RuleactionsviewPK_Roo_Identifier.aj...


    Feeling oh so confident, I did a controller all and tried to run it...

    Code:
    2011-05-31 07:44:36,366 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [C:\Users\user\Documents\workspace-sts-2.6.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\DBRETest3\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\Users\user\Documents\workspace-sts-2.6.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\DBRETest3\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    Since this test was more about how to create a finder against that view, I didn't try to debug the above and include it FYI.

    Trying to create a finder for the Ruleactionsview entity that DBRE generated, I did...

    Code:
    ~.model.Ruleactionsview roo> finder list --class com.corenttech.roo.dbretest.model.Ruleactionsview --depth 2 
    ~.model.Ruleactionsview roo> finder list --class com.corenttech.roo.dbretest.model.Ruleactionsview
    and both returned zero, nada, zip, nothing. But...

    Code:
    ~.model.Ruleactionsview roo> finder list --class com.corenttech.roo.dbretest.model.Rules --depth 2
    ...worked fine, so it isn't about a DBRE generated entity, just the view entity.

    So, Unless someone has a suggestion to achieve a Roo based finder, I will have to code one up manually. BTW the reason I want a Roo based finder, is that I have MANY such views and the whole reason to use Roo is to get best practices and standards automagically and hand coding is so passe.
    Last edited by MikeOliverAZ; May 30th, 2011 at 07:01 PM. Reason: corrected typos

  6. #6
    Join Date
    Nov 2010
    Location
    Santo Domingo, Albay Philippines
    Posts
    158

    Default

    [QUOTE=MikeOliverAZ;364773]
    [CODE]
    Feeling oh so confident, I did a controller all and tried to run it...

    Code:
    2011-05-31 07:44:36,366 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [C:\Users\user\Documents\workspace-sts-2.6.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\DBRETest3\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\Users\user\Documents\workspace-sts-2.6.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\DBRETest3\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    This was caused by a tinyblob column in one of the tables and DBRE identified it as a blob, which caused the build of the EntityManagerFactory to fail. I removed the offending column and ran it again and controller all gave me a working application hooray. Now if only there was a way to generate a finder from the view entity.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •