Top Banner
36

HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Jun 03, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types
Page 2: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

HIBERNATE OGM

Page 3: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Hibernate OGM Architecture

Page 4: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Hibernate OGM Architecture

http://docs.jboss.org/hibernate/ogm/4.0/reference/en-US/html_single/

Page 5: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Data Persistence

Page 6: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

How is Data Persisted

•  Abstraction between the application object model and the persistent data model

•  Persist data as basic types •  Keep the notion of primary key to address an

entity •  Keep the notion of foreign key to link two

entities

Page 7: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

UserOne -userid -name -address

composition

Address -street -city -pin

Tbl_userone

•  userid_pk •  name •  street •  city •  pin

Page 8: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Key Value

{userid=1, Name=“Gerad”,

Tbl_userone,userid,1 address.street=“18th main”, address.city=“Bangalore”, Address.pin= 5760041 }

Key identifying an entity instance is composed of: •  the table name •  the primary key column name •  the primary key value

Page 9: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

UserOne -userid -name -address

N N

Address -addid -street -city -pin

tbl_user

-userid_pk -name

tbl_user_address

-userid_fk -addid_fk

tbl_address

-adddid_pk -street -city -pin

Page 10: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Key for association data is composed of: •  the table name •  the column name representing the foreign

key to the entity we come from •  the column value representing the foreign

key to the entity we come from

Page 11: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Key Value tbl_userone,userid_pk,1

{userid_pk=1,name=“Gerad”}

tbl_userone,userid_pk,2

{userid_pk=2,name=“Samuel”}

tbl_address,addid_pk,11 {addid_pk=11,street=“18th main”}

tbl_address,addid_pk,12

{addid_pk=12,street=“20th main”}

tbl_userone_address,userid_fk,1 {{userid_fk=1,addid_fk=11}, {userid_fk=1,addid_fk=12}}

tbl_userone_address,userid_fk,2

{{userid_fk=2,addid_fk=13}, {userid_fk=3,addid_fk=14}}

tbl_userone_address,addid_fk,11

{{userid_fk=1,addid_fk=11}, {userid_fk=4,addid_fk=11}}

tbl_userone_address,addid_fk,12

{{userid_fk=1,addid_fk=12}, {userid_fk=5,addid_fk=12}}

Page 12: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Querying Data

Page 13: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

http://docs.jboss.org/hibernate/ogm/4.0/reference/en-US/html_single/

Page 14: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Hibernate OGM Configuration

Page 15: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Persistence.xml <?xml version="1.0"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/ xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name=“HibOGMPU" transaction-type="JTA"> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> <properties> <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" /> <property name="hibernate.ogm.datastore.provider" value=“mongo" /> </properties> </persistence-unit> </persistence>

Page 16: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

MongoDB Installation and Configuration

Page 17: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

MongoDB Installation •  Download the open source mongodb from

http://www.mongodb.org/downloads (version 2.0.4) and unzip in a directory

•  Create Directory c:\data\db for data files (or specify alternate path using - - dbpath argument)

•  Starting MongoDB from the Command Prompt •  From the unzipped directory – go to bin •  Execute mongod.exe

(or) mongod --dbpath D:\data\db (since the default C:\data\db is changed to D:\data\db – it has to

be specified explicitly)

Page 18: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

MongoDB Installation a. http://localhost:28017/ - to check if it is working as in the next slide b. Press <Ctrl –c> on the shell running the server, to stop the service c. Open another command prompt à go to bin directory à execute mongo.exe (mongodb JavaScript shell)

Page 19: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Hibernate OGM Configuration For MongoDB

Page 20: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Hibernate OGM –MongoDB

hibernate.ogm.datastore.provider mongodb hibernate.ogm.mongodb.host default value is 127.0.0.1 hibernate.ogm.mongodb.port default value is 27017 hibernate.ogm.mongodb.database no default value hibernate.ogm.mongodb.username Mongo username hibernate.ogm.mongodb.password Mongo password hibernate.ogm.mongodb.safe default value is true. hibernate.ogm.mongodb.connection_timeout

expressed in milliseconds. The default value is 5000.

hibernate.ogm.mongodb.associations.store

GLOBAL_COLLECTION/ COLLECTION/ IN_ENTITY

Page 21: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Entity Classes

Page 22: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Entity class @Entity public class UserOne { @Id private String userid; private String name; @Column(name="desc") private String description; //getters, setters ... }

Page 23: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Mongo JSON Document : { "_id" : "5678-9999-0123-8553", “name": “Gerad", "desc": “Male aged 32", }

Page 24: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Primary Keys and Identifiers

Page 25: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Composite Primary Key @Entity public class Employee { @EmbeddedId private IDClass id; //getters, setters ... } @Embeddable public class IDClass implements Serializable { private String empid; private String deptid; //getters, setters ... }

Page 26: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

JSON Representation { "_id" :{ “empid": “11234", “deptid": “777" } }

Page 27: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Association Strategies

Page 28: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Association Strategies •  IN_ENTITY (default) •  GLOBAL_COLLECTION •  COLLECTION

Page 29: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Association Relationship Between Entities

Page 30: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Generators and DataTypes JPA id generators are supported: •  IDENTITY •  SEQUENCE •  TABLE •  AUTO Java Types Supported: •  Boolean •  Byte •  Calendar (this may change) •  Class (this may change)

Page 31: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Generators and DataTypes Java Types Supported: •  Date (this may change) •  Double •  Integer •  Long •  Byte Array •  String Types Maapped as String: •  BigDecimal •  BigInteger •  Url •  UUID

Page 32: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Supported Associations •  @OneToOne •  @OneToMany •  @ManyToOne •  @ManyToMany

Page 33: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Querying MongoDB

Page 34: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Query Support •  Hibernate Search FullTextQueries

•  Native query technology of MongoDB.

•  While using JPQL : –  Limitations are:

•  No join, aggregation, or other relational operations •  Use Hibernate Session API •  The entities and properties are indexed by Hibernate Search

•  Criteria API not implemented yet

Page 35: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Q&A

Page 36: HIBERNATE OGM - JBoss · How is Data Persisted • Abstraction between the application object model and the persistent data model • Persist data as basic types

Thank you