OK, I understand that, thanks,
ray.
I am using mySQL, not derby by
default.
I have to manually add constraints by
myself.
In the
example,
The HomeAddress, WorkAddress,
and BillingAddress inherit from Address using vertical inheritance.
1.How to
write foreign key constraints for them?
Teacher/Employee has
workAddress
2. Is there
foreign key constraints between Employee and Address or
workaddress?
I added
constraints for EMPLOYEE_ADDRESS, broken the insertion when i create new teacher
with workaddress.
Deleted this
constraints OR add constraints EMPLOYEE_WORKADDRESS, insert succeed,
but broken
the code EOUtilities.objectsForEntityNamed(ec, "Teacher"); after restart
app.
error
message:
Error:
java.lang.IllegalStateException
exception Reason: java.lang.IllegalStateException: The object with
globalID _EOIntegralKeyGlobalID[Address (java.lang.Integer)49] could not be
found in the database. This could be result of a referential integrity problem
with the database. An empty fault could not be created because the object's
class could not be determined (e.g. the GID is temporary or it is for an
abstract entity).
how to fix it?
thanks,
kevin
On Jun 18, 2008, at 7:33 PM, Ren, Kevin wrote:
Hi,
My question is coming from "SQL generation" in
Entity Modeler. When I am playing the
code with Apple/example/SophisticatedDatabaseExample.
Both EOModeler and Entity Modeler take the approach that they are speaking
JDBC, not any database-specific SQL. There are, of course, plugins that can make
the behavior of any of the EOAdaptors more sophisticated. I do not think that
Entity Modeler promises to do everything it could do to create the optimal SQL
for any particular database and schema.
A couple of things. If you know what you want, you can probably add the
proper constraints yourself. EOF's primary job is to give you an object graph,
not to do database design.
Also, if you want to suggest changes to any of the plugins in PWO, you
could. The new SQL implemented there would have to not break anyone else.
I would also ask if all the complexity allowed in your database needs to
have a place in the model. A model provides an abstraction. Perhaps the model
could be kept simpler for greater flexibility in the future.
But then again, EOF and Entity Modeler could always do better. Sometimes
the tools just really do the most minimal job and more could be done.
cheers - ray
Copied from README: The SophisticatedDatabaseExample demonstrates the use of inheritance,
flattening, and multiple models.
The Person class is abstract. Student, Parent and
Employee inherit from Person using horizontal inheritance. The Admin,Staff, Teacher classes all inherit from Employee
using single-table inheritance. The
HomeAddress, WorkAddress, and BillingAddress inherit from Address using
vertical inheritance.
The relationship between Student and
ScheduledCourse is an example of a many-to-many "flattened" relationship. The
normal indirect "join" table values are extracted into each side of the
relationship, giving the appearance of a direct many-to-many relationship
between entities(classes). This relationship is interesting because Student is
an entity in the School model but ScheduledClass is an entity in the Course
model.
When I tried to create foreign key constraints
using "Generate SQL", I only got some constraints, not all of them.
All I got from two models: ALTER TABLE SCHEDULED_CLASS ADD CONSTRAINT
SCHEDULED_CLASS_SCHEDULE_FK FOREIGN KEY (SCHEDULE_ID) REFERENCES SCHEDULE
(SCHEDULE_ID);
ALTER TABLE SCHEDULED_CLASS ADD CONSTRAINT
SCHEDULED_CLASS_COURSE_FK FOREIGN KEY (COURSE_ID) REFERENCES COURSE
(COURSE_ID);
ALTER TABLE SCHEDULED_CLASS ADD CONSTRAINT
SCHEDULED_CLASS_CLASSROOM_FK FOREIGN KEY (CLASSROOM_ID) REFERENCES CLASSROOM
(CLASSROOM_ID);
ALTER TABLE STUDENTPARENT ADD CONSTRAINT
STUDENTPARENT_STUDENT_FK FOREIGN KEY (PARENT_ID) REFERENCES STUDENT
(PERSON_ID);
ALTER TABLE STUDENTPARENT ADD CONSTRAINT
STUDENTPARENT_PARENT_FK FOREIGN KEY (PARENT_ID) REFERENCES PARENT
(PERSON_ID);
ALTER TABLE STUDENT_SCHEDULED_CLASS ADD
CONSTRAINT STUDENT_SCHEDULED_CLASS_STUDENT_FK FOREIGN KEY (STUDENT_ID)
REFERENCES STUDENT (PERSON_ID);
I think some foreign key constraints are missing,
like SCHEDULED_CLASS and
TEACHER(EMPLOYEE), EMPLOYEE and ADDRESS, STUDENT and STUDENT_SCHEDULED_CLASS
…..
Is it bug in Entity Modeler or somewhere couldn't
figure out the horizontal/vertical inheritance in the model?
Thanks
Kevin
"This communication is confidential and may
contain privileged and/or copyright material. If you are not the intended
recipient you must not use, disclose, copy or retain it. If you have received
it in error please immediately notify me by return email, delete the emails
and destroy any hard copies. ANZ National Bank Limited does not guarantee the
integrity of this communication, or that it is free from errors, viruses or
interference."
_______________________________________________
Do not post admin requests to the list. They will be
ignored.
Help/Unsubscribe/Update your Subscription:
"This communication is confidential and may contain
privileged and/or copyright material. If you are not the intended recipient you
must not use, disclose, copy or retain it. If you have received it in error
please immediately notify me by return email, delete the emails and destroy any
hard copies. ANZ National Bank Limited does not guarantee the integrity of this
communication, or that it is free from errors, viruses or
interference."
|