SlideShare a Scribd company logo
1 of 47
AD106 Don't fall asleep using Relational 
Databases: Using Hibernate with XPages 
Toby Samples, PSC Group, Consultant 
MWLUG 2014
About Toby 
Over 10 years as a Web Developer using various technologies 
ASP.net 
J2EE 
PHP 
XPages 
Consultant at PSC Group LLC 
• XPages® Developer 
• Contact Information 
• Blog: http://www.tobysamples.com 
• Email: tsamples@psclistens.com 
• Twitter: @tsamples 
• Skype: toby.samples23 
www.psclistens.com @pscgroup
• Agenda 
– Pre-requisites 
– Intro to RDBMS 
– Intro to Hibernate 
– Download and Install + adding to DDE 
– Create Hibernate Configuration 
– Run Code Generation 
– Copy Java files to DDE 
– Util code for Hibernate 
– CRUD Code 
– XPages Code 
– Questions
• Pre-requisite knowledge 
– Understand How to write an Xpage application 
– How to add a Jar/Java Library to an Xpages application 
• Build Path Configuration 
– Some knowledge of How to use Java in XPages 
– Where to find errors from Java code in XPages
• Oh no, I have to use Relational Databases
• Using the Domino API vs RDBMS 
– We’ve been lucky (More code to doing Relational Database 
persistence) 
– Pros to using RDBMS 
• Tools – Lots of them 
• Vendors – Varied with many strengths and niches 
• Scales (Size Limit) 
• Transactional 
• Truly relational, can have constraints and triggers 
– Hibernate has a strong connection to the Domino API
• RDBMS - Another tool in the toolbox 
– Not your enemy 
– Relational Databases are everywhere 
– You probably already have some in your environment 
– Even if you use an RDBMS as your data store you can still leverage 
all the other pieces of Domino in your XPages app 
• Security 
• NAB 
• XPages Knowledge (XSP, Dojo, Java, ssjs) already baked in.
• History of Connecting to Relational 
Databases in Java 
– JDBC 
– J2EE JRE 1.2 released in 1999
• DAO Design Pattern 
– Became a defacto standard and is still in use today. 
– Requires lot of code to be hand written 
– Builds on JDBC API to create an easier way to persist data.
• JPA 1.0 
– Released in JRE 1.5 2006 
– JSR 220 Expert Group 
– Eclipselink became the reference implementation
• Why use an Object Relational mapping 
– Relational Database are table-driven, with rows and columns, they 
are designed for fast queries 
– In Java we are used to working with Objects that have properties 
with getters and setters. 
– If you don’t use an ORM you have to do this mapping yourself from 
the standard JDBC Connection after you run a SQL Query 
– With an ORM the developer gets to focus on Java 
– ORM Solutions are mature
• Hibernate 
– Created in 2001 as a way to put more of an abstraction layer 
between applications and Databases. 
– Jboss hired the developers and started investing in Hibernate in 
2005 
– OpenSource with an LGPL license 
– Originally used XML Mapping files 
– After JDK 5 was released 
implemented Annotations
• What is Hibernate 
– Object/Relational Mapping 
• JPA Provider 
• Entities 
• JPQL 
Hibernate Tools 
Mapping Editor 
Reverse Engineering 
Other Hibernate Modules 
Hibernate Search 
Hibernate Validator 
Hibernate OGM (NoSQL)
• Why use Hibernate 
– Performance 
• High Performance Object Caching 
• Configurable Strategies 
– Awesome Query abilities 
• Criteria API 
• Query By Example 
• HQL 
• Native SQL 
– Proven used all over the world in J2EE applications
• Why use Hibernate to connect to RDBMS? 
– There are other options 
• JDBC Connections 
• Extension Library Tooling 
Because you’re lazy  OK, you’re efficient! 
Automatic Caching 
Connection Pooling (C3P0 or DBCP) 
Hibernate’s tooling and code generation makes life so much easier when 
dealing with relational databases. 
Hibernate abstracts away database independence, (same code, no 
matter the vendor, just change the dialect) 
NO SQL NEEDED, no really.
• Hibernate Architecture
• Hibernate Architecture 
– The architecture abstracts 
away the underlying JDBC, 
JNDI, and JTA API’s, and lets 
the Hibernate engine take 
care of all of the plumbing
• Domain Classes 
– Domain Classes are Java Classes that implement the objects or 
“entities” that make up your business process and application 
• Invoice 
• PurchaseOrder 
• ShippingItem 
– These Objects are usually very simple and follow the rules to be 
POJOs
• Writing Domain Classes 
– Must have a no-argument constructor 
– Has to have an identifier property 
• It maps the primary key of the database table 
• Shows the mapping to the database table column 
• Has to show the type whether it’s a string, or integer, or Boolean, etc 
• Can have other options such as how the ID is generated 
– Declares getters and setters for fields that are to be persisted in the 
database
• Saving Objects 
– An Object is considered transient until it has been saved by the 
Hibernate Session, once it has been saved it is considered persistent 
and is tied to that instance of Hibernate Session 
– Once saved Objects get updated with their Object Identifier
• How to Save Objects 
– In the Session Interface or class 
– public Serializable save(Object object) 
• Saves the transient object 
• Assigns the Object Identifier to the object 
• Returns the Object Identifier
• Example of saving an Object 
Student student = new Student(); 
student.setFirstName(“Joe”); 
student.setLastName(“Smith”); 
student.setEmail(“joe.smith@mwlug.com”); 
Object id = session.save(student); 
Id now represents the object identifier for the persisted object
• Getting Objects 
– You can also use hibernate to pull a record out of the database into 
a persisted object. 
– Using get() vs load() 
• Get will return null if the unique id specified doesn’t exist 
• Load will throw an exception if the unique id doesn’t exist
• Get and Load examples 
Public Object get(Class clazz, Serializable identifier) 
Put in the type of object you want to return and the id and it will 
return that object from the database into your newly created persisted 
object.
• Getting an object example 
Student student = (Student)session.get(Student.class, id); 
If (student == null) { 
System.out.println(“Student does not exist with id “ + id); 
}
• Refreshing Objects 
– Refreshing persistent objects allows you to know that the data that 
is in the object is in sync with what is in the database. 
– If your database is used by more than just your Hibernate 
application it’s a good idea to use this functionality as you don’t 
know exactly when the database row may have been updated 
– However if that’s not the case this has a large performance cost 
because it makes another call to the SQL database
• Updating Objects 
– Hibernate automatically manages changes to the persistent objects 
• If a property changes on a persistent object, then it will be updated in 
the database once the object is commited 
– You can force Hibernate to commit all objects by calling the flush() 
method on the session object 
– You can also use the isDirty() method to determine the status of all 
of the persisted objects
• Deleting Objects 
– Used to delete objects from the Database table 
• Session.delete(Object) will delete the database record 
• Transactions are available to ensure that if there is an issue it will be 
rolled back.
• Querying Data 
– Hibernate returns data back in standard Java Data Collections such 
as Lists and Sets 
– There are several ways to query data 
• Criteria API 
• Query By Example 
• Hibernate Query Language 
• Native SQL
• Querying Data 
– All of these querying methods return back Persisted objects so it is 
easy to get a handle on a returned object change it and update the 
data in the database. 
– Example Query by Example 
public void testEquals() throws Exception { 
Session session = (Session) entityManager.getDelegate(); 
Address address = new Address(); 
address.setCountryISO2Code("US"); 
address.setCity("CHICAGO"); 
Example addressExample = Example.create(address); 
Criteria criteria = session.createCriteria(Address.class).add(addressExample); 
listAddresses(criteria.list());}
Hibernate Framework Classes
• Org.Hibernate.Session 
– Single Threaded 
– Short lived 
– Represents the conversation between the application and the 
database 
– Called a “persistence Context” 
• A Persistence Context is a container of objects that are being persisted 
– Handles CRUD for the database 
• Create 
• Read 
• Update 
• Delete 
– Also holds a factory for creating Transactions
• Org.hibernate.Transaction 
– Single threaded 
– Short lived 
– Specifies a very specific small unit of work on the database 
– Keeps us from having to deal with the JTA framework 
– Mandatory 
• Any and all database operations must be done within the context of a 
transaction 
– Commit and Rollback
Hibernate Configuration
• Hibernate Configuration 
– Hibernate Configuration File 
<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
<session-factory name="hibernateSessionFactory"> 
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
<property name="hibernate.connection.password">password</property> 
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property> 
<property name="hibernate.connection.username">root</property> 
<property name="hibernate.show_sql">true</property> 
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
<property name="hibernate.search.autoregister_listeners">false</property> 
<mapping class="com.mwlug.demo.hibernate.Notes" /> 
</session-factory> 
</hibernate-configuration>
• Object to Table Mapping 
– Mapping through Mapping XML Configuration Files 
• Add configuration of file in main hibernate configuration file 
– <mapping resource=“/Employee.mapping.xml” /> 
• Create Mapping File 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping package=“com.mwlug.demo.hibernate"> 
<class name="Employee" table="EMPLOYEE"> 
<id name="employeeId" column="EMPLOYEE_ID"> 
<generator class="native" /> 
</id> 
<one-to-one name="employeeDetail" 
class=“com.mwlug.demo.hibernate.EmployeeDetail" 
cascade="save-update"></one-to-one> 
<property name="firstname" /> 
<property name="lastname" column="lastname" /> 
<property name="birthDate" type="date" column="birth_date" /> 
<property name="cellphone" column="cell_phone" /> 
</class> 
</hibernate-mapping>
• Object to Table Mapping 
– Using Annotations to Map database tables to Classes 
– Add mapping to congiguration file 
• <mapping class="com.mwlug.demo.hibernate.Equipment" /> 
– Annotations within Code
• Object to Table Mapping
Download 
Java Library 
Hibernate.org 
Hibernate ORM 
Tools 
Eclipse.org/downloads 
Eclipse IDE for Java EE Developers 
Hibernate.org 
Hibernate Tools (Update Site for eclipse)
• Install 
– Installing Eclipse 
• After downloading unzip into folder and run eclipse.exe 
– No Install 
– Installing Hibernate Tools 
• Load up Eclipse 
– Help Menu /Install New Software 
» Create new Update site: 
http://download.jboss.org/jbosstools/updates/stable/kepler/ 
» Search for Hibernate Tools 
» Install and restart Eclipse
• Install 
– Adding Jar files to Domino Server 
• Unzip and Extract files from hibernate-release-4.3.6.Final.zip to its own 
folder 
• Take all of the jar files out of their respective folders and put into either 
an OSGI Plugin or <DominoProgramFolder>/jvm/lib/ext 
– This is both for ease of installation and for security 
• Restart Domino Server
• Demo
• Closing thoughts 
– RDBMS can be pretty quick to develop 
– Doesn’t have to be the entire app 
– Use tools that make your life easier as a developer 
• The Best Code is No Code At All 
– Let tried and true tools write code 
– Use libraries that have been time tested 
– Use datastores that work and have large user bases
• Yay I get to use Hibernate
• References 
– Hibernate.org 
• http://www.hibernate.org 
– JPA Documentation 
• http://docs.oracle.com/javaee/6/tutorial/doc/bnbpz.html
Questions

