Chapter 4. Collections and Associations
|
|
- William Boyd
- 5 years ago
- Views:
Transcription
1 Chapter 4. Collections and Associations Collections Associations 1 / 51
2 Java Variable and Collection class Person { Address address; class Address { Set<Person> persons = new HashSet<Person>; 2 / 51
3 Java Collections Java Collections Implementat ions Interfaces Hash Table Resizable Array Tree Linked List Hash Table + Linked List Set HashSet TreeSet LinkedHashSet List ArrayList LinkedList Queue Deque ArrayDeque LinkedList Map HashMap TreeMap LinkedHashMap 3 / 51
4 Association and Mapping Birectional Associations 4 / 51
5 Association and Mapping Birectional Many-to-One/One-to-Many Associations 1/3 Person * PersonAddress persons 1 address Address class Person { Address address; class Address { Set<Person> persons = new HashSet<Person>; create table Person ( personid bigint not null primary key, addressid bigint not null create table Address ( addressid bigint not null primary key 5 / 51
6 Association and Mapping Birectional Many-to-One/One-to-Many Associations 2/3 class Person { Address address; class Address { Set<Person> persons = new HashSet<Person>; create table Person ( personid bigint not null primary key generated by default as entity, addressid bigint not null create table Address ( addressid bigint not null primary key generated by default as entity <class name="person"> < name="" column="personid"> <generator class="native"/> </> <many-to-one name="address" class="address" column="addressid" not-null="true" /> </class> <class name="address"> < name="" column="addressid"> <generator class="native"/> </> <set name="persons" inverse="true"> <key column="addressid"/> <one-to-many class="person"/> </set> </class> 6 / 51
7 Association and Mapping (detail Birectional Many-to-One/One-to-Many Associations 3/3 class Person { Address address; class Address { Set<Person> persons = new HashSet<Person>; create table Person ( personid bigint not null primary key generated by default as entity, addressid bigint not null create table Address ( addressid bigint not null primary key generated by default as entity <class name="person"> < name="" column="personid"> <generator class="native"/> </> <many-to-one name="address" class="address" column="addressid" not-null="true" /> </class> <class name="address"> < name="" column="addressid"> <generator class="native"/> </> <set name="persons" inverse="true"> <key column="addressid"/> <one-to-many class="person"/> </set> </class> 7 / 51
8 Association and Mapping Birectional Many-to-Many Associations 1/2 Person * PersonAddress persons * addresses Address class Person { Set<Address> addresses = new HashSet<Address>; class Address { Set<Person> persons = new HashSet<Person>; create table Person ( personid bigint not null primary key, create table Address ( addressid bigint not null primary key create table PersonAddress ( personid bigint not null, addressid bigint not null, primary key (personid, addressid 8 / 51
9 Association and Mapping Birectional Many-to-Many Associations 2/2 class Person { Set<Address> addresses = new HashSet<Address>; class Address { Set<Person> persons = new HashSet<Person>; create table Person ( personid bigint not null primary key create table PersonAddress ( personid bigint not null, addressid bigint not null, primary key (personid, addressid create table Address ( addressid bigint not null primary key <class name="person"> < name="" column="personid"> <generator class="native"/> </> <set name="addresses" table="personaddress"> <key column="personid"/> <many-to-many class="address" column="addressid"/> </set> </class> <class name="address"> < name="" column="addressid"> <generator class="native"/> </> <set name="persons" table="personaddress" inverse="true"> <key column="addressid"/> <many-to-many class="person" column="personid"/> </set> </class> 9 / 51
10 Association and Mapping Birectional One-to-One Associations on a Foreign Key 1/2 Person 1 PersonAddress person 1 address Address class Person { Address address; class Address { Person person; create table Person ( personid bigint not null primary key, addressid bigint not null create table Address ( addressid bigint not null primary key 10 / 51
11 Association and Mapping Birectional One-to-One Associations on a Foreign Key 2/2 class Person { Address address; class Address { Person person; create table Person ( personid bigint not null primary key, addressid bigint not null create table Address ( addressid bigint not null primary key <class name="person"> < name="" column="personid"> <generator class="native"/> </> <many-to-one name="address" </class> class="address" column="addressid" unique="true" not-null="true" /> <class name="address"> < name="" column="addressid"> <generator class="native"/> </> <one-to-one name="person" </class> property-ref="address"/> property-ref (optional: the name of a property of the associated class that is joined to the primary key of this class 11 / 51 If not specified, the primary key of the associated class is used.
12 Association and Mapping Birectional One-to-One Associations on a Primary Key 1/2 Person 1 PersonAddress person 1 address Address class Person { Address address; class Address { Person person; create table Person ( personid bigint not null primary key, create table Address ( personid bigint not null primary key 12 / 51
13 Association and Mapping Birectional One-to-One Associations on a Primary Key 2/2 class Person { Address address; class Address { Person person; create table Person ( personid bigint not null primary key, create table Address ( personid bigint not null primary key <class name="person"> < name="" column="personid"> <generator class="native"/> </> <one-to-one name="address" cascade= all /> </class> <class name="address"> < name="" column="personid"> <generator class="foreign"> <param name="property">person</param> </generator> </> <one-to-one name="person" constrained="true"/> </class> constrained (optional: specifies that a foreign key constraint on the primary key of the mapped table and references the table of the associated class 13 / 51
14 Association and Mapping Unirectional Associations 14 / 51
15 Association and Mapping Unirectional Many-to-One Associations 1/2 Person * PersonAddress persons 1 address Address class Person { Address address; class Address { create table Person ( personid bigint not null primary key, addressid bigint not null create table Address ( addressid bigint not null primary key 15 / 51
16 Association and Mapping Unirectional Many-to-One Associations 2/2 class Person { Address address; class Address { create table Person ( personid bigint not null primary key, addressid bigint not null create table Address ( addressid bigint not null primary key <class name="person"> < name="" column="personid"> <generator class="native"/> </> <many-to-one name="address" column="addressid" not-null="true" /> </class> <class name="address"> < name="" column="addressid"> <generator class="native"/> </> </class> 16 / 51
17 Association and Mapping Unirectional One-to-Many Associations (unusual case 1/2 Person 1 PersonAddress * person addresses Address class Person { Set<Address> addresses; class Address { create table Person ( personid bigint not null primary key create table Address ( addressid bigint not null primary key, personid bigint not null 17 / 51
18 Association and Mapping Unirectional One-to-Many Associations (unusual case 2/2 class Person { Set<Address> addresses; class Address { create table Person ( personid bigint not null primary key create table Address ( addressid bigint not null primary key, personid bigint not null <class name="person"> < name="" column="personid"> <generator class="native"/> </> <set name="addresses"> <key column="personid" not-null="true"/> <one-to-many class="address"/> </set> </class> <class name="address"> < name="" column= addressid"> <generator class= native"> </> </class> 18 / 51
19 Association and Mapping Unirectional Many-to-Many Associations 1/2 Person * PersonAddress * persons addresses Address class Person { Set<Address> addresses = new HashSet<Address>; class Address { create table Person ( personid bigint not null primary key, create table Address ( addressid bigint not null primary key create table PersonAddress ( personid bigint not null, addressid bigint not null, primary key (personid, addressid 19 / 51
20 Association and Mapping Unirectional Many-to-Many Associations 2/2 class Person { Set<Address> addresses = new HashSet<Address>; create table Person ( personid bigint not null primary key, class Address { create table Address ( addressid bigint not null primary key create table PersonAddress ( personid bigint not null, addressid bigint not null, primary key (personid, addressid <class name="person"> < name="" column="personid"> <generator class="native"/> </> <set name="addresses" table="personaddress"> <key column="personid"/> <many-to-many class="address" column="addressid" /> </set> </class> <class name="address"> < name="" column= addressid"> <generator class= native"> </> </class> 20 / 51
21 Association and Mapping Unirectional One-to-One Associations on a Foreign Key 1/2 Person 1 PersonAddress person 1 address Address class Person { Address address; class Address { create table Person ( personid bigint not null primary key, addressid bigint not null create table Address ( addressid bigint not null primary key 21 / 51
22 Association and Mapping Unirectional One-to-One Associations on a Foreign Key 2/2 class Person { Address address; class Address { create table Person ( personid bigint not null primary key, addressid bigint not null create table Address ( addressid bigint not null primary key <class name="person"> < name="" column="personid"> <generator class="native"/> </> <many-to-one name="address" class="address" column="addressid" unique="true" not-null="true" /> </class> <class name="address"> < name="" column="addressid"> <generator class="native"/> </> </class> 22 / 51
23 Association and Mapping Unirectional One-to-One Associations on a Primary Key 1/2 Person 1 PersonAddress person 1 address Address class Person { class Address { Person person; create table Person ( personid bigint not null primary key, create table Address ( personid bigint not null primary key 23 / 51
24 Association and Mapping Unirectional One-to-One Associations on a Primary Key 2/2 class Person { class Address { Person person; create table Person ( personid bigint not null primary key, create table Address ( personid bigint not null primary key <class name="address"> <class name="person"> < name="" column="personid"> <generator class= native /> </> </class> < name="" column="personid"> <generator class= foreign > <param name= property >person</param> </generator> </> <one-to-one name= person" constrained= true /> </class> 24 / 51
25 Association and Mapping Exercise hibernate-369-mkyong-win 01-stock-quickstart-xml 03-stock-onetomany-xml 05-stock-manytomany-xml 08-stock-onetoone-xml 25 / 51
26 Exercise #4: Generate hbm.xml of Employee and Company ex04/src/main/java/com/oreilly/hh/data/employee.hbm.xml: <hibernate-mapping> <class name="com.oreilly.hh.data.employee" > < name="" > </> </class> </hibernate-mapping> ex04/src/main/java/com/oreilly/hh/data/company.hbm.xml: <hibernate-mapping> <class name="com.oreilly.hh.data.company" > < name="" > </> </class> </hibernate-mapping> 26 / 51
27 Exercise #4: test $ gradle test :ex04:test Results: SUCCESS (3 tests, 3 successes, 0 failures, 0 skipped BUILD SUCCESSFUL 27 / 51
28 Java Collections vs Database Relationships Birectional Many-to-Many Associations Track UML name Artist 0..* artists track_artists 0..* tracks title filepath playtime added volume Java class Artist { Integer ; String name; Set<Track> tracks; class Track { Integer ; String title; String filepath; time playtime; date added; short volume; Set<Artist> artists; 28 / 51
29 Java Collections vs Database Relationships Unirectional Many-to-Many Associations Track UML name Artist track_artists 0..* tracks title filepath playtime added volume Java class Artist { Integer ; String name; Set<Track> tracks; class Track { Integer ; String title; String filepath; time playtime; date added; short volume; 29 / 51
30 Java Collections vs Database Relationships Many-to-Many Associations and Database Relationships Track UML name Artist 0..* artists track_artists 0..* tracks title filepath playtime added volume Table create table ARTIST ( integer primary key, name varchar(62 create table TRACK_ARTISTS ( artist_ integer, track_ integer, foreign key (artist_ references artist(, foreign key (track_ references track( create table TRACK ( integer primary key, title varchar(62, filepath varchar(62, playtime time, added date, volume smallint 30 / 51
31 Mapping Collections (for Birectional Many-to-Many Association name Artist 0..* artists track_artists 0..* tracks Track title filepath playtime added volume <set name="tracks" table="track_artists" inverse="true"> <key column="artist_id /> <many-to-many class="com.oreilly.hh.data.track" column="track_id"/> </set> <set name="artists" table="track_artists"> <key column="track_id"/> <many-to-many class="com.oreilly.hh.data.artist" column="artist_id"/> </set> 31 / 51
32 Mapping Collections (for Unirectional Many-to-Many Association name Artist track_artists 0..* tracks Track title filepath playtime added volume <set name="tracks" table="track_artists"> <key column="artist_id /> <many-to-many class="com.oreilly.hh.data.track" column="track_id"/> </set> 32 / 51
33 Mapping Collections (Artist.hbm.xml <?xml version="1.0 encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC...> <hibernate-mapping> <class name="com.oreilly.hh.data.artist" table="artist"> <meta attribute="class-description">... </meta> < name="" type="int" column="artist_id"> <generator class="native"/> </> <property name="name" type="string"> <column name="name" not-null="true" unique="true" index="artist_name"/> </property> <set name="tracks" table="track_artists" inverse="true"> <key column="artist_id"/> <many-to-many class="com.oreilly.hh.data.track" column="track_id"/> </set> </class> </hibernate-mapping> 33 / 51
34 Mapping Collections (Track.hbm.xml <?xml version="1.0 encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC...> <hibernate-mapping> <class name="com.oreilly.hh.data.track" table="track">... <set name="artists" table="track_artists"> <key column="track_id"/> <many-to-many class="com.oreilly.hh.data.artist" column="artist_id"/> </set>... </class> </hibernate-mapping> 34 / 51
35 Mapping Collections (hibernate.cfg.xml hibernate.cfg.xml : <?xml version="1.0 encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC...> <hibernate-configuration> <session-factory>... <mapping resource="com/oreilly/hh/data/track.hbm.xml"/> <mapping resource="com/oreilly/hh/data/artist.hbm.xml"/> </session-factory> </hibernate-configuration> 35 / 51
36 Persisting Collections (CreateTest.java public class CreateTest { public static Artist getartist(string name, boolean create, Session session { Query query = session.getnamedquery("com.oreilly.hh.artistbyname"; query.setstring("name", name; Artist found = (Artistquery.uniqueResult(; if (found == null && create { found = new Artist(name, new HashSet<Track>(; session.save(found; return found; /** * Utility method to associate an artist with a track */ private static vo addtrackartist(track track, Artist artist { track.getartists(.add(artist; / 51
37 Persisting Collections (Artist.hbm.xml Artist.hbm.xml :... <query name="com.oreilly.hh.artistbyname"> <![CDATA[ from Artist as artist where upper(artist.name = upper(:name ]]> </query>... Track.hbm.xml :... <query name="com.oreilly.hh.tracksnolongerthan"> <![CDATA[ from Track as track where track.playtime <= :length ]]> </query> / 51
38 Persisting Collections (CreateTest.java... public static vo main(string args[] throws Exception {... try { // Create some data and persist it tx = session.begintransaction(; Track track = new Track("Russian Trance", "vol2/album610/track02.mp3", Time.valueOf("00:03:30", new HashSet<Artist>(, new Date(, (short0; addtrackartist(track, getartist("ppk", true, session; session.save(track; track = new Track("Veo Killed the Radio Star", "vol2/album611/track12.mp3", Time.valueOf("00:03:49", new HashSet<Artist>(, new Date(, (short0; addtrackartist(track, getartist("the Buggles", true, session; session.save(track; track = new Track("Gravity's Angel", "vol2/album175/track03.mp3", Time.valueOf("00:06:06", new HashSet<Artist>(, new Date(, (short0; addtrackartist(track, getartist("laurie Anderson", true, session; session.save(track; 38 / 51
39 Persisting Collections (CreateTest.java... track = new Track("Adagio for Strings (Ferry Corsten Remix", "vol2/album972/track01.mp3", Time.valueOf("00:06:35", new HashSet<Artist>(, new Date(, (short0; addtrackartist(track, getartist("william Orbit", true, session; addtrackartist(track, getartist("ferry Corsten", true, session; addtrackartist(track, getartist("samuel Barber", true, session; session.save(track; track = new Track("Adagio for Strings (ATB Remix", "vol2/album972/track02.mp3", Time.valueOf("00:07:39", new HashSet<Artist>(, new Date(, (short0; addtrackartist(track, getartist("william Orbit", true, session; addtrackartist(track, getartist("atb", true, session; addtrackartist(track, getartist("samuel Barber", true, session; session.save(track; track = new Track("The World '99", "vol2/singles/pvw99.mp3", Time.valueOf("00:07:05", new HashSet<Artist>(, new Date(, (short0; addtrackartist(track, getartist("pulp Victim", true, session; addtrackartist(track, getartist("ferry Corsten", true, session; session.save(track; track = new Track("Test Tone 1", "vol2/singles/test01.mp3", session.save(track;... Time.valueOf("00:00:10", new HashSet<Artist>(, new Date(, (short0; 39 / 51
40 Persisting Collections : What just happened? $ gradle ctest $ gradle db 40 / 51
41 Retrieving Collections (QueryTest.java package com.oreilly.hh;... public class QueryTest {... public static String listartistnames(set<artist> artists { StringBuilder result = new StringBuilder(; for (Artist artist : artists { result.append((result.length( == 0? "(" : ", "; result.append(artist.getname(; if (result.length( > 0 { result.append(" "; return result.tostring(; / 51
42 Retrieving Collections (QueryTest.java public class QueryTest {... public static String listartistnames(set<artist> artists {... public static vo main(string args[] throws Exception {... try { // Print the tracks that will fit in seven minutes List tracks = tracksnolongerthan(time.valueof("00:07:00", session;... for ( Track atrack : tracks { System.out.println("Track: \"" + atrack.gettitle( + "\" " + listartistnames(atrack.getartists( + atrack.getplaytime(; 42 / 51
43 Retrieving Collections (Hibernate.cfg.xml... <!-- Echo all executed SQL to stdout --> <property name="show_sql">false</property> / 51
44 Retrieving Collections : QueryTest Output $ gradle qtest :ch04:compilejava UP-TO-DATE :ch04:processresources UP-TO-DATE :ch04:classes UP-TO-DATE :ch04:qtest Track: "Russian Trance" (PPK 00:03:30 Track: "Veo Killed the Radio Star" (The Buggles 00:03:49 Track: "Gravity's Angel" (Laurie Anderson 00:06:06 Track: "Adagio for Strings (Ferry Corsten Remix" (Ferry Corsten, William Orbit, Samuel Ba rber 00:06:35 Track: "Test Tone 1" 00:00:10 Comment: Pink noise to test equalization BUILD SUCCESSFUL Total time: secs 44 / 51
45 Using Birectional Associations (QueryTest2.java // Example Source for QueryTest2.java public class QueryTest2 extends JPanel {... private vo updatetracks(string name { model.removeallelements(; // Clear out previous tracks if (name.length( < 1 return; // Nothing to do try { // Ask for a session using the JDBC information we've configured Session session = sessionfactory.opensession(; try { Artist artist = CreateTest.getArtist(name, false, session; if (artist == null { // Unknown artist model.addelement("artist not found"; return; // List the tracks associated with the artist for (Track atrack : artist.gettracks( { model.addelement("track: \"" + atrack.gettitle( + "\", " + atrack.getplaytime(; finally { session.close(; catch (Exception e { System.err.println("Problem updating tracks:" + e; e.printstacktrace(; 45 / 51
46 Using Birectional Associations (build.gradle... task qtest2(dependson: classes, type: JavaExec { main = 'com.oreilly.hh.querytest2' classpath = sourcesets.main.runtimeclasspath $ gradle qtest2 46 / 51
47 Working with Simpler Collections 47 / 51
48 Working with Simpler Collections Collections of associations to other objects collections of simple values, like strings, numbers, and nonpersistent value classes want to record some number of comments about each track in the database Track.hbm.xml... <set name="comments" table="track_comments"> <key column="track_id"/> <element column="comment" type="string"/> </set> gradle schema create table TRACK_COMMENTS (TRACK_ID integer not null, COMMENT varchar(255; alter table TRACK_COMMENTS add constraint FK105B26882DCBFAB5 foreign key (TRACK_ID references TRACK; 48 / 51
49 Working with Simpler Collections Add Comment Set at the end of each Constructor of CreateTest.java : track = new Track("Test Tone 1", "vol2/singles/test01.mp3", Time.valueOf("00:00:10", new HashSet<Artist>(, new Date(, (short0, new HashSet<String>(; Then assign a comment on the following line : track.getcomments(.add("pink noise to test equalization"; 49 / 51
50 Working with Simpler Collections Add another loop after the track println( in QueryTest.java to print the comments for the track : for (String comment : atrack.getcomments( { System.out.println(" Comment: " + comment; gradle qtest... Track: "Test Tone 1" 00:00:10 Comment: Pink noise to test equalization 50 / 51
51 Materials for Further Study Hibernate Home Hibernate Manual Hibernate Getting Started Gue Hibernate Reference Documentation Hibernate Reference Documentation 4.3 and 5.0 Hibernate Tutorial 51 / 51
Chapter 3. Harnessing Hibernate
Chapter 3. Harnessing Hibernate hibernate.cfg.xml session.save() session.createquery( from Track as track ) session.getnamedquery( tracksnolongerthan ); 1 / 20 Configuring Hibernate using XML (hibernate.cfg.xml)...
More informationChapter 6. Custom Value Types
Chapter 6. Custom Value Types User Type Composite User Type Custom Type Mapping 1 / 25 Defining a User Type Hibernate supports a wealth of Java types Simple Values integer, long, short, float, double,
More informationChapter 7. The Annotations Alternative
Chapter 7. The Annotations Alternative Hibernate Annotations 1 / 33 Hibernate Annotations Java Annotation is a way to add information about a piece of code (typically a class, field, or method to help
More informationChapter 2. Introduction to Mapping
Chapter 2. Introduction to Mapping 1 / 20 Class and Table Generation of Track TRACK id title filepath
More informationChapter 9. A Look at HQL
Chapter 9. A Look at HQL Writing HQL Queries Working with Aggregate Values Writing Native SQL Queries 1 / 18 Writing HQL Queries Minimal Valid HQL Queries from Example 9-1. The simplest HQL
More informationAdvanced Web Systems 9- Hibernate annotations, Spring integration, Aspect Oriented Programming. A. Venturini
Advanced Web Systems 9- Hibernate annotations, Spring integration, Aspect Oriented Programming A. Venturini Contents Hibernate Core Classes Hibernate and Annotations Data Access Layer with Spring Aspect
More informationChapter 13. Hibernate with Spring
Chapter 13. Hibernate with Spring What Is Spring? Writing a Data Access Object (DAO) Creating an Application Context Putting It All Together 1 / 24 What is Spring? The Spring Framework is an Inversion
More informationStep By Step Guideline for Building & Running HelloWorld Hibernate Application
Step By Step Guideline for Building & Running HelloWorld Hibernate Application 1 What we are going to build A simple Hibernate application persisting Person objects The database table, person, has the
More informationInstalling MySQL. Hibernate: Setup, Use, and Mapping file. Setup Hibernate in IDE. Starting WAMP server. phpmyadmin web console
Installing MySQL Hibernate: Setup, Use, and Mapping file B.Tech. (IT), Sem-6, Applied Design Patterns and Application Frameworks (ADPAF) Dharmsinh Desai University Prof. H B Prajapati Way 1 Install from
More informationHIBERNATE - ONE-TO-ONE MAPPINGS
HIBERNATE - ONE-TO-ONE MAPPINGS http://www.tutorialspoint.com/hibernate/hibernate_one_to_one_mapping.htm Copyright tutorialspoint.com A one-to-one association is similar to many-to-one association with
More informationHIBERNATE - MANY-TO-ONE MAPPINGS
HIBERNATE - MANY-TO-ONE MAPPINGS http://www.tutorialspoint.com/hibernate/hibernate_many_to_one_mapping.htm Copyright tutorialspoint.com A many-to-one association is the most common kind of association
More informationHIBERNATE - COMPONENT MAPPINGS
HIBERNATE - COMPONENT MAPPINGS http://www.tutorialspoint.com/hibernate/hibernate_component_mappings.htm Copyright tutorialspoint.com A Component mapping is a mapping for a class having a reference to another
More informationHIBERNATE - SORTEDSET MAPPINGS
HIBERNATE - SORTEDSET MAPPINGS http://www.tutorialspoint.com/hibernate/hibernate_sortedset_mapping.htm Copyright tutorialspoint.com A SortedSet is a java collection that does not contain any duplicate
More informationUnit 6 Hibernate. List the advantages of hibernate over JDBC
Q1. What is Hibernate? List the advantages of hibernate over JDBC. Ans. Hibernate is used convert object data in JAVA to relational database tables. It is an open source Object-Relational Mapping (ORM)
More informationJAVA SYLLABUS FOR 6 WEEKS
JAVA SYLLABUS FOR 6 WEEKS Java 6-Weeks INTRODUCTION TO JAVA History and Features of Java Comparison of C, C++, and Java Java Versions and its domain areas Life cycle of Java program Writing first Java
More informationJAVA. Duration: 2 Months
JAVA Introduction to JAVA History of Java Working of Java Features of Java Download and install JDK JDK tools- javac, java, appletviewer Set path and how to run Java Program in Command Prompt JVM Byte
More informationHIBERNATE - INTERCEPTORS
HIBERNATE - INTERCEPTORS http://www.tutorialspoint.com/hibernate/hibernate_interceptors.htm Copyright tutorialspoint.com As you have learnt that in Hibernate, an object will be created and persisted. Once
More informationJava Object/Relational Persistence with Hibernate. David Lucek 11 Jan 2005
Java Object/Relational Persistence with Hibernate David Lucek 11 Jan 2005 Object Relational Persistence Maps objects in your Model to a datastore, normally a relational database. Why? EJB Container Managed
More information1 st Step. Prepare the class to be persistent:
1 st Step Prepare the class to be persistent: Add a surrogate id field, usually int, long, Integer, Long. Encapsulate fields (properties) using exclusively getter and setter methods. Make the setter of
More informationLightweight J2EE Framework
Lightweight J2EE Framework Struts, spring, hibernate Software System Design Zhu Hongjun Session 4: Hibernate DAO Refresher in Enterprise Application Architectures Traditional Persistence and Hibernate
More informationCore Java Contents. Duration: 25 Hours (1 Month)
Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java
More informationJAVA. 1. Introduction to JAVA
JAVA 1. Introduction to JAVA History of Java Difference between Java and other programming languages. Features of Java Working of Java Language Fundamentals o Tokens o Identifiers o Literals o Keywords
More informationAdvanced Programming Languages Effective Java Item 1. Spring 2015 Chungnam National Univ Eun-Sun Cho
Advanced Programming Languages Effective Java Item 1 Spring 2015 Chungnam National Univ Eun-Sun Cho 1 1. Introduction 2. Creating and Destroying Objects Item 1: Consider static factory methods instead
More informationThe Object-Oriented Paradigm. Employee Application Object. The Reality of DBMS. Employee Database Table. From Database to Application.
The Object-Oriented Paradigm CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles The world consists of objects So we use object-oriented
More informationIntroduction to Relational Database Management Systems
Introduction to Relational Database Management Systems nikos bikakis bikakis@dblab.ntua.gr dblab NTU Athens Jan 2014 Outline RDBMS History Relational Model Overview RDBMS Overview Integrity Constraints
More informationComplete Java Contents
Complete Java Contents Duration: 60 Hours (2.5 Months) Core Java (Duration: 25 Hours (1 Month)) Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing
More informationTopic 10: The Java Collections Framework (and Iterators)
Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of
More informationJPA. Java persistence API
JPA Java persistence API JPA Entity classes JPA Entity classes are user defined classes whose instances can be stored in a database. JPA Persistable Types The term persistable types refers to data types
More informationPeers Techno log ies Pv t. L td. Core Java & Core Java &Adv Adv Java Java
Page 1 Peers Techno log ies Pv t. L td. Course Brochure Core Java & Core Java &Adv Adv Java Java Overview Core Java training course is intended for students without an extensive programming background.
More information5/23/2015. Core Java Syllabus. VikRam ShaRma
5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5
More informationIntroduction to Session beans. EJB - continued
Introduction to Session beans EJB - continued Local Interface /** * This is the HelloBean local interface. * * This interface is what local clients operate * on when they interact with EJB local objects.
More informationJAVA SYLLABUS FOR 6 MONTHS
JAVA SYLLABUS FOR 6 MONTHS Java 6-Months INTRODUCTION TO JAVA Features of Java Java Virtual Machine Comparison of C, C++, and Java Java Versions and its domain areas Life cycle of Java program Writing
More informationMappings and Queries. with. Hibernate
Mappings and Queries with Hibernate Mappings Collection mapping Mapping collection of values e.g. holidays, months Association mapping Mapping of relationships between two objects e.g. Account and AccountOwner
More informationGenerating A Hibernate Mapping File And Java Classes From The Sql Schema
Generating A Hibernate Mapping File And Java Classes From The Sql Schema Internally, hibernate maps from Java classes to database tables (and from It also provides data query and retrieval facilities by
More informationJava Magistère BFA
Java 101 - Magistère BFA Lesson 4: Generic Type and Collections Stéphane Airiau Université Paris-Dauphine Lesson 4: Generic Type and Collections (Stéphane Airiau) Java 1 Linked List 1 public class Node
More informationObject Persistence and Object-Relational Mapping. James Brucker
Object Persistence and Object-Relational Mapping James Brucker Goal Applications need to save data to persistent storage. Persistent storage can be database, directory service, XML files, spreadsheet,...
More informationAdvanced Programming Generics Collections
Advanced Programming Generics Collections The Context Create a data structure that stores elements: a stack, a linked list, a vector a graph, a tree, etc. What data type to use for representing the elements
More informationCSE 530A. Lab 3. Washington University Fall 2013
CSE 530A Lab 3 Washington University Fall 2013 Table Definitions The table definitions for lab 3 are slightly different from those for lab 2 Serial ID columns have been added to all of the tables Lab 2:
More informationCore Java Syllabus. Overview
Core Java Syllabus Overview Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java
More informationDatabase Application Architectures
Chapter 15 Database Application Architectures Database Systems(Part 2) p. 221/287 Database Applications Most users do not interact directly with a database system The DBMS is hidden behind application
More informationHibernate Overview. By Khader Shaik
Hibernate Overview By Khader Shaik 1 Agenda Introduction to ORM Overview of Hibernate Why Hibernate Anatomy of Example Overview of HQL Architecture Overview Comparison with ibatis and JPA 2 Introduction
More informationInternational Journal of Advance Research in Engineering, Science & Technology HIBERNATE FRAMEWORK FOR ENTERPRISE APPLICATION
Impact Factor (SJIF): 3.632 International Journal of Advance Research in Engineering, Science & Technology e-issn: 2393-9877, p-issn: 2394-2444 Volume 4, Issue 3, March-2017 HIBERNATE FRAMEWORK FOR ENTERPRISE
More informationSQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1
SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier
More informationData Modelling and Databases. Exercise Session 7: Integrity Constraints
Data Modelling and Databases Exercise Session 7: Integrity Constraints 1 Database Design Textual Description Complete Design ER Diagram Relational Schema Conceptual Modeling Logical Modeling Physical Modeling
More informationCollections. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff
Collections by Vlad Costel Ungureanu for Learn Stuff Collections 2 Collections Operations Add objects to the collection Remove objects from the collection Find out if an object (or group of objects) is
More informationLearn Java/J2EE Basic to Advance level by Swadeep Mohanty
Basics of Java Java - What, Where and Why? History and Features of Java Internals of Java Program Difference between JDK,JRE and JVM Internal Details of JVM Variable and Data Type OOPS Conecpts Advantage
More informationWentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Collections & Maps. Lecture 12. Collections & Maps
Lecture 12 1 Review: Data Structure A data structure is a collection of data organized in some fashion The structure not only stores data but also supports operations for accessing/manipulating the data
More informationJava Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING)
Java Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING) What is a Data Structure? Introduction A data structure is a particular way of organizing data using one or
More informationBuilding Java Programs
Building Java Programs Chapter 16 References and linked nodes reading: 16.1 2 Recall: stacks and queues stack: retrieves elements in reverse order as added queue: retrieves elements in same order as added
More informationTable of Contents. Tutorial API Deployment Prerequisites... 1
Copyright Notice All information contained in this document is the property of ETL Solutions Limited. The information contained in this document is subject to change without notice and does not constitute
More informationTeneo: Integrating EMF & EclipseLink
Teneo: Integrating EMF & EclipseLink Model-Driven Development with Persistence Shaun Smith Martin Taal Stephan Eberle 2009 Eclipse Foundation; made available under the EPL v1.0 2 Teneo: Integrating EMF
More informationEJB 3 Entity Relationships
Berner Fachhochschule Technik und Informatik EJB 3 Entity Relationships Course Multi Tier Business Applications with Java EE Prof. Dr. Eric Dubuis Berner Fachhochschule Biel Content What are relationships?
More informationApplication Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started
Application Development in JAVA Duration Lecture: Specialization x Hours Core Java (J2SE) & Advance Java (J2EE) Detailed Module Part I: Core Java (J2SE) Getting Started What is Java all about? Features
More informationHibernate OGM Architecture
HIBERNATE OGM Hibernate OGM Architecture Hibernate OGM Architecture http://docs.jboss.org/hibernate/ogm/4.0/reference/en-us/html_single/ Data Persistence How is Data Persisted Abstraction between the application
More informationJava Programming Unit 8. Selected Java Collec5ons. Generics.
Java Programming Unit 8 Selected Java Collec5ons. Generics. Java Collec5ons Framework Classes and interfaces from packages java.util and java.util.concurrent are called Java Collec5ons Framework. java.u5l:
More informationObject-Oriented Programming with Java
Object-Oriented Programming with Java Recitation No. 2 Oranit Dror The String Class Represents a character string (e.g. "Hi") Explicit constructor: String quote = "Hello World"; string literal All string
More informationU N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM Time Allowed: TWO HOURS ********
More informationEJB 3 Entity Relationships
Berner Fachhochschule Technik und Informatik EJB 3 Entity Relationships Course Multi Tier Business Applications with Java EE Prof. Dr. Eric Dubuis Berner Fachhochschule Biel Content What are relationships?
More informationCOMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016 Announcements Final is scheduled for Apr 21, 2pm 5pm GYM FIELD HOUSE Rows 1-21 Please submit course evaluations!
More informationPieter van den Hombergh Richard van den Ham. February 8, 2018
Pieter van den Hombergh Richard van den Ham Fontys Hogeschool voor Techniek en Logistiek February 8, 2018 /FHTenL February 8, 2018 1/16 Collection Zoo The basic collections, well known in programming s
More information27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection
Objectives Collection Collections Framework Concrete collections Collection algorithm By Võ Văn Hải Faculty of Information Technologies Summer 2012 Legacy collection 1 2 2/27 Collections Framework "Collection"
More informationBuilding Java Programs
Building Java Programs Chapter 16 References and linked nodes reading: 16.1 2 Value semantics value semantics: Behavior where values are copied when assigned, passed as parameters, or returned. All primitive
More informationCollections (Java) Collections Framework
Collections (Java) https://docs.oracle.com/javase/tutorial/collections/index.html Collection an object that groups multiple elements into a single unit. o store o retrieve o manipulate o communicate o
More informationHibernate in close action. INF5750/ Lecture 3 (Part III)
Hibernate in close action INF5750/9750 - Lecture 3 (Part III) Recalling Hibernate from Lect 2 Hibernate is an ORM tool? Hibernate can communication with different DBMS through? (mentioned in hibernate.properties)
More informationCSE 143 Au03 Final Exam Page 1 of 15
CSE 143 Au03 Final Exam Page 1 of 15 Reference information about many standard Java classes appears at the end of the test. You might want to tear off those pages to make them easier to refer to while
More informationIBM DB2 UDB V7.1 Family Fundamentals.
IBM 000-512 DB2 UDB V7.1 Family Fundamentals http://killexams.com/exam-detail/000-512 Answer: E QUESTION: 98 Given the following: A table containing a list of all seats on an airplane. A seat consists
More informationJava Persistence API (JPA)
Java Persistence API (JPA) Petr Křemen petr.kremen@fel.cvut.cz Winter Term 2016 Petr Křemen (petr.kremen@fel.cvut.cz) Java Persistence API (JPA) Winter Term 2016 1 / 53 Contents 1 Data Persistence 2 From
More informationInterview Questions I received in 2017 and 2018
Interview Questions I received in 2017 and 2018 Table of Contents INTERVIEW QUESTIONS I RECEIVED IN 2017 AND 2018... 1 1 OOPS... 3 1. What is the difference between Abstract and Interface in Java8?...
More informationChapter 1. Installation and Setup
Chapter 1. Installation and Setup Gradle ( Ant) HSQLDB Hibernate Core Project Hierarchy 1 / 18 Getting an Gradle Distribution Why do I care? Ant vs Maven vs Gradle How do I do that? http://www.gradle.org/
More informationModel Solutions. COMP 103: Test April, 2013
Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 40 minutes
More informationWhat data persistence means? We manipulate data (represented as object state) that need to be stored
1 Data Persistence What data persistence means? We manipulate data (represented as object state) that need to be stored persistently to survive a single run of the application queriably to be able to retrieve/access
More informationInterfaces. An interface defines a set of methods. An interface declaration contains signatures, but no implementations.
Interface Interface definition Interface implementation by classes Benefits of interfaces Implementation of multiple interface Java Collection Framework Interfaces An interface defines a set of methods.
More informationJava Collections Framework reloaded
Java Collections Framework reloaded October 1, 2004 Java Collections - 2004-10-01 p. 1/23 Outline Interfaces Implementations Ordering Java 1.5 Java Collections - 2004-10-01 p. 2/23 Components Interfaces:
More informationHIBERNATE MOCK TEST HIBERNATE MOCK TEST I
http://www.tutorialspoint.com HIBERNATE MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Hibernate Framework. You can download these sample mock tests
More informationStrings and Arrays. Hendrik Speleers
Hendrik Speleers Overview Characters and strings String manipulation Formatting output Arrays One-dimensional Two-dimensional Container classes List: ArrayList and LinkedList Iterating over a list Characters
More informationTECHNICAL WHITEPAPER. Performance Evaluation Java Collections Framework. Performance Evaluation Java Collections. Technical Whitepaper.
Performance Evaluation Java Collections Framework TECHNICAL WHITEPAPER Author: Kapil Viren Ahuja Date: October 17, 2008 Table of Contents 1 Introduction...3 1.1 Scope of this document...3 1.2 Intended
More informationHibernate Interview Questions
Hibernate Interview Questions 1. What is Hibernate? Hibernate is a powerful, high performance object/relational persistence and query service. This lets the users to develop persistent classes following
More informationExploring EJB3 With JBoss Application Server Part 6.3
By Swaminathan Bhaskar 02/07/2009 Exploring EJB3 With JBoss Application Server Part 6.3 In this part, we will continue to explore Entity Beans Using Java Persistence API (JPA). In the previous part, we
More informationJDO XML MetaData Reference (v5.2)
JDO XML MetaData Reference (v5.2) Table of Contents Metadata for package tag.................................................................... 6 Metadata for class tag.......................................................................
More informationChapter 10 Collections
Chapter 10 Collections I. Scott MacKenzie 1 Outline 2 1 What is a Collection? A collection is an aggregation with a variable number of components, or elements Examples Portfolio - a collection of Investment
More informationPERSİSTENCE OBJECT RELATİON MAPPİNG
PERSİSTENCE Most of the applications require storing and retrieving objects in a persistent storage mechanism. This chapter introduces how to store and retrieve information in a persistent storage with
More informationCall: JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline
JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline Advanced Java Database Programming JDBC overview SQL- Structured Query Language JDBC Programming Concepts Query Execution Scrollable
More informationTable of Contents. I. Pre-Requisites A. Audience B. Pre-Requisites. II. Introduction A. The Problem B. Overview C. History
Table of Contents I. Pre-Requisites A. Audience B. Pre-Requisites II. Introduction A. The Problem B. Overview C. History II. JPA A. Introduction B. ORM Frameworks C. Dealing with JPA D. Conclusion III.
More informationWhat is Transaction? Why Transaction Management Required? JDBC Transaction Management in Java with Example. JDBC Transaction Management Example
JDBC Transaction Management in Java with Example Here you will learn to implement JDBC transaction management in java. By default database is in auto commit mode. That means for any insert, update or delete
More informationCSE 8B Final Exam Fall 2015
Name: Tutor: Student ID: Signature: CSE 8B Final Exam Fall 2015 You can rip off the last page and use as scratch paper. Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 0
More information[Ref: Core Java Chp 13, Intro to Java Programming [Liang] Chp 22, Absolute Java Chp 16, docs.oracle.com/javase/tutorial/collections/toc.
Contents Topic 08 - Collections I. Introduction - Java Collection Hierarchy II. Choosing/using collections III. Collection and Iterator IV. Methods of Collection V. Concrete classes VI. Implementation
More informationCSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,
CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding
More informationHIBERNATE MOCK TEST HIBERNATE MOCK TEST IV
http://www.tutorialspoint.com HIBERNATE MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Hibernate Framework. You can download these sample mock tests
More informationPieter van den Hombergh Thijs Dorssers Stefan Sobek. June 8, 2017
Pieter van den Hombergh Thijs Dorssers Stefan Sobek Fontys Hogeschool voor Techniek en Logistiek June 8, 2017 /FHTenL June 8, 2017 1/19 Collection Zoo The basic collections, well known in programming s
More informationDaffodil DB. Design Document (Beta) Version 4.0
Daffodil DB Design Document (Beta) Version 4.0 January 2005 Copyright Daffodil Software Limited Sco 42,3 rd Floor Old Judicial Complex, Civil lines Gurgaon - 122001 Haryana, India. www.daffodildb.com All
More informationCSC 1351: Final. The code compiles, but when it runs it throws a ArrayIndexOutOfBoundsException
VERSION A CSC 1351: Final Name: 1 Interfaces, Classes and Inheritance 2 Basic Data Types (arrays, lists, stacks, queues, trees,...) 2.1 Does the following code compile? If it does not, how can it be fixed?
More informationExceptions and Design
Exceptions and Exceptions and Table of contents 1 Error Handling Overview Exceptions RuntimeExceptions 2 Exceptions and Overview Exceptions RuntimeExceptions Exceptions Exceptions and Overview Exceptions
More informationClass Libraries. Readings and References. Java fundamentals. Java class libraries and data structures. Reading. Other References
Reading Readings and References Class Libraries CSE 142, Summer 2002 Computer Programming 1 Other References» The Java tutorial» http://java.sun.com/docs/books/tutorial/ http://www.cs.washington.edu/education/courses/142/02su/
More informationTwo hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 22 nd May Time: 14:00 16:00
Appendices Attached First year overseas students are allowed the use of a pre-approved simple English language translation, non-scientific dictionary. COMP17010 Two hours UNIVERSITY OF MANCHESTER SCHOOL
More informationBinghamton University. CS-140 Fall Problem Solving. Creating a class from scratch
Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods
More informationLinked Lists. References and objects
Linked Lists slides created by Marty Stepp http://www.cs.washington.edu/143/ Modified by Sarah Heckman Reading: RS Chapter 16 References and objects In Java, objects and arrays use reference semantics.
More informationImplementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations
Readings List Implementations Chapter 20.2 Objectives Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations Additional references:
More informationHibernate in Action by Christian Bauer and Gavin King Chapter 6. Copyright 2004 Manning Publications
JAVA Ara Abrahamian, XDoclet Lead Developer What s Inside AUTHOR ONLINE Ask the Authors Ebook edition ISBN -932394-5-X contents Christian Bauer and Gavin King The Bible of Hibernate ibernate practically
More informationindx.qxd 11/3/04 3:34 PM Page 339 Index
indx.qxd 11/3/04 3:34 PM Page 339 Index *.hbm.xml files, 30, 86 @ tags (XDoclet), 77 86 A Access attributes, 145 155, 157 165, 171 ACID (atomic, consistent, independent, and durable), 271 AddClass() method,
More informationHibernate Quickly by Patrick Peak and Nick Heudecker Chapter 3
Hibernate Quickly by Patrick Peak and Nick Heudecker Chapter 3 Brief contents 1 Why Hibernate? 1 2 Installing and building projects with Ant 26 3 Hibernate basics 50 4 Associations and components 88 5
More information