- This topic has 2 replies, 2 voices, and was last updated 13 years, 1 month ago by jkennedy.
-
AuthorPosts
-
Smitht19MemberMyEclipse is not creating any code for a OneToMany between my User table and My User Roles Table. I tell MyEclipse that the user Table is the parent. It does not ask about any join keys. I have included my Oracle tables. I will take any help I can get.
My User should have many roles
User Roles table
LTER TABLE STATE_HOSPITALS.USER_ROLES DROP PRIMARY KEY CASCADE; DROP TABLE STATE_HOSPITALS.USER_ROLES CASCADE CONSTRAINTS; CREATE TABLE STATE_HOSPITALS.USER_ROLES ( USER_ROLE_ID NUMBER(10) NOT NULL, CREATED_BY VARCHAR2(30 BYTE), CREATED_ON DATE, MODIFIED_BY VARCHAR2(30 BYTE), MODIFIED_ON DATE, USER_ID NUMBER(10) NOT NULL, ROLE_ROLE_ID NUMBER(10) NOT NULL ) TABLESPACE USERS PCTUSED 0 PCTFREE 10 INITRANS 1 MAXTRANS 255 STORAGE ( INITIAL 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 BUFFER_POOL DEFAULT ) LOGGING NOCOMPRESS NOCACHE NOPARALLEL MONITORING; COMMENT ON COLUMN STATE_HOSPITALS.USER_ROLES.USER_ROLE_ID IS 'Sequence generated number that uniquely identifies the record.'; COMMENT ON COLUMN STATE_HOSPITALS.USER_ROLES.CREATED_BY IS 'Username of the person who created the record.'; COMMENT ON COLUMN STATE_HOSPITALS.USER_ROLES.CREATED_ON IS 'Date the record was created.'; COMMENT ON COLUMN STATE_HOSPITALS.USER_ROLES.MODIFIED_BY IS 'Username of the person that modiified the record.'; COMMENT ON COLUMN STATE_HOSPITALS.USER_ROLES.MODIFIED_ON IS 'Date the record was modified.'; COMMENT ON COLUMN STATE_HOSPITALS.USER_ROLES.USER_ID IS 'System generated number that uniquely identifies this record.'; COMMENT ON COLUMN STATE_HOSPITALS.USER_ROLES.ROLE_ROLE_ID IS 'System generated number that uniquely identifies the record.'; CREATE INDEX STATE_HOSPITALS.UR_ROL_FK_I ON STATE_HOSPITALS.USER_ROLES (ROLE_ROLE_ID) LOGGING TABLESPACE USERS PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE ( INITIAL 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 BUFFER_POOL DEFAULT ) NOPARALLEL; CREATE INDEX STATE_HOSPITALS.UR_USE_1_FK_I ON STATE_HOSPITALS.USER_ROLES (USER_ID) LOGGING TABLESPACE USERS PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE ( INITIAL 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 BUFFER_POOL DEFAULT ) NOPARALLEL; CREATE UNIQUE INDEX STATE_HOSPITALS.USER_ROLE_PK ON STATE_HOSPITALS.USER_ROLES (USER_ROLE_ID) LOGGING TABLESPACE USERS PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE ( INITIAL 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 BUFFER_POOL DEFAULT ) NOPARALLEL; CREATE OR REPLACE TRIGGER STATE_HOSPITALS.TR_USER_ROLES_CREATED BEFORE INSERT ON STATE_HOSPITALS.USER_ROLES FOR EACH ROW BEGIN IF :NEW.USER_ROLE_ID IS NULL THEN SELECT SH_USER_ROLE_SEQ.NEXTVAL INTO :NEW.USER_ROLE_ID FROM DUAL; END IF; IF :NEW.created_on IS NULL THEN SELECT SYSDATE INTO :NEW.created_on FROM DUAL; END IF; END TR_USER_ROLES_CREATED; / CREATE OR REPLACE TRIGGER STATE_HOSPITALS.TR_USER_ROLES_MODIFIED BEFORE UPDATE OF USER_USER_ID , ROLE_ROLE_ID ON STATE_HOSPITALS.USER_ROLES FOR EACH ROW BEGIN :new.modified_on := SYSDATE; END TR_USER_ROLES_MODIFIED; / ALTER TABLE STATE_HOSPITALS.USER_ROLES ADD ( CONSTRAINT USER_ROLE_PK PRIMARY KEY (USER_ROLE_ID) USING INDEX STATE_HOSPITALS.USER_ROLE_PK); ALTER TABLE STATE_HOSPITALS.USER_ROLES ADD ( CONSTRAINT USER_ROLE_FK FOREIGN KEY (ROLE_ROLE_ID) REFERENCES STATE_HOSPITALS.ROLES (ROLE_ID));
My User Table
ALTER TABLE STATE_HOSPITALS.USERS DROP PRIMARY KEY CASCADE; DROP TABLE STATE_HOSPITALS.USERS CASCADE CONSTRAINTS; CREATE TABLE STATE_HOSPITALS.USERS ( USER_ID NUMBER(10) NOT NULL, USER_NAME VARCHAR2(30 BYTE), FIRST_NAME VARCHAR2(20 BYTE), LAST_NAME VARCHAR2(20 BYTE), STATUS VARCHAR2(10 BYTE), ADMINISTRATOR VARCHAR2(1 BYTE), CREATED_BY VARCHAR2(30 BYTE), CREATED_ON DATE, MODIFIED_BY VARCHAR2(30 BYTE), MODIFIED_ON DATE ) TABLESPACE USERS PCTUSED 0 PCTFREE 10 INITRANS 1 MAXTRANS 255 STORAGE ( INITIAL 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 BUFFER_POOL DEFAULT ) LOGGING NOCOMPRESS NOCACHE NOPARALLEL MONITORING; COMMENT ON COLUMN STATE_HOSPITALS.USERS.USER_ID IS 'System generated number that uniquely identifies this record.'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.USER_NAME IS 'Single Sign On username of the user.'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.FIRST_NAME IS 'First name of the user entering the IBS data'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.LAST_NAME IS 'Last name of the user entering the IBS data'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.STATUS IS 'Indicates whether the user is an active or inactive user of the system.'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.ADMINISTRATOR IS 'The role of the user as it pertains to functions needed on the system.'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.CREATED_BY IS ' Username of the person who entered the record in the system.'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.CREATED_ON IS 'Date the record was entered into the system.'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.MODIFIED_BY IS 'Username of the person who last modified the record in the system.'; COMMENT ON COLUMN STATE_HOSPITALS.USERS.MODIFIED_ON IS ' Date the record was last modified in the system.'; CREATE UNIQUE INDEX STATE_HOSPITALS.USERS_USER_ID_PK ON STATE_HOSPITALS.USERS (USER_ID) LOGGING TABLESPACE USERS PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE ( INITIAL 64K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 BUFFER_POOL DEFAULT ) NOPARALLEL; CREATE OR REPLACE TRIGGER STATE_HOSPITALS.TR_USERS_MODIFIED BEFORE UPDATE OF ADMINISTRATOR , STATUS , FIRST_NAME , LAST_NAME , USER_NAME ON STATE_HOSPITALS.USERS FOR EACH ROW BEGIN :new.modified_on := SYSDATE; END TR_USERS_MODIFIED; / CREATE OR REPLACE TRIGGER STATE_HOSPITALS.TR_USERS_CREATED BEFORE INSERT ON STATE_HOSPITALS.USERS FOR EACH ROW BEGIN IF :NEW.USER_ID IS NULL THEN SELECT SH_USERS_SEQ.NEXTVAL INTO :NEW.USER_ID FROM DUAL; END IF; IF :NEW.created_on IS NULL THEN SELECT SYSDATE INTO :NEW.created_on FROM DUAL; END IF; END TR_USERS_CREATED; / ALTER TABLE STATE_HOSPITALS.USERS ADD ( CONSTRAINT USERS_USER_ID_PK PRIMARY KEY (USER_ID) USING INDEX STATE_HOSPITALS.USERS_USER_ID_PK);
Smitht19MemberI was missing a Foreign Key so I was not creating the OneToMany. Here is my problem now. When I save a User I am not saving a UserRole. II am new to Hibernate. I have written some Hibernate code with no software generation. My biggest issue with Myeclipse for Spring is trying to understand the code that was generated. There is not any OneToMany examples out there using generated code from MyEclipse for Spring. Sure the Videos out there are great if you only have single tables to populate that works great. Please advise
Thanks
jkennedyMemberYou can review this video to see a 1 to M relationship in action (in this case, with a Flex front ent).
http://www.youtube.com/user/myeclipseforspring#p/u/12/WRm1n3WgZgo
Many of our documents and instructional materials include demonstrations of 1 to M relationships.
You can use the embedded derby database to scaffold out code that demonstrates these types of relationships if you are new to JPA / Hibernate based coding.
The scaffolding engine will use the MetaData from your schema to generate the code, and so yes, if that meta data does not include information that is needed to form the relationship, it will not be generated.
Regarding the behavior you are seeing in this case, you should put a break point in the DAO or service code where the User is being saved. It isn’t clear to me the steps you are following in the generated UI, but you can verify that the Object you are receiving at the DAO layer matches with the information you are putting in through the Web UI and go from there.
Thanks,
Jack -
AuthorPosts