### Mapping OO domain model to database model

 The @Entity annotation marks class StudyCourse to become a JPA mapped entity. Every @Entity must have exactly one @Id property (or a combination of properties) designated to become the entities primary key. @Column annotations are optional supplying additional JPA mapping meta data Limit the shortName and fullName attributes' database length. Property fullName is about to become a unique key. Since fullName is no primary but just a unique key we have to state the desired business rule constraint explicitly.

No. 40

#### Database server limitations

Q:

Repeat Figure 913, “StudyCourse entity definition ” but omit the length = 150 constraint.

Analyze the generated schema. What do you observe? Give an explanation.

### Tip

Read the Mysql server Maximums and Minimums documentation.

A:

The generated schema lacks a unique key definition in contrast to the unique=true setting.

Mysql imposes upper limits on unique key lengths. Omitting length = 150 implies type VARCHAR(255). Depending on the database server's encoding the resulting length exceeds a key's maximum possible length.

Unfortunately this happens silently without even a warning.