Results 1 to 9 of 9

Thread: creating a user inside roo

  1. #1

    Default 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. #2
    Join Date
    Aug 2006
    Posts
    22

    Default 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

  3. #3

    Default

    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?

  4. #4
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Post 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.
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  5. #5

    Default

    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?

  6. #6
    Join Date
    Aug 2006
    Posts
    22

    Default User as table.

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

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

  7. #7
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Lightbulb

    Quote 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?
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  8. #8

    Default

    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.

  9. #9
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Default

    Quote 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).
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

Posting Permissions

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