hibernate annontaion learn more

sponsored links
Hibernate Annotation Description

Turn http://relucent.javaeye.com/
@ Entity
public class Flight implements Serializable (
Long id;
@ Id
public Long getId () (return id;)
public void setId (Long id) (this.id = id;)
)

@ Entity annotation to a class declaration for the entity Bean, @ Id annotation declares the identity of the entity Bean property.

Hibernate can be property or method of the class notes. Attribute the corresponding field types, method of getXxx () the corresponding property types.

Definition Table

@ Table as the entity through the corresponding database table specified Bean, catalogs and schema name.

@ Entity
@ Table (name = "tbl_sky")
public class Sky implements Serializable (

...

@ Table annotation contains a schema and a catelog attribute table can be defined using the @ UniqueConstraints the only constraint.

@ Table (name = "tbl_sky",
uniqueConstraints = (@ UniqueConstraint (columnNames = ("month", "day")))
)

The code in the "month" and "day" field on the two with unique constrainst.

@ Version annotation used to support optimistic locking version control.

@ Entity
public class Flight implements Serializable (
...
@ Version
@ Column (name = "OPTLOCK")
public Integer getVersion () (...)
)

version property is mapped to "OPTLOCK" column, entity manager use this field to detect conflicts. General can be numbers or timestamp type to support version.

Entity Bean in all non-static non transient property can be persistent, unless using the @ Transient annotation.

By default, all attributes with @ Basic annotation.

public transient int counter; / / transient property

private String firstname; / / persistent property
@ Transient
String getLengthInMeter () (...) / / transient property
String getName () (...) / / persistent property
@ Basic
int getLength () (...) / / persistent property
@ Basic (fetch = FetchType.LAZY)
String getDetailedComment () (...) / / persistent property
@ Temporal (TemporalType.TIME)
java.util.Date getDepartureTime () (...) / / persistent property
@ Enumerated (EnumType.STRING)
Starred getNote () (...) / / enum persisted as String in database

The code counter, lengthInMeter property will not be ignored persistent, and firstname, name, length was defined as persistent and accessible.

@ TemporalType. (DATE, TIME, TIMESTAMP) were Map java.sql. (Date, Time, Timestamp).

@ Lob annotation properties will be persisted in a Blog or Clob type. Specific java.sql.Clob, Character [], char [] and java.lang.String will be persisted in a Clob type. Java.sql.Blob, Byte [], byte [] and serializable type will be persisted in a Blob type.

@ Lob
public String getFullText () (
return fullText; / / clob type
)

@ Lob
public byte [] getFullCode () (
return fullCode; / / blog type
)

@ Column annotation attribute mapped to the column.

@ Entity
public class Flight implements Serializable (
...
@ Column (updatable = false, name = "flight_name", nullable = false, length = 50)
public String getName () (...)

Defined name attribute is mapped to flight_name column, not null, can't update, length equal 50

@ Column (
name = "columnName"; (1) listing
boolean unique () default false; (2) whether to set a unique constraint on the column
boolean nullable () default true; (3) columns can be empty?
boolean insertable () default true; (4) whether the column generated insert statement as a column
boolean updatable () default true; (5) whether the column as a column generated update statement
String columnDefinition () default ""; (6) default
String table () default ""; (7) defines the corresponding table (deault is the main table)
int length () default 255; (8) column length
int precision () default 0; / / decimal precision (9) decimal precision
int scale () default 0; / / decimal scale (10) decimal length

Embedded objects (also known as component) is defined by other object properties

Component class must be defined at the class level @ Embeddable annotation. In the particular entity associated with the use of property and @ AttributeOverride @ Embeddable annotations to override the embedded object attributes corresponding to the column mapping.

@ Entity
public class Person implements Serializable (
/ / Persistent component using defaults
Address homeAddress;
@ Embedded
@ AttributeOverrides ((
@ AttributeOverride (name = "iso2", column = @ Column (name = "bornIso2")),
@ AttributeOverride (name = "name", column = @ Column (name = "bornCountryName"))
))
Country bornIn;
...
)

@ Embeddable
public class Address implements Serializable (
String city;
Country nationality; / / no overriding here
)

@ Embeddable
public class Country implements Serializable (
private String iso2;
@ Column (name = "countryName") private String name;
public String getIso2 () (return iso2;)
public void setIso2 (String iso2) (this.iso2 = iso2;)
public String getName () (return name;)
public void setName (String name) (this.name = name;)
...
)

Person class defines Address and Country objects, see above the concrete realization of the two classes.

No comments attribute default values:

? Property as a simple type, is mapped as @ Basic

? Attribute corresponds to the type of @ Embeddable annotation is defined, it is mapped as @ Embedded

? Attribute corresponding types of implements Serializable, then property is mapped as @ Basic in a column to save the object's serialized version.

? Property is of type java.sql.Clob or java.sql.Blob, is mapped to the corresponding type of @ Lob.

Mapping the primary key attribute

@ Id annotation entity Bean can be defined in a primary key attribute, use @ GenerateValue annotation can be defined in the identifier generation strategy.

? AUTO - can be identity column, sequence or table type, depending on the underlying database
? TABLE - save the id value using the table
? IDENTITY - identity column
? SEQUENCE - seque

nce

@ Id @ GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
public Integer getId () (...)

@ Id @ GeneratedValue (strategy = GenerationType.IDENTITY)
public Long getId () (...)

AUTO generator, application and application portability, a number of @ Id can share the same identifier generator, as long as the generator set to the same value property can be. By @ SequenceGenerator and @ TableGenerator can configure a different identifier generator.

<Table-generator name = "EMP_GEN"
table = "GENERATOR_TABLE"
pk-column-name = "key"
value-column-name = "hi"
pk-column-value = "EMP"
allocation-size = "20" />
/ / And the annotation equivalent
@ Javax.persistence.TableGenerator (
name = "EMP_GEN",
table = "GENERATOR_TABLE",
pkColumnName = "key",
valueColumnName = "hi"
pkColumnValue = "EMP",
allocationSize = 20
)
<Sequence-generator name = "SEQ_GEN"
sequence-name = "my_sequence"
allocation-size = "20" />
/ / And the annotation equivalent
@ Javax.persistence.SequenceGenerator (
name = "SEQ_GEN",
sequenceName = "my_sequence",
allocationSize = 20
)

The next example shows the definition of a sequence generator in a class scope:

@ Entity
@ Javax.persistence.SequenceGenerator (
name = "SEQ_STORE",
sequenceName = "my_sequence"
)
public class Store implements Serializable (
private Long id;
@ Id @ GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
public Long getId () (return id;)
)

Store class uses named my_sequence the sequence, and SEQ_STORE generator for other class is not visible.

By the following syntax, you can define key combinations.

? The Component class annotations as @ Embeddable, and components of the property for the @ Id annotation
? The components of the property annotated @ EmbeddedId
? The class annotated @ IdClass, and all the primary key of the entity attributes are annotated with @ Id

@ Entity
@ IdClass (FootballerPk.class)
public class Footballer (
/ / Part of the id key
@ Id public String getFirstname () (
return firstname;
)
public void setFirstname (String firstname) (
this.firstname = firstname;
)
/ / Part of the id key
@ Id public String getLastname () (
return lastname;
)
public void setLastname (String lastname) (
this.lastname = lastname;
)
public String getClub () (
return club;
)
public void setClub (String club) (
this.club = club;
)
/ / Appropriate equals () and hashCode () implementation
)

@ Embeddable
public class FootballerPk implements Serializable (
/ / Same name and type as in Footballer
public String getFirstname () (
return firstname;
)
public void setFirstname (String firstname) (
this.firstname = firstname;
)
/ / Same name and type as in Footballer
public String getLastname () (
return lastname;
)
public void setLastname (String lastname) (
this.lastname = lastname;
)
/ / Appropriate equals () and hashCode () implementation
)

@ Entity
@ AssociationOverride (name = "id.channel", joinColumns = @ JoinColumn (name = "chan_id"))
public class TvMagazin (
@ EmbeddedId public TvMagazinPk id;
@ Temporal (TemporalType.TIME) Date time;
)

@ Embeddable
public class TvMagazinPk implements Serializable (
@ ManyToOne
public Channel channel;
public String name;
@ ManyToOne
public Presenter presenter;
)

Mapping inheritance

EJB supports 3 types of inheritance.

? Table per Class Strategy: the <union-class> element in Hibernate a table for each class
? Single Table per Class Hierarchy Strategy: the <subclass> element in Hibernate a table for each class hierarchy
? Joined Subclass Strategy: the <joined-subclass> element in Hibernate to connect the sub-class strategy

@ Inheritance annotation to define the class of the selected strategy.

A table for each class

@ Entity
@ Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
public class Flight implements Serializable (

Shortcomings, such as multi-state inquiries or association. Hibernate queries using SQL Union to implement this strategy. This strategy supports two-way-to-many association, but does not support IDENTIFY generator strategy, because ID must be shared across several tables. Can not be used when using the AUTO and IDENTIFY generator.

A table for each class hierarchy

@ Entity
@ Inheritance (strategy = InheritanceType.SINGLE_TABLE)
@ DiscriminatorColumn (
name = "planetype",
discriminatorType = DiscriminatorType.STRING
)
@ DiscriminatorValue ("Plane")
public class Plane (...)

@ Entity
@ DiscriminatorValue ("A320")
public class A320 extends Plane (...)

The entire hierarchy of all classes and subclasses of the parent properties are mapped to the same table, instances are to identify break through a column (discriminator) to differentiate.

Plane is the parent class. @ DiscriminatorColumn annotation defines the symbol to identify the column. Inheritance hierarchy for each class, @ DiscriminatorValue annotation defines the value used to identify the class. Break out to identify the name of the default for the DTYPE, its default value entity name. The type DiscriminatorType.STRING.

Subclass of connected

@ Entity
@ Inheritance (strategy = InheritanceType.JOINED)
public class Boat implements Serializable (...)

@ Entity
public class Ferry extends Boat (...)

@ Entity
@ PrimaryKeyJoinColumn (name = "BOAT_ID")
public class AmericaCupClass extends Boat (...)

All of the above entities use the JOINED strategy Ferry and Boat class primary key associated with the use of the same name (eg: Boat.id = Ferry.id), AmericaCupClass and Boat related conditions Boat.id = AmericaCupClass.BOAT_ID.

Property inherited from the parent class

@ MappedSuperclass
public class BaseEntity (
@ Basic
@ Temporal (TemporalType.TIMESTAMP)
public Date getLastUpdate () (...)
public String getLastUpdater () (...)
...
)

@ Entity class Order extends BaseEntity (
@ Id public Integer getId () (...)
...
)

Some properties of the parent class inheritance, but not as a mapping parent entity, this time need @ MappedSuperclass annotation. The entity is mapped to the database when the corresponding Order entity Bean, its has a id, lastUpdate, lastUpdater three attributes. If there is no @ MappedSuperclass annotation, then the parent class attribute ignored, this is only the Order Entity Bean id an attribute.

Entity Bean mapping relationship between the association

One to One

Annotation using the @ OneToOne can create one to one relationship between the entity Bean. There are three kinds of cases one to one relationship.

? Related entities share the same primary key.

@ Entity
public class Body (
@ Id
public Long getId () (return id;)
@ OneToOne (cascade = CascadeType.ALL)
@ PrimaryKeyJoinColumn
public Heart getHeart () (
return heart;
)
...
)

@ Entity
public class Heart (
@ Id
public Long getId () (...)
)

Annotation is defined by @ PrimaryKeyJoinColumn one to one association.

? Foreign key by one entity to another entity associated with the primary key. Note: one on one, then the foreign key constraint must be unique.

@ Entity
public class Customer implements Serializable (
@ OneToOne (cascade = CascadeType.ALL)
@ JoinColumn (name = "passport_fk")
public Passport getPassport () (
...
)

@ Entity
public class Passport implements Serializable (
@ OneToOne (mappedBy = "passport")
public Customer getOwner () (
...
)

@ JoinColumn annotation defined by one to one association. If no @ JoinColumn annotation, the system automatically handles, in the main table will be created to connect the column, the column name: the theme associated with the property name + underscore + is associated with the primary key column names end. The cases passport_id, as in the associated attribute Customer passport, Passport's primary key is id.

? Through the association table to hold the relationships between the two entities. Note: one on one, then the related table for each foreign key must be the only constraint.

@ Entity
public class Customer implements Serializable (
@ OneToOne (cascade = CascadeType.ALL)
@ JoinTable (name = "CustomerPassports",
joinColumns = @ JoinColumn (name = "customer_fk"),
inverseJoinColumns = @ JoinColumn (name = "passport_fk")
)
public Passport getPassport () (
...
)

@ Entity public class Passport implements Serializable (
@ OneToOne (mappedBy = "passport")
public Customer getOwner () (
...
)

Customer table and Passport related by CustomerPassports association. The association table foreign key pointing through passport_fk Passport table, the confidence is defined as inverseJoinColumns the property value. By customer_fk foreign key point to Customer table, the information is defined as joinColumns property value.

Many to one

@ ManyToOne annotation using the definition of many to one relationship.

@ Entity ()
public class Flight implements Serializable (
@ ManyToOne (cascade = (CascadeType.PERSIST, CascadeType.MERGE))
@ JoinColumn (name = "COMP_ID")
public Company getCompany () (
return company;
)
...
)

@ JoinColumn annotation which is optional, defaults and key fields similar to one to one association. Listed as: the theme associated with the property name + underscore + is associated with the primary key column names end. In this case company_id, because of the associated property is company, Company of the primary key for the id.

@ ManyToOne annotation have targetEntity attribute defines the parameters of the target entity name. Usually do not need to define, in most cases the default values. However, this situation requires targetEntity following definition (to use interface as the return value, rather than the commonly used entities).

@ Entity ()
public class Flight implements Serializable (
@ ManyToOne (cascade = (CascadeType.PERSIST, CascadeType.MERGE), targetEntity = CompanyImpl.class)
@ JoinColumn (name = "COMP_ID")
public Company getCompany () (
return company;
)
...
)

public interface Company (
...

Many to one association table can also be a way to map annotations can be defined through the @ JoinTable associated table. The association table contains foreign key refers back to the entity (via @ JoinTable.joinColumns) and to the target entity table foreign key (via @ JoinTable.inverseJoinColumns).

@ Entity ()
public class Flight implements Serializable (

@ ManyToOne (cascade = (CascadeType.PERSIST, CascadeType.MERGE))
@ JoinTable (name = "Flight_Company",
joinColumns = @ JoinColumn (name = "FLIGHT_ID"),
inverseJoinColumns = @ JoinColumn (name = "COMP_ID")
)
public Company getCompany () (
return company;
)
...
)

Collection type

One to many

@ OneToMany annotation can be defined many relationships. Many relationships can be bidirectional.

Two-way

Specification is almost always more on the side of the main two-way association (owner) side, and one to many association annotation to @ OneToMany (mappedBy =)

@ Entity
public class Troop (
@ OneToMany (mappedBy = "troop")
public Set <Soldier> getSoldiers () (
...
)

@ Entity
public class Soldier (
@ ManyToOne
@ JoinColumn (name = "troop_fk")
public Troop getTroop () (
...
)

Troop Soldier through the troop property and established a one to many bidirectional association. In mappedBy side without any physical mapping can not be defined.

Unidirectional

@ Entity
public class Customer implements Serializable (
@ OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@ JoinColumn (name = "CUST_ID")
public Set <Ticket> getTickets () (
...
)

@ Entity
public class Ticket implements Serializable (
... / / No bidir
)

Usually by connecting the table to achieve this association, you can @ JoinColumn annotation to describe this one-way relation. Customer CUST_ID out by the example and established a one-way Ticket affiliated.

Through the association table to deal with one-way association

@ Entity
public class Trainer (
@ OneToMany
@ JoinTable (
name = "TrainedMonkeys",
joinColumns = @ JoinColumn (name = "trainer_id"),
inverseJoinColumns = @ JoinColumn (name = "monkey_id")
)
public Set <Monkey> getTrainedMonkeys () (
...
)

@ Entity
public class Monkey (
... / / No bidir
)

Through the association to deal with one-way-to-many relationship table is preferred, this association by @ JoinTable annotations to describe. Trainer on the example table and the Monkey by TrainedMonkeys established one-way relation. One foreign key trainer_id associated Trainer (joinColumns) key monkey_id suits related to the Monkey (inverseJoinColumns).

The default handling mechanism

By connecting the table to create a one-way-to-many association mapping does not require any physical description, the table name consists of the following three parts, the main table (owner table) the table name + underscore + from the table (the other side table) table name . Point to the main table of the foreign key name: name + underscore + Main outstanding master table primary key column names point to the definition from the table as the only foreign key constraint, used to represent one to many association.

@ Entity
public class Trainer (
@ OneToMany
public Set <Tiger> getTrainedTigers () (
...
)

@ Entity
public class Tiger (
... / / No bidir
)

Tiger Trainer and the above example the table to establish a one-way connection through Trainer_Tiger affiliated. Which related to foreign key trainer_id Trainer table, the outer table key trainedTigers_id related to Tiger.

Many to many

Defined by @ ManyToMany annotation-many relationships and described by @ JoinTable annotation associated with the table and associated conditions. One end is defined as the owner, the other a defined inverse (on the association table update operation, this is ignored.)

@ Entity
public class Employer implements Serializable (
@ ManyToMany (
targetEntity = org.hibernate.test.metadata.manytomany.Employee.class,
cascade = (CascadeType.PERSIST, CascadeType.MERGE)
)
@ JoinTable (
name = "EMPLOYER_EMPLOYEE",
joinColumns = @ JoinColumn (name = "EMPER_ID"),
inverseJoinColumns = @ JoinColumn (name = "EMPEE_ID")
)
public Collection getEmployees () (
return employees;
)
...
)

@ Entity
public class Employee implements Serializable (
@ ManyToMany (
cascade = (CascadeType.PERSIST, CascadeType.MERGE),
mappedBy = "employees",
targetEntity = Employer.class
)
public Collection getEmployers () (
return employers;
)
)

Default value:

Associated table name: the main outstanding name + underscore + from the outstanding name; related to the main table table foreign key: the main outstanding name + underscore + master table primary key column names; association table to the outside from the table key name: the main table for the associated property name + underscore + from the table the primary key column names.

To achieve communication with cascading persistence (Transitive persistence)

cascade attribute to accept a value of CascadeType array, its type is as follows:

? CascadeType.PERSIST: cascades the persist (create) operation to associated entities persist () is called or if the entity is managed, if an entity is subject to state control, or when persist () function is called, triggers the cascade to create (create ) operation.

? CascadeType.MERGE: cascades the merge operation to associated entities if merge () is called or if the entity is managed, if an entity is subject to state control, or when the merge () function is called, triggers the cascade merge (merge) operation .

? CascadeType.REMOVE: cascades the remove operation to associated entities if delete () is called when the delete () function is called, triggers the cascade delete (remove) operation.

? CascadeType.REFRESH: cascades the refresh operation to associated entities if refresh () is called when the refresh () function is called, starting cascading update (refresh) operation.

? CascadeType.ALL: all of the above All of the above

Secondary list map

Using class-level annotation @ SecondaryTable and @ SecondaryTables can achieve a single entity to multiple tables mapping. Using the @ Column or @ JoinColumn annotation parameters can be specified in the table a column belongs to a specific table.

@ Entity
@ Table (name = "MainCat")
@ SecondaryTables ((
@ SecondaryTable (name = "Cat1", pkJoinColumns = (
@ PrimaryKeyJoinColumn (name = "cat_id", referencedColumnName = "id ")}),
@ SecondaryTable (name = "Cat2", uniqueConstraints = (
@ UniqueConstraint (columnNames = ("storyPart2 "})})
))
public class Cat implements Serializable (
private Integer id;
private String name;

private String storyPart1;
private String storyPart2;
@ Id @ GeneratedValue
public Integer getId () (
return id;
)
public String getName () (
return name;
)
@ Column (table = "Cat1")
public String getStoryPart1 () (
return storyPart1;
)
@ Column (table = "Cat2")
public String getStoryPart2 () (
return storyPart2;
)

In the above example, name stored in MainCat table, storyPart1 stored in Cat1 table, storyPart2 stored in Cat2 table. Cat1 table by foreign key cat_id and MainCat table associated, Cat2 table id column and MainCat table by association. Listed on the storyPart2 unique constraint is also defined.

Map query

Annotation can be mapped using EJBQL / HQL query, @ NamedQuery and @ NamedQueries class level can be used in the XML file or JPA annotations.

<entity-mappings>
<named-query name="plane.getAll">
<query> select p from Plane p </ query>
</ Named-query>
...
</ Entity-mappings>
...
@ Entity
@ NamedQuery (name = "night.moreRecentThan", query = "select n from Night n where n.date> =: date")
public class Night (
...
)
public class MyDao (
doStuff () (
Query q = s.getNamedQuery ("night.moreRecentThan");
q.setDate ("date", aMonthAgo);
List results = q.list ();
...
)
...
)

Can define an array of hints QueryHint provide some hint for the query attribute information. The figure is the number of Hibernate hints:

Mapping native query

By @ SqlResultSetMapping annotation to describe SQL resultset structure. If the definition of multiple result sets map, then use @ SqlResultSetMappings.

@ NamedNativeQuery (name = "night & area", query = "select night.id nid, night.night_duration,"
+ "Night.night_date, area.id aid, night.area_id, area.name"
+ "From Night night, Area area where night.area_id = area.id", resultSetMapping = "joinMapping")

@ SqlResultSetMapping (name = "joinMapping", entities = (
@ EntityResult (entityClass = org.hibernate.test.annotations.query.Night.class, fields = (
@ FieldResult (name = "id", column = "nid"),
@ FieldResult (name = "duration", column = "night_duration"),
@ FieldResult (name = "date", column = "night_date"),
@ FieldResult (name = "area", column = "area_id"),
discriminatorColumn = "disc"
))

@ EntityResult (entityClass = org.hibernate.test.annotations.query.Area.class, fields = (
@ FieldResult (name = "id", column = "aid"),
@ FieldResult (name = "name", column = "name")
))
)
)

The above example, called "night & area" of the query and "joinMapping" corresponds to the result set mapping, the mapping returns 2 entities, respectively Night and Area, in which each attribute associated with a column, the column names by querying for.

@ Entity
@ SqlResultSetMapping (name = "implicit",
entities = @ EntityResult (
entityClass = org.hibernate.test.annotations. @ NamedNativeQuery (
name = "implicitSample", query = "select * from SpaceShip",
resultSetMapping = "implicit")
public class SpaceShip (
private String name;
private String model;
private double speed;
@ Id
public String getName () (
return name;
)
public void setName (String name) (
this.name = name;
)
@ Column (name = "model_txt")
public String getModel () (
return model;
)
public void setModel (String model) (
this.model = model;
)
public double getSpeed () (
return speed;
)
public void setSpeed (double speed) (
this.speed = speed;
)
)

The example model1 property is bound to model_txt out, if and related entities associated with the design to a composite primary key, you should use the @ FieldResult annotations to define foreign key column for each. @ FieldResult name consists of: the definition of the relationship property name + "." + Primary key name or primary key columns or primary key attribute.

@ Entity
@ SqlResultSetMapping (name = "compositekey",
entities = @ EntityResult (entityClass = org.hibernate.test.annotations.query.SpaceShip.class,
fields = (
@ FieldResult (name = "name", column = "name"),
@ FieldResult (name = "model", column = "model"),
@ FieldResult (name = "speed", column = "speed"),
@ FieldResult (name = "captain.firstname", column = "firstn"),
@ FieldResult (name = "captain.lastname", column = "lastn"),
@ FieldResult (name = "dimensions.length", column = "length"),
@ FieldResult (name = "dimensions.width", column = "width")
))
columns = (@ ColumnResult (name = "surface"),

@ ColumnResult (name = "volume")))
@ NamedNativeQuery (name = "compositekey",
query = "select name, model, speed, lname as lastn, fname as firstn, length, width, length * width as resultSetMapping =" compositekey ")
))

If the query returns a single entity, or intends to use the system default mapping, in which case you can not use resultSetMapping, use resultClass property, for example:

@ NamedNativeQuery (name = "implicitSample", query = "select * from SpaceShip",
resultClass = SpaceShip.class)
public class SpaceShip (

Hibernate Annotations unique extension

Hibernate provides a feature to coincide with its own annotations, org.hibernate.annotations package contains the annotations.

Entity

org.hibernate.annotations.Entity defines the Hibernate entity needed information.

? Mutable: whether this entity is mutable or not this entity is variable

? DynamicInsert: allow dynamic SQL for inserts with dynamic SQL Added

? DynamicUpdate: allow dynamic SQL for updates using dynamic SQL update

? SelectBeforeUpdate: Specifies that Hibernate should never perform an SQL UPDATE unless it is certain that an object is actually modified. Hibernate never specified to run SQL Update, unless it can determine the object has been modified

? Polymorphism: whether the entity polymorphism is of PolymorphismType.IMPLICIT (default) or PolymorphismType.EXPLICIT that entity polymorphism is PolymorphismType.IMPLICIT (default) or PolymorphismType.EXPLICIT

? OptimisticLock: optimistic locking strategy (OptimisticLockType.VERSION, OptimisticLockType.NONE, OptimisticLockType.DIRTY or OptimisticLockType.ALL) optimistic locking strategy

Identifier

@ Org.hibernate.annotations.GenericGenerator and hibernate @ org.hibernate.annotations.GenericGenerators allows you to define the unique identifier.

@ Id @ GeneratedValue (generator = "system-uuid")
@ GenericGenerator (name = "system-uuid", strategy = "uuid")
public String getId () (
@ Id @ GeneratedValue (generator = "hibseq")
@ GenericGenerator (name = "hibseq", strategy = "seqhilo",
parameters = (
@ Parameter (name = "max_lo", value = "5"),
@ Parameter (name = "sequence", value = "heybabyhey")
)
)
public Integer getId () (

New examples

@ GenericGenerators (
(
@ GenericGenerator (
name = "hibseq",
strategy = "seqhilo",
parameters = (
@ Parameter (name = "max_lo", value = "5"),
@ Parameter (name = "sequence", value = "heybabyhey")
)
),
@ GenericGenerator (...)
)
)

Nature ID

Identified with the annotation @ NaturalId

Formula

To the database rather than JVM calculated.

@ Formula ("obj_length * obj_height * obj_width")
public long getObjectVolume ()

Index

Through the column attribute (property) using @ Index annotation, you can specify a specific column index, columnNames attribute (attribute) will subsequently be ignored.

@ Column (secondaryTable = "Cat1")
@ Index (name = "story1index")
public String getStoryPart1 () (
return storyPart1;
)

Identifying symbol

@ Entity
@ DiscriminatorFormula ("case when forest_type is null then 0 else forest_type end")
public class Forest (...)

Filter query ...
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of hibernate annontaion learn more

  • Based on Spring's Hibernate Search full-text search function of sample

    Database: Oracle 9i JDBC Driver: OJDBC14 Development Environment: Eclipse-JEE Spring version: Spring 2.0.6 Hibernate version: Hibernate Core 3.2.5/Hibernate Annotation 3.3.0/Hibernate Validator 3.0.0/Hibernate Search 3.0.0 Beta4 / / jdbc.properties (JDBC

  • Hibernate Mapping Types

    Hibernate mapping types divided into two categories: built-in mapping types and mapping types of customers. Built-in mapping types is responsible for some common Java types are mapped to the corresponding SQL type; In addition, Hibernate also allows users

  • Hibernate configuration parameters hibernate.hbm2ddl.auto

    Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • WebQQ, ExtJs + Servlet + Hibernate + Spring implementation

    Code for the development of boredom when using ExtJs + Servlet + hibernate (Ant + xdoclet generate HBM files) + spring implementation, Pure whim, but implementation has been more than chat, group chat, what's not achieve, nor how to consider the perfo

  • Hibernate.cfg.xml configuration file (including the primary key generation strategy Introduction)

    Hibernate.cfg.xml configuration file: <? xml version = "1.0" encoding = "utf-8"?> <! DOCTYPE hibernate-configuration PUBLIC "- / / Hibernate / Hibernate Configuration DTD / / EN" "hibernate-configuration-2.0.dtd

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Hibernate annotation using notebook

    These are the basic common @Entity --Declared an entity bean @Table(name="promotion_info") --For the entity bean mapping for the specified table (Table name ="promotion_info) @Id --Declare that the identifying attribute of the entity bean @GeneratedValue

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries