WebObjects/EOF/Modeling/Entities

(Redirected from Programming:WebObjects/EOF/Modeling/Entities)

An entity in an object graph usually represents a table in a relational database. For example, suppose one is working with a school. One may have a database with one table of students and a list of classrooms. In standard SQL-ish notation, the table of students might be called STUDENT and the table of classrooms may be called ROOM. One would have a "Student" entity and a "Room" entity.

It was a deliberate choice to call our ROOM table by that name. It could have been called CLASSROOM. One may see, though, that a classroom is really any room in which one puts students and in which one hopes they can be taught. Thus, the rooms are just rooms. There may be other more abstractions one can use. One may decide that students are just instances from a list of PERSON, and this would not be wrong. How abstract one chooses one's entities to be is a matter of choice and experience.

EOF uses the class com.webobjects.eoaccess.EOEntity to manage an entity.

An entity may be something other than a table. An entity can represent any group of things, when it is useful to look just at that group, as a group.

For example, one may decide to use a PERSON table. One may have a column in the table for 'isStudent'. There are other ways to do this, but this is one method. In this case, an entity "Student" can be defined as the objects in the PERSON table which satisfy the qualifier defined as "(isStudent == YES)". Indeed, this is how one sets up an entity using single-table entity inheritance.

One may also have some external data source through which one gets information. For example, an external tool could be retrieve price information from the New York Stock Exchange. The list of "prices received from NYSE today" could be modelled as an entity, though an entity with volatile contents. One could have a telescope reporting to a data service with "objects in field of view that are moving". This would be an extremely volatile entity. It might be likely that no object will appear twice in this entity, which is not at all how a relational database would be expected to behave, but it can be viewed as an entity nonetheless.