facebook

Scaffolding, one entity, two incoming ‘one-to-many’ rels

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #314162 Reply

    anton1980
    Member

    Hi,

    These are my entities:

    Vendor (id, name)
    Status (id, name)
    Invoice (id, amount, vendor_id, status_id)

    As you can guess, Vendor and Invoice are one-to-many and Status and Invoice are one-to-many.

    When I generate the code with Scaffolding, everything seems to go fine, there are no errors or anything. The application starts up fine too. However, if I want to add an Invoice I can either do that through a Vendor or a Status, but that does not work. There are constraints on the database, which require that both vendor and status were defined for an Invoice. So, if I add an Invoice through Vendor then Status is null and the database produces an error.

    Can this type of setup be maintained in Spring DSL or I will need to get it to work manually? Please give me some pointers on how to proceed… Thanks!

    Anton

    #314301 Reply

    jkennedy
    Member

    Anton,
    Which UI technology are you using? The reason I ask is because they each have slight differences.

    In general, if your rdbms has foreign key constraints against two relationships, then you would need to setup both relationships prior to persisting as you have stated.

    I think your best bet would be to add to or extend the generated code to create a composition of generated “pieces” that allow your users to define all of the required data at one time, either in one webflow, or in one jsp form, or one GWT UI, etc, depending on the front end option you are using.

    Let me know if you don’t see a clear path to achieve that goal.

    Thanks,
    Jack

    #314309 Reply

    anton1980
    Member

    Hi Jack,

    Thank you for your response.

    We are using web flow.

    I did exactly what you are suggesting. I added a method to the service which allows the user to set two entities simultaneously. I guess thought I was missing something and there was another way of doing it, but this works just fine.

    Anton

    #314445 Reply

    luckyhg90
    Member

    thanks for sharing

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Scaffolding, one entity, two incoming ‘one-to-many’ rels

You must be logged in to post in the forum log in