Annotations in - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Annotations in

Description:

Hibernate Annotations offers JDK 5.0 code annotations as a replacement or in ... JPA is a POJO API for object/relational mapping that supports the use both of ... – PowerPoint PPT presentation

Number of Views:318
Avg rating:3.0/5.0
Slides: 13
Provided by: AnaT99
Category:
Tags: annotations | pojo

less

Transcript and Presenter's Notes

Title: Annotations in


1
Annotations in
2
Remember the Structure
3
Hibernate Model
  • Hibernate Core offers native APIs
    object/relational mapping with XML metadata
  • Hibernate Annotations offers JDK 5.0 code
    annotations as a replacement or in addition to
    XML metadata
  • Hibernate EntityManager involves standard JPA for
    Java SE and Java EE

4
JPA (Java Persistent API)
  • JPA is a part of EJB 3.0 specification
  • JPA is a POJO API for object/relational mapping
    that supports the use both of Java metadata
    annotations and/or XML metadata

5
What is Annotation ?
  • Annotation is a specific construction in java 5
    for adding additional information to Java source
    code
  • Annotations are embedded in class files generated
    by compiler can be used by other frameworks

6
Annotation Using Syntax
  • _at_AnnotationName (element1 value1, element2
    value2)
  • _at_AnnotationName (value)

7
Can be used for
  • classes
  • methods
  • variables
  • parameters
  • packages
  • annotations

8
Hibernate Annotations
  • Basic annotations that implement the JPA standard
  • Hibernate extension annotations

9
Annotated Java class
  • _at_Entity
    // Declares
    this an entity bean
  • _at_Table(name "people")
    // Maps the bean to SQL
    table "people"
  • class Person implements Serializable
  • _at_Id
    // Map
    this to the primary key column.
  • _at_GeneratedValue(strategy GenerationType.AUTO)
    // Database will generate new primary keys
  • private Integer id
  • _at_Column(length 32)
    // Truncate column
    values to 32 characters.
  • private String name
  • public Integer getId()
  • return id
  • public void setId(Integer id)
  • this.id id

10
Basic Annotations
  • _at_Entity
  • _at_Id
  • _at_EmbeddedId
  • _at_GeneratedValue
  • _at_Table
  • _at_Column
  • _at_OneToOne
  • _at_ManyToOne
  • _at_OneToMany
  • Declares this an entity bean
  • Identity
  • Database Schema Attributes
  • Relationship mappings
  • etc.

11
Extension Annotations
  • Contained in org.hibernate.annotations package
  • Examples
  • _at_org.hibernate.annotations.Entity
  • _at_org.hibernate.annotations.Table
  • _at_BatchSize
  • _at_Where
  • _at_Check
  • .etc

12
hibernate.cfg.xml
  • lthibernate-configurationgt
  • ltsession-factorygt
  • ltproperty name"hibernate.connection.driver_cl
    ass"gtorg.hsqldb.jdbcDriverlt/propertygt
  • ltproperty name"hibernate.connection.url"gtjdbc
    hsqldbhsql//localhost/
  • lt/propertygt
  • ltproperty name"hibernate.connection.username"
    gtsalt/propertygt
  • ltproperty name"dialect"gtorg.hibernate.dialect
    .HSQLDialectlt/propertygt
  • ltmapping class"hello.Person"/gt
    -------- !!! ----------
  • lt/session-factorygt
  • lt/hibernate-configurationgt
Write a Comment
User Comments (0)
About PowerShow.com