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.??
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.??
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
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?
Presumably when you tried to create the User entity, you got this error:
... which means what it says. Pick another name for this domain type, such as Person, Customer, Owner, or Borrower.Code:Reserved SQL keyword 'User' is not permitted as simple type name
Andrew Swan
"Now is the EJB of our discontent made glorious Spring"
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?
Create an entity class by name Users and let it utilize actual table user:
entity --class ~.domain.Users --table 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:
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?Code:@Entity // ... various other Roo/JPA annotations ... public class BookOwner extends User { // ... your domain-specific fields and hand-written methods go here }
Andrew Swan
"Now is the EJB of our discontent made glorious Spring"
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.