Avoiding overlapping maps
In some cases, the mapping tool allows you to map a column in the database twice, once as an attribute and once in a relationship role. This can be referred to as an overlap in the mapping. This overlap could cause data integrity problems. For this reason, you should avoid overlapping your mappings to database elements.
Consider the following example of an overlapped mapping that you could create with the mapping tool:
- Bean1 has a key field that is mapped to the PK1 (primary key) column of Table1, and Bean2 has a key field that is mapped to the PK2 column of Table2. Table2 includes a FK2 (foreign key) column that points to the PK1 column of Table1. You create a relationship between Bean1 and Bean2, and you map this relationship using the FK2 column in Table2.
- You then directly map a simple CMP attribute in Bean2 to the FK2 column in Table2. The FK2 column is now mapped twice, once as as a mapped attribute and once as a mapped relationship between the two beans. This overlap could lead to problems if the columns or the tables change.
- For example, if you use the setter in Bean2 to change the FK2 column (which is also a foreign key) and then save this change, the next time you reload your beans they will have changed relationships. Or, if you change the relationship so that Bean2 is now pointing at another instance of Bean1, the attribute in Bean2 will not reflect that change.
Parent topic
Updating maps with the Mapping editor