Announcement Announcement Module
Collapse
No announcement yet.
creating a user inside roo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • creating a user inside roo

    How can I create/modify the user class, and reference it in m:m and 1:m relationships as well.

    For example, I have a m:m where a user can own many books and the same book can be owned by many users.??

  • #2
    Mappings

    Basic code samples to create mappings:

    M-TO-M
    field set --fieldName books --element ~.server.domain.Book

    1-TO-1
    field reference --fieldName sampleField --type ~server.domain.SampleClass

    Comment


    • #3
      Thanks,

      but i get an error when i try to create ~.domain.User ....a user class so Im not sure what types of user is pre-created by roo? HOw do i reference this user?

      Comment


      • #4
        It helps if you provide the error message...

        Presumably when you tried to create the User entity, you got this error:

        Code:
        Reserved SQL keyword 'User' is not permitted as simple type name
        ... which means what it says. Pick another name for this domain type, such as Person, Customer, Owner, or Borrower.

        Comment


        • #5
          Thanks. I am sure that when I run 'security setup' there is already a 'User' created by Roo/Hibernate, how can i hook into this user?

          In other words, a user wil be created automagically and I want to create a 'book' entity that is owned by a user. So how can I create an FK on the books table and refer to the automatically created User?

          Comment


          • #6
            User as table.

            Create an entity class by name Users and let it utilize actual table user:

            entity --class ~.domain.Users --table user

            Comment


            • #7
              Originally posted by kamilski81 View Post
              Thanks. I am sure that when I run 'security setup' there is already a 'User' created by Roo/Hibernate, how can i hook into this user?

              In other words, a user wil be created automagically and I want to create a 'book' entity that is owned by a user. So how can I create an FK on the books table and refer to the automatically created User?
              When you run 'security setup', Roo adds the Spring Security JARs to your project's classpath, which includes the org.springframework.security.core.userdetails.User class. This class isn't a JPA entity, but you can use it as the superclass for one, for example:

              Code:
              @Entity
              // ... various other Roo/JPA annotations ...
              public class BookOwner extends User {
                  // ... your domain-specific fields and hand-written methods go here
              }
              That way, your BookOwner class "is a" User. If you add a BookOwner field to your Book class, then you will have an FK from the book table to the book_owner table. Is that what you're looking for?

              Comment


              • #8
                So it's an "is-a" relationship and you can't actually add/edit the actual user. For example, if I only want to add a middle-name, I can't do that to the existing class.

                Would i just have to re-write my own user class, and reference it somehow?

                However, this is definitely a step in the right direction.

                Comment


                • #9
                  Originally posted by kamilski81 View Post
                  For example, if I only want to add a middle-name, I can't do that to the existing class.

                  Would i just have to re-write my own user class, and reference it somehow?
                  No, just add a "middleName" field to your subclass of User (e.g. BookOwner).

                  Comment

                  Working...
                  X