More Related Content

What's hot

The View - Leveraging Lotuscript for Database Connectivity
The View - Leveraging Lotuscript for Database ConnectivityThe View - Leveraging Lotuscript for Database Connectivity
The View - Leveraging Lotuscript for Database ConnectivityBill Buchan
 
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...Stephan H. Wissel
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSpeedment, Inc.
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisWill Iverson
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc driversmyrajendra
 
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Lee Klement
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1myrajendra
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesBrett Meyer
 
Transformations: Smart Application Migration to XPages
Transformations: Smart Application Migration to XPagesTransformations: Smart Application Migration to XPages
Transformations: Smart Application Migration to XPagesTeamstudio
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Big data: current technology scope.
Big data: current technology scope.Big data: current technology scope.
Big data: current technology scope.Roman Nikitchenko
 
Scala play-framework
Scala play-frameworkScala play-framework
Scala play-frameworkAbdhesh Kumar
 

What's hot (19)

The View - Leveraging Lotuscript for Database Connectivity
The View - Leveraging Lotuscript for Database ConnectivityThe View - Leveraging Lotuscript for Database Connectivity
The View - Leveraging Lotuscript for Database Connectivity
 
Dao example
Dao exampleDao example
Dao example
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
SHOW107: The DataSource Session: Take XPages data boldly where no XPages data...
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your database
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatis
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012
 
Hibernate performance tuning
Hibernate performance tuningHibernate performance tuning
Hibernate performance tuning
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance Techniques
 
Transformations: Smart Application Migration to XPages
Transformations: Smart Application Migration to XPagesTransformations: Smart Application Migration to XPages
Transformations: Smart Application Migration to XPages
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Big data: current technology scope.
Big data: current technology scope.Big data: current technology scope.
Big data: current technology scope.
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
 
Scala play-framework
Scala play-frameworkScala play-framework
Scala play-framework
 

Similar to Hibernate in XPages

hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfPatiento Del Mar
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesBrett Meyer
 
New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1Stefan Schmidt
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?DATAVERSITY
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jjJoe Jacob
 
Accesso ai dati con Azure Data Platform
Accesso ai dati con Azure Data PlatformAccesso ai dati con Azure Data Platform
Accesso ai dati con Azure Data PlatformLuca Di Fino
 
Building Deep Learning Workflows with DL4J
Building Deep Learning Workflows with DL4JBuilding Deep Learning Workflows with DL4J
Building Deep Learning Workflows with DL4JJosh Patterson
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoFu Cheng
 

Similar to Hibernate in XPages (20)

Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
 
Hibernate
HibernateHibernate
Hibernate
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
 
Where to save my data, for devs!
Where to save my data, for devs!Where to save my data, for devs!
Where to save my data, for devs!
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate
HibernateHibernate
Hibernate
 
New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1
 
Hadoop introduction
Hadoop introductionHadoop introduction
Hadoop introduction
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Persistence hibernate
Persistence hibernatePersistence hibernate
Persistence hibernate
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
 
CSharp
CSharpCSharp
CSharp
 
Accesso ai dati con Azure Data Platform
Accesso ai dati con Azure Data PlatformAccesso ai dati con Azure Data Platform
Accesso ai dati con Azure Data Platform
 
Building Deep Learning Workflows with DL4J
Building Deep Learning Workflows with DL4JBuilding Deep Learning Workflows with DL4J
Building Deep Learning Workflows with DL4J
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate
HibernateHibernate
Hibernate
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Hibernate in XPages

  • 1. AD106 Don't fall asleep using Relational Databases: Using Hibernate with XPages Toby Samples, PSC Group, Consultant MWLUG 2014
  • 2. About Toby Over 10 years as a Web Developer using various technologies ASP.net J2EE PHP XPages Consultant at PSC Group LLC • XPages® Developer • Contact Information • Blog: http://www.tobysamples.com • Email: tsamples@psclistens.com • Twitter: @tsamples • Skype: toby.samples23 www.psclistens.com @pscgroup
  • 3.
  • 4. • Agenda – Pre-requisites – Intro to RDBMS – Intro to Hibernate – Download and Install + adding to DDE – Create Hibernate Configuration – Run Code Generation – Copy Java files to DDE – Util code for Hibernate – CRUD Code – XPages Code – Questions
  • 5. • Pre-requisite knowledge – Understand How to write an Xpage application – How to add a Jar/Java Library to an Xpages application • Build Path Configuration – Some knowledge of How to use Java in XPages – Where to find errors from Java code in XPages
  • 6. • Oh no, I have to use Relational Databases
  • 7. • Using the Domino API vs RDBMS – We’ve been lucky (More code to doing Relational Database persistence) – Pros to using RDBMS • Tools – Lots of them • Vendors – Varied with many strengths and niches • Scales (Size Limit) • Transactional • Truly relational, can have constraints and triggers – Hibernate has a strong connection to the Domino API
  • 8. • RDBMS - Another tool in the toolbox – Not your enemy – Relational Databases are everywhere – You probably already have some in your environment – Even if you use an RDBMS as your data store you can still leverage all the other pieces of Domino in your XPages app • Security • NAB • XPages Knowledge (XSP, Dojo, Java, ssjs) already baked in.
  • 9. • History of Connecting to Relational Databases in Java – JDBC – J2EE JRE 1.2 released in 1999
  • 10. • DAO Design Pattern – Became a defacto standard and is still in use today. – Requires lot of code to be hand written – Builds on JDBC API to create an easier way to persist data.
  • 11. • JPA 1.0 – Released in JRE 1.5 2006 – JSR 220 Expert Group – Eclipselink became the reference implementation
  • 12. • Why use an Object Relational mapping – Relational Database are table-driven, with rows and columns, they are designed for fast queries – In Java we are used to working with Objects that have properties with getters and setters. – If you don’t use an ORM you have to do this mapping yourself from the standard JDBC Connection after you run a SQL Query – With an ORM the developer gets to focus on Java – ORM Solutions are mature
  • 13. • Hibernate – Created in 2001 as a way to put more of an abstraction layer between applications and Databases. – Jboss hired the developers and started investing in Hibernate in 2005 – OpenSource with an LGPL license – Originally used XML Mapping files – After JDK 5 was released implemented Annotations
  • 14. • What is Hibernate – Object/Relational Mapping • JPA Provider • Entities • JPQL Hibernate Tools Mapping Editor Reverse Engineering Other Hibernate Modules Hibernate Search Hibernate Validator Hibernate OGM (NoSQL)
  • 15. • Why use Hibernate – Performance • High Performance Object Caching • Configurable Strategies – Awesome Query abilities • Criteria API • Query By Example • HQL • Native SQL – Proven used all over the world in J2EE applications
  • 16. • Why use Hibernate to connect to RDBMS? – There are other options • JDBC Connections • Extension Library Tooling Because you’re lazy  OK, you’re efficient! Automatic Caching Connection Pooling (C3P0 or DBCP) Hibernate’s tooling and code generation makes life so much easier when dealing with relational databases. Hibernate abstracts away database independence, (same code, no matter the vendor, just change the dialect) NO SQL NEEDED, no really.
  • 18. • Hibernate Architecture – The architecture abstracts away the underlying JDBC, JNDI, and JTA API’s, and lets the Hibernate engine take care of all of the plumbing
  • 19. • Domain Classes – Domain Classes are Java Classes that implement the objects or “entities” that make up your business process and application • Invoice • PurchaseOrder • ShippingItem – These Objects are usually very simple and follow the rules to be POJOs
  • 20. • Writing Domain Classes – Must have a no-argument constructor – Has to have an identifier property • It maps the primary key of the database table • Shows the mapping to the database table column • Has to show the type whether it’s a string, or integer, or Boolean, etc • Can have other options such as how the ID is generated – Declares getters and setters for fields that are to be persisted in the database
  • 21. • Saving Objects – An Object is considered transient until it has been saved by the Hibernate Session, once it has been saved it is considered persistent and is tied to that instance of Hibernate Session – Once saved Objects get updated with their Object Identifier
  • 22. • How to Save Objects – In the Session Interface or class – public Serializable save(Object object) • Saves the transient object • Assigns the Object Identifier to the object • Returns the Object Identifier
  • 23. • Example of saving an Object Student student = new Student(); student.setFirstName(“Joe”); student.setLastName(“Smith”); student.setEmail(“joe.smith@mwlug.com”); Object id = session.save(student); Id now represents the object identifier for the persisted object
  • 24. • Getting Objects – You can also use hibernate to pull a record out of the database into a persisted object. – Using get() vs load() • Get will return null if the unique id specified doesn’t exist • Load will throw an exception if the unique id doesn’t exist
  • 25. • Get and Load examples Public Object get(Class clazz, Serializable identifier) Put in the type of object you want to return and the id and it will return that object from the database into your newly created persisted object.
  • 26. • Getting an object example Student student = (Student)session.get(Student.class, id); If (student == null) { System.out.println(“Student does not exist with id “ + id); }
  • 27. • Refreshing Objects – Refreshing persistent objects allows you to know that the data that is in the object is in sync with what is in the database. – If your database is used by more than just your Hibernate application it’s a good idea to use this functionality as you don’t know exactly when the database row may have been updated – However if that’s not the case this has a large performance cost because it makes another call to the SQL database
  • 28. • Updating Objects – Hibernate automatically manages changes to the persistent objects • If a property changes on a persistent object, then it will be updated in the database once the object is commited – You can force Hibernate to commit all objects by calling the flush() method on the session object – You can also use the isDirty() method to determine the status of all of the persisted objects
  • 29. • Deleting Objects – Used to delete objects from the Database table • Session.delete(Object) will delete the database record • Transactions are available to ensure that if there is an issue it will be rolled back.
  • 30. • Querying Data – Hibernate returns data back in standard Java Data Collections such as Lists and Sets – There are several ways to query data • Criteria API • Query By Example • Hibernate Query Language • Native SQL
  • 31. • Querying Data – All of these querying methods return back Persisted objects so it is easy to get a handle on a returned object change it and update the data in the database. – Example Query by Example public void testEquals() throws Exception { Session session = (Session) entityManager.getDelegate(); Address address = new Address(); address.setCountryISO2Code("US"); address.setCity("CHICAGO"); Example addressExample = Example.create(address); Criteria criteria = session.createCriteria(Address.class).add(addressExample); listAddresses(criteria.list());}
  • 33. • Org.Hibernate.Session – Single Threaded – Short lived – Represents the conversation between the application and the database – Called a “persistence Context” • A Persistence Context is a container of objects that are being persisted – Handles CRUD for the database • Create • Read • Update • Delete – Also holds a factory for creating Transactions
  • 34. • Org.hibernate.Transaction – Single threaded – Short lived – Specifies a very specific small unit of work on the database – Keeps us from having to deal with the JTA framework – Mandatory • Any and all database operations must be done within the context of a transaction – Commit and Rollback
  • 36. • Hibernate Configuration – Hibernate Configuration File <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory name="hibernateSessionFactory"> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">password</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.search.autoregister_listeners">false</property> <mapping class="com.mwlug.demo.hibernate.Notes" /> </session-factory> </hibernate-configuration>
  • 37. • Object to Table Mapping – Mapping through Mapping XML Configuration Files • Add configuration of file in main hibernate configuration file – <mapping resource=“/Employee.mapping.xml” /> • Create Mapping File <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package=“com.mwlug.demo.hibernate"> <class name="Employee" table="EMPLOYEE"> <id name="employeeId" column="EMPLOYEE_ID"> <generator class="native" /> </id> <one-to-one name="employeeDetail" class=“com.mwlug.demo.hibernate.EmployeeDetail" cascade="save-update"></one-to-one> <property name="firstname" /> <property name="lastname" column="lastname" /> <property name="birthDate" type="date" column="birth_date" /> <property name="cellphone" column="cell_phone" /> </class> </hibernate-mapping>
  • 38. • Object to Table Mapping – Using Annotations to Map database tables to Classes – Add mapping to congiguration file • <mapping class="com.mwlug.demo.hibernate.Equipment" /> – Annotations within Code
  • 39. • Object to Table Mapping
  • 40. Download Java Library Hibernate.org Hibernate ORM Tools Eclipse.org/downloads Eclipse IDE for Java EE Developers Hibernate.org Hibernate Tools (Update Site for eclipse)
  • 41. • Install – Installing Eclipse • After downloading unzip into folder and run eclipse.exe – No Install – Installing Hibernate Tools • Load up Eclipse – Help Menu /Install New Software » Create new Update site: http://download.jboss.org/jbosstools/updates/stable/kepler/ » Search for Hibernate Tools » Install and restart Eclipse
  • 42. • Install – Adding Jar files to Domino Server • Unzip and Extract files from hibernate-release-4.3.6.Final.zip to its own folder • Take all of the jar files out of their respective folders and put into either an OSGI Plugin or <DominoProgramFolder>/jvm/lib/ext – This is both for ease of installation and for security • Restart Domino Server
  • 44. • Closing thoughts – RDBMS can be pretty quick to develop – Doesn’t have to be the entire app – Use tools that make your life easier as a developer • The Best Code is No Code At All – Let tried and true tools write code – Use libraries that have been time tested – Use datastores that work and have large user bases
  • 45. • Yay I get to use Hibernate
  • 46. • References – Hibernate.org • http://www.hibernate.org – JPA Documentation • http://docs.oracle.com/javaee/6/tutorial/doc/bnbpz.html