Re: Help with record definition
"john_price_137" <[email protected]>
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
Hi, Thanks for the reply. Thats what I tried first, but I get a "Duplicate Column Name" error for ROLE_ID and USER_NAME. The problem is their are only two fields in the table, both of which make up the primary key, and each field is also a foreign key to another table. John --- In [email protected], Franck Routier <franck.routier@...> wrote: > > Hi, > > sure, it is the very purpose of SFieldReference. > > you should just add the following fields to you UserRole class : > > public static final SFieldReference ROLE = > new SFieldReference(meta, Role.meta) > > public static final SFieldReference USER = > new SFieldReference(meta, User.meta) > > (provided that you defined a Role and User class representing these tables). > > This very straightforward constructor works if the name of the fields in > both tables are the same, which seems to be your case ! > > You then can use SRecordInstance.getReference(UserRole.USER) to access > the referenced user.... > > Does it help ? > > Franck > > > john_price_137 a écrit : > > > > Help, I have a table with the following definition: > > > > CREATE TABLE USER_ROLES ( > > USER_NAME VARCHAR(20) NOT NULL, > > ROLE_ID INTEGER NOT NULL > > ); > > > > PRIMARY KEY (USER_NAME, ROLE_ID); > > FOREIGN KEY (USER_NAME) REFERENCES USERS (USER_NAME); > > FOREIGN KEY (ROLE_ID) REFERENCES "ROLE" (ROLE_ID); > > > > and have defined a class for it as: > > > > public class UserRole extends SRecordInstance > > { > > public static final SRecordMeta meta = new > > RecordMeta(UserRole.class, "USER_ROLES"); > > > > public static final SFieldString USER_NAME = new > > SFieldString(meta, "USER_NAME", 20, SCon.SFD_PRIMARY_KEY); > > > > public static final SFieldLong ROLE_ID = new SFieldLong(meta, > > "ROLE_ID", SCon.SFD_PRIMARY_KEY); > > } > > > > is it possible to define references to the USERS and ROLE tables ? > > and how do I do it! > > > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> Something is new at Yahoo! Groups. Check out the enhanced email design. http://us.click.yahoo.com/kOt0.A/gOaOAA/yQLSAA/5cFolB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/SimpleORM/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/SimpleORM/join (Yahoo! ID required) <*> To change settings via email: mailto:[email protected] mailto:[email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/