`@Entity public class MyEntity {
2.6.1. Simple identifiers
<div class="paragraph">
Simple identifiers map to a single basic attribute, and are denoted using the `javax.persistence.Id` annotation.
</div>
<div class="paragraph">
According to JPA only the following types should be used as identifier attribute types:
</div>
<div class="ulist">
- any Java primitive type
- any primitive wrapper type
java.lang.String
java.util.Date
(TemporalType#DATE)java.sql.Date
java.math.BigDecimal
java.math.BigInteger
</div>Any types used for identifier attributes beyond this list will not be portable.
</div>
Assigned identifiers
Values for simple identifiers can be assigned, as we have seen in the examples above. The expectation for assigned identifier values is that the application assigns (sets them on the entity attribute) prior to calling save/persist.
</div>
Example 107. Simple assigned identifier@Id public Integer id; ...
}`</pre> </div> </div> </div> </div> </div>
Generated identifiers
Values for simple identifiers can be generated. To denote that an identifier attribute is generated, it is annotated with
javax.persistence.GeneratedValue
</div>
Example 108. Simple generated identifier`@Entity public class MyEntity {
@Id @GeneratedValue public Integer id; ...
}`</pre> </div> </div> </div> </div>
Additionally, to the type restriction list above, JPA says that if using generated identifier values (see below) only integer types (short, int, long) will be portably supported.
</div>
The expectation for generated identifier values is that Hibernate will generate the value when the save/persist occurs.
</div>
Identifier value generations strategies are discussed in detail in the Generated identifier values section.
</div> </div> </div>