@(#)orm_1_0.xsd 1.0 Feb 8 2006 The entity-mappings element is the root element of an orm XML file. It contains the following four types of elements: 1. The persistence-unit-defaults element contains default values for the entire persistence unit. It is undefined for this element to be in multiple ORM files within the same persistence unit. 2. The package, schema, catalog and access elements apply to all of the entity, mapped-superclass and embeddable elements defined in this file only. 3. The sequence-generator, table-generator, named-query, named-native-query and sql-result-set-mapping elements are global to the persistence unit. It is undefined to have more than one sequence-generator or table-generator of the same name in the same or different ORM files in a persistence unit. It is also undefined to have more than one named-query or named-native-query of the same name in the same or different ORM files in a persistence unit. 4. The entity, mapped-superclass and embeddable elements each define the complete set, or a subset, of mapping information for a managed persistent class. Setting the metadata-complete attribute to true means that this file contains the complete set of ORM metadata for this persistence unit. No persistence annotations will be processed if this attribute is set. These defaults are applied to the persistence unit as a whole unless they are overridden by local annotation or XML element settings. schema - Used as the schema for all tables or secondary tables defined or defaulted in the persistence unit catalog - Used as the catalog for all tables or secondary tables defined or defaulted in the persistence unit cascade-persist - Adds cascade-persist to the set of cascade options in entity relationships of the persistence unit entity-listeners - List of default entity listeners to be invoked on each entity in the persistence unit. These listeners will be invoked before the listeners defined on the entity Defines the settings and mappings for an entity. Is allowed to be sparsely populated and used in conjunction with the annotations. Alternatively, the metadata-complete element can be used to indicate that no entity annotations are to be processed. @Target(TYPE) @Retention(RUNTIME) public @interface Entity { String name() default ""; } This element contains the entity field or property mappings. It may be sparsely populated to include only a subset of the fields or properties. If metadata-complete for the entity is true then the remainder of the attributes will be defaulted according to the default rules. public enum AccessType { PROPERTY, FIELD }; @Target({METHOD}) @Retention(RUNTIME) public @interface EntityListeners { Class[] value(); } Defines an entity listener to be invoked at lifecycle events for the entities that list this listener. @Target({METHOD}) @Retention(RUNTIME) public @interface PrePersist {} @Target({METHOD}) @Retention(RUNTIME) public @interface PostPersist {} @Target({METHOD}) @Retention(RUNTIME) public @interface PreRemove {} @Target({METHOD}) @Retention(RUNTIME) public @interface PostRemove {} @Target({METHOD}) @Retention(RUNTIME) public @interface PreUpdate {} @Target({METHOD}) @Retention(RUNTIME) public @interface PostUpdate {} @Target({METHOD}) @Retention(RUNTIME) public @interface PostLoad {} public enum FlushModeType { COMMIT, AUTO } @Target({}) @Retention(RUNTIME) public @interface QueryHint { String name(); String value(); } @Target({TYPE}) @Retention(RUNTIME) public @interface NamedQuery { String name(); String query(); QueryHint[] hints() default {}; } @Target({TYPE}) @Retention(RUNTIME) public @interface NamedNativeQuery { String name(); String query(); QueryHint[] hints() default {}; Class resultClass(); String resultSetMapping() default ""; // name of SQLResultSetMapping } @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface SqlResultSetMapping { String name(); EntityResult[] entities() default {}; ColumnResult[] columns() default {}; } @Target({}) @Retention(RUNTIME) public @interface EntityResult { Class entityClass(); FieldResult[] fields() default {}; String discriminatorColumn() default ""; } @Target({}) @Retention(RUNTIME) public @interface FieldResult { String name(); String column(); } @Target({}) @Retention(RUNTIME) public @interface ColumnResult { String name(); } @Target({TYPE}) @Retention(RUNTIME) public @interface Table { String name() default ""; String catalog() default ""; String schema() default ""; UniqueConstraint[] uniqueConstraints() default {}; } @Target({TYPE}) @Retention(RUNTIME) public @interface SecondaryTable { String name(); String catalog() default ""; String schema() default ""; PrimaryKeyJoinColumn[] pkJoinColumns() default {}; UniqueConstraint[] uniqueConstraints() default {}; } @Target({TYPE}) @Retention(RUNTIME) public @interface UniqueConstraint { String[] columnNames(); } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Column { String name() default ""; boolean unique() default false; boolean nullable() default true; boolean insertable() default true; boolean updatable() default true; String columnDefinition() default ""; String table() default ""; int length() default 255; int precision() default 0; // decimal precision int scale() default 0; // decimal scale } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface JoinColumn { String name() default ""; String referencedColumnName() default ""; boolean unique() default false; boolean nullable() default true; boolean insertable() default true; boolean updatable() default true; String columnDefinition() default ""; String table() default ""; } public enum GenerationType { TABLE, SEQUENCE, IDENTITY, AUTO }; @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface AttributeOverride { String name(); Column column(); } @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface AssociationOverride { String name(); JoinColumn[] joinColumns(); } @Target({TYPE}) @Retention(RUNTIME) public @interface IdClass { Class value(); } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Id {} @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface EmbeddedId {} @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Transient {} @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Version {} @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Basic { FetchType fetch() default EAGER; boolean optional() default true; } public enum FetchType { LAZY, EAGER }; @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Lob {} @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Temporal { TemporalType value(); } public enum TemporalType { DATE, // java.sql.Date TIME, // java.sql.Time TIMESTAMP // java.sql.Timestamp } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Enumerated { EnumType value() default ORDINAL; } public enum EnumType { ORDINAL, STRING } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface ManyToOne { Class targetEntity(); CascadeType[] cascade() default {}; FetchType fetch() default EAGER; boolean optional() default true; } public enum CascadeType { ALL, PERSIST, MERGE, REMOVE, REFRESH}; @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface OneToOne { Class targetEntity(); CascadeType[] cascade() default {}; FetchType fetch() default EAGER; boolean optional() default true; String mappedBy() default ""; } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface OneToMany { Class targetEntity(); CascadeType[] cascade() default {}; FetchType fetch() default LAZY; String mappedBy() default ""; } @Target({METHOD, FIELD}) public @interface JoinTable { String name() default ""; String catalog() default ""; String schema() default ""; JoinColumn[] joinColumns() default {}; JoinColumn[] inverseJoinColumns() default {}; UniqueConstraint[] uniqueConstraints() default {}; } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface ManyToMany { Class targetEntity(); CascadeType[] cascade() default {}; FetchType fetch() default LAZY; String mappedBy() default ""; } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface GeneratedValue { GenerationType strategy() default AUTO; String generator() default ""; } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface MapKey { String name() default ""; } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface OrderBy{ String value() default ""; } @Target({TYPE}) @Retention(RUNTIME) public @interface Inheritance { InheritanceType strategy() default SINGLE_TABLE; } public enum InheritanceType { SINGLE_TABLE, JOINED, TABLE_PER_CLASS}; @Target({TYPE}) @Retention(RUNTIME) public @interface DiscriminatorValue { String value(); } public enum DiscriminatorType { STRING, CHAR, INTEGER }; @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface PrimaryKeyJoinColumn { String name() default ""; String referencedColumnName() default ""; String columnDefinition() default ""; } @Target({TYPE}) @Retention(RUNTIME) public @interface DiscriminatorColumn { String name() default ""; DiscriminatorType discriminatorType() default STRING; String columnDefinition() default ""; int length() default 31; } Defines the settings and mappings for embeddable objects. Is allowed to be sparsely populated and used in conjunction with the annotations. Alternatively, the metadata-complete element can be used to indicate that no annotations are to be processed in the class @Target({TYPE}) @Retention(RUNTIME) public @interface Embeddable {} @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Embedded {} Defines the settings and mappings for a mapped superclass. Is allowed to be sparsely populated and used in conjunction with the annotations. Alternatively, the metadata-complete element can be used to indicate that no annotations are to be processed in the class. @Target(TYPE) @Retention(RUNTIME) public @interface MappedSuperclass{} @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface SequenceGenerator { String name(); String sequenceName() default ""; int initialValue() default 0; int allocationSize() default 50; } @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface TableGenerator { String name(); String table() default ""; String catalog() default ""; String schema() default ""; String pkColumnName() default ""; String valueColumnName() default ""; String pkColumnValue() default ""; int initialValue() default 0; int allocationSize() default 50; UniqueConstraint[] uniqueConstraints() default {}; }