1 Hibernate Quick Start For the labs we will be using the following: Hibernate 3.2.6 Hibernate Tools JDK 1.5.0.15 Derby 10.4.1.3 Tomcat 5.5.26 Eclipse 3.3.2 JEE Download and install the following: Hibernate 3.2.6 http://www.hibernate.org HibernateTools-3.2.2.Beta1.zip http://www.hibernate.org JDK 1.5.0.15 http://java.sun.com/javase/downloads/index_jdk5.jsp Derby 10.4.1.3 http://db.apache.org/derby Tomcat 5.5.26 http://www.apache.org Eclipse IDE for Java EE Developers http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/releas e/europa/winter/eclipse-jee-europa-winter-win32.zip
224
Embed
Hibernate Quick Start - Marathon Technology, Inc. Quick Start.pdf · 1 Hibernate Quick Start For the labs we will be using the following: Hibernate 3.2.6 Hibernate Tools JDK 1.5.0.15
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
Hibernate Quick Start
For the labs we will be using the following: Hibernate 3.2.6 Hibernate Tools JDK 1.5.0.15 Derby 10.4.1.3 Tomcat 5.5.26 Eclipse 3.3.2 JEE
Eclipse IDE for Java EE Developershttp://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/europa/winter/eclipse-jee-europa-winter-win32.zip
PET_ID BIGINT NOT NULL,NICKNAME VARCHAR(40) NOT NULL,CONSTRAINT PK_PET_BREEDS PRIMARY KEY(PET_ID, NICKNAME),CONSTRAINT FK_NICKNAMES_TO_PET FOREIGN KEY(PET_ID) REFERENCES
PET(PET_ID));
CREATE TABLE DOG(
PET_ID BIGINT NOT NULL,TRICKS VARCHAR(120) NOT NULL,CONSTRAINT PK_DOG PRIMARY KEY(PET_ID),CONSTRAINT FK_DOG_TO_PET FOREIGN KEY(PET_ID) REFERENCES
PET(PET_ID));
CREATE TABLE INVENTORY(
INVENTORY_ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (STARTWITH 1, INCREMENT BY 1),
PET_ID BIGINT NOT NULL,LOCATION VARCHAR(25) NOT NULL,QUANTITY INTEGER NOT NULL,VERSION INTEGER DEFAULT 1,CONSTRAINT PK_INVENTORY PRIMARY KEY(INVENTORY_ID),CONSTRAINT UNQ_PET_LOCATION UNIQUE(PET_ID, LOCATION),CONSTRAINT FK_INVENTORY_TO_PET FOREIGN KEY(PET_ID) REFERENCES
PET(PET_ID));
45
INSERT INTO PET VALUES (DEFAULT, 'LIC00000', 'Fido', 'Dog', '1992-01-04', 19.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC11111', 'Rex', 'Dog', '1994-02-05', 119.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC12222', 'Fluffy', 'Cat', '1998-05-04', 29.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC33333', 'Goldie', 'Fish', '2001-11-03', 39.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC44444', 'Slinky', 'Snake', '2002-12-10', 49.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC55555', 'Spot', 'Dog', '2004-06-15', 40.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC66666', 'Inky', 'Cat', '2006-01-24', 110.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC77777', 'Bubbles', 'Fish', '1992-02-14', 16.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC88888', 'Arson', 'Dog', '1991-03-14', 10.95, 1);INSERT INTO PET VALUES (DEFAULT, 'LIC99999', 'Rollins', 'Dog', '1992-04-24', 120.95, 1);
INSERT INTO PET_NICKNAMES VALUES (1, 'Fi');INSERT INTO PET_NICKNAMES VALUES (1, 'Do');INSERT INTO PET_NICKNAMES VALUES (2, 'R');INSERT INTO PET_NICKNAMES VALUES (2, 'Rexxy');INSERT INTO PET_NICKNAMES VALUES (3, 'Fluf');INSERT INTO PET_NICKNAMES VALUES (4, 'Goldk');INSERT INTO PET_NICKNAMES VALUES (5, 'Slink');INSERT INTO PET_NICKNAMES VALUES (6, 'Out');INSERT INTO PET_NICKNAMES VALUES (7, 'Ink');INSERT INTO PET_NICKNAMES VALUES (8, 'Bub');INSERT INTO PET_NICKNAMES VALUES (9, 'Arny');INSERT INTO PET_NICKNAMES VALUES (10, 'Rolly');
INSERT INTO DOG VALUES (1, 'Sit, Play Dead');INSERT INTO DOG VALUES (2, 'Sit, Roll Over');INSERT INTO DOG VALUES (3, 'Eat, Sleep');INSERT INTO DOG VALUES (4, 'Eat, Swim');INSERT INTO DOG VALUES (5, 'Sleep, Eat');
INSERT INTO INVENTORY VALUES (DEFAULT, 1, 'Dallas', 10, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 1, 'Ft Worth', 20, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 2, 'Dallas', 15, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 3, 'Dallas', 5, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 4, 'Dallas', 8, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 5, 'Dallas', 18, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 6, 'Dallas', 3, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 7, 'Dallas', 21, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 8, 'Dallas', 4, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 9, 'Dallas', 2, 1);INSERT INTO INVENTORY VALUES (DEFAULT, 10, 'Dallas', 1, 1);
46
Set the Connection Profile Type, Name and Database.
47
Execute the SQL. The DROP statements will fail, so select all of the SQL except theDROP statements and select Execute Selected Text.
48
You should see the following Successful messages.
49
You can examine and edit the data. You may have to refresh the database to see thetables.
50
You can edit the data if you want to.
Click F5 to Refresh the data.
51
Lab 5 - Prepare the Project for Hibernate.
Create a User Library.
Switch back to the JEE Perspective.
52
Select Java | Build Path | User Libraries
Click New…
53
Name the Library.
54
Click Add JARs…
55
Add the hibernate3.jar file from C:\hibernate-3.2
56
Add the following JARs from C:\hibernate-3.2\lib
57
Add derbyclient.jar from C:\db-derby-10.4.1.3-bin\lib
58
Click OK
59
Add the User Library to the Project.
Select the Project Properties
60
Select Java Build Path | Libraries tab.
Click Add Library…
61
Select User Library.
62
Select the Library.
63
Click OK.
64
Create the Hibernate Configuration File
Create a new XML file in the src folder.
65
Name the file hibernate.cfg.xml.
66
Select to create the XML from a DTD file.
67
Select the Hibernate DTD. This is available when Hibernate Tools is installed.
68
Accept the defaults and click Finish.
69
Enter the following.
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-configuration PUBLIC
INFO: Not binding factory to JNDI, no JNDI name configuredSession connect status: trueSep 24, 2008 12:10:15 PM org.hibernate.impl.SessionFactoryImpl closeINFO: closing
74
The Problem with the Classpath. This means that the JAR files will not be added to theserver. We will discuss this later.
If you have problems with Hibernate not finding the tables, try the following inhibernate.cfg.xml:
<property name="hibernate.default_schema">user
</property>
75
Lab 6 - Create a Simple Class Mapping
Create a new package named pets.
76
Create a new class named Pet with the following attributes.
Re-Run TestSimpleMapping and you should see the following.
INFO: Not binding factory to JNDI, no JNDI name configuredSession connect status: trueHibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.LICENSE asLICENSE0_0_, pet0_.NAME as NAME0_0_, pet0_.DESCRIPTION asDESCRIPT4_0_0_, pet0_.BIRTH_DATE as BIRTH5_0_0_, pet0_.PRICE asPRICE0_0_ from PET pet0_ where pet0_.PET_ID=?pets.Pet@1, Pet_ID: 1, Name: Fido, Description: Dog, Price: 19.95, Dateof Birth: 1992-01-04Sep 26, 2008 9:22:53 PM org.hibernate.impl.SessionFactoryImpl close
88
Lab 8 - Logging with Log4j
Create a new file in the src folder called log4j.properties.
89
Enter the following or copy the Hibernate sample and make any changes.
### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p%c{1}:%L - %m%n
### direct messages to file hibernate.log ####log4j.appender.file=org.apache.log4j.FileAppender#log4j.appender.file.File=hibernate.log#log4j.appender.file.layout=org.apache.log4j.PatternLayout#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L- %m%n
### set log levels - for more verbose logging change 'info' to 'debug'###
### enable the following line if you want to track down connection ###### leakages when using DriverManagerConnectionProvider ####log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
90
Add the Log4j JAR file to the User Library.
Select Window | Preferences…
91
From the Java Build Path | User Libraries, click the Add JARs… button.
92
From the lib folder where you installed Hibernate, select log4j-1.2.11.jar and clickOpen.
93
Click OK.
94
Run TestSimpleMapping and you should see the following:
21:28:24,250 INFO SessionFactoryObjectFactory:82 - Not binding factoryto JNDI, no JNDI name configuredSession connect status: true21:28:24,296 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_0_,pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_, pet0_.DESCRIPTIONas DESCRIPT4_0_0_, pet0_.BIRTH_DATE as BIRTH5_0_0_, pet0_.PRICE asPRICE0_0_ from PET pet0_ where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.LICENSE asLICENSE0_0_, pet0_.NAME as NAME0_0_, pet0_.DESCRIPTION asDESCRIPT4_0_0_, pet0_.BIRTH_DATE as BIRTH5_0_0_, pet0_.PRICE asPRICE0_0_ from PET pet0_ where pet0_.PET_ID=?21:28:24,296 DEBUG LongType:133 - binding '1' to parameter: 121:28:24,328 DEBUG StringType:172 - returning 'LIC00000' as column:LICENSE0_0_21:28:24,328 DEBUG StringType:172 - returning 'Fido' as column:NAME0_0_21:28:24,328 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT4_0_0_21:28:24,343 DEBUG DateType:172 - returning '04 January 1992' ascolumn: BIRTH5_0_0_21:28:24,343 DEBUG BigDecimalType:172 - returning '19.95' as column:PRICE0_0_pets.Pet@1, Pet_ID: 1, Name: Fido, Description: Dog, Price: 19.95, Dateof Birth: 1992-01-0421:28:24,359 INFO SessionFactoryImpl:769 - closing
95
Lab 9 - Simple Inserting and Modifying
Create a new class called TestSimpleInsertModify in the tests package.
// Insert new PetPet pet1 = new Pet();pet1.setName("Rocky");pet1.setLicense("LIC12121");pet1.setDescription("Dog");pet1.setPrice(new BigDecimal("42.12"));pet1.setBirth_date(
new Date(System.currentTimeMillis()));
// Save the new PetTransaction tx = s.beginTransaction();Long pet1_id = (Long) s.save(pet1);System.out.println("Saved Pet: " + pet1);tx.commit();
96
// Modify the Pettx = s.beginTransaction();pet1 = (Pet) s.get(Pet.class, pet1_id);System.out.println("Retrieved Pet: " + pet1);pet1.setDescription("This is a new Description");tx.commit();
// Deleting the Pettx = s.beginTransaction();pet1 = (Pet) s.load(Pet.class, pet1_id);s.delete(pet1);tx.commit();
"*** Query all Pets Where pet_id > 3 ***");Query q = s.createQuery("FROM Pet p WHERE pet_id > 3");Iterator i = q.list().iterator();while (i.hasNext()) {
Pet pet = (Pet) i.next();System.out.println(
"pet_id > 3 query retrieved Pet: " + pet);}
99
// PagesSystem.out.println(
"*** Pagination - first 2 then next 2 where " +"pet_id > 3 ***");
q.setFirstResult(0);q.setMaxResults(2);System.out.println("--- First 2 results");i = q.list().iterator();while (i.hasNext()) {
Pet pet = (Pet) i.next();System.out.println(
"pet_id > 3 query retrieved Pet: " + pet);}
q.setFirstResult(5);q.setMaxResults(5);System.out.println("--- Second 2 results");i = q.list().iterator();while (i.hasNext()) {
Pet pet = (Pet) i.next();System.out.println(
"pet_id > 3 query retrieved Pet: " + pet);}
// Named ParametersSystem.out.println("*** Named Parameters **");Query q2 = s.createQuery("FROM Pet WHERE pet_id = :pet_id");q2.setLong("pet_id", new Long(4));Pet pet = (Pet) q2.uniqueResult();
Session connect status: true*** Query all Pets Where pet_id > 3 ***22:11:24,218 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_,pet0_.LICENSE as LICENSE0_, pet0_.NAME as NAME0_, pet0_.DESCRIPTION asDESCRIPT4_0_, pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_from PET pet0_ where pet0_.PET_ID>3Hibernate: select pet0_.PET_ID as PET1_0_, pet0_.LICENSE as LICENSE0_,pet0_.NAME as NAME0_, pet0_.DESCRIPTION as DESCRIPT4_0_,pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_ from PET pet0_where pet0_.PET_ID>322:11:24,234 DEBUG LongType:172 - returning '4' as column: PET1_0_22:11:24,234 DEBUG StringType:172 - returning 'LIC33333' as column:LICENSE0_22:11:24,234 DEBUG StringType:172 - returning 'Goldie' as column:NAME0_22:11:24,234 DEBUG StringType:172 - returning 'Fish' as column:DESCRIPT4_0_22:11:24,250 DEBUG DateType:172 - returning '03 November 2001' ascolumn: BIRTH5_0_22:11:24,250 DEBUG BigDecimalType:172 - returning '39.95' as column:PRICE0_22:11:24,250 DEBUG LongType:172 - returning '5' as column: PET1_0_22:11:24,250 DEBUG StringType:172 - returning 'LIC44444' as column:LICENSE0_22:11:24,250 DEBUG StringType:172 - returning 'Slinky' as column:NAME0_22:11:24,250 DEBUG StringType:172 - returning 'Snake' as column:DESCRIPT4_0_22:11:24,250 DEBUG DateType:172 - returning '10 December 2002' ascolumn: BIRTH5_0_22:11:24,250 DEBUG BigDecimalType:172 - returning '49.95' as column:PRICE0_22:11:24,250 DEBUG LongType:172 - returning '6' as column: PET1_0_22:11:24,250 DEBUG StringType:172 - returning 'LIC55555' as column:LICENSE0_22:11:24,250 DEBUG StringType:172 - returning 'Spot' as column: NAME0_22:11:24,250 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT4_0_22:11:24,250 DEBUG DateType:172 - returning '15 June 2004' as column:BIRTH5_0_22:11:24,250 DEBUG BigDecimalType:172 - returning '40.95' as column:PRICE0_22:11:24,250 DEBUG LongType:172 - returning '7' as column: PET1_0_22:11:24,265 DEBUG StringType:172 - returning 'LIC66666' as column:LICENSE0_22:11:24,265 DEBUG StringType:172 - returning 'Inky' as column: NAME0_22:11:24,265 DEBUG StringType:172 - returning 'Cat' as column:DESCRIPT4_0_
102
22:11:24,265 DEBUG DateType:172 - returning '24 January 2006' ascolumn: BIRTH5_0_22:11:24,265 DEBUG BigDecimalType:172 - returning '110.95' as column:PRICE0_22:11:24,265 DEBUG LongType:172 - returning '8' as column: PET1_0_22:11:24,265 DEBUG StringType:172 - returning 'LIC77777' as column:LICENSE0_22:11:24,265 DEBUG StringType:172 - returning 'Bubbles' as column:NAME0_22:11:24,265 DEBUG StringType:172 - returning 'Fish' as column:DESCRIPT4_0_22:11:24,265 DEBUG DateType:172 - returning '14 February 1992' ascolumn: BIRTH5_0_22:11:24,265 DEBUG BigDecimalType:172 - returning '16.95' as column:PRICE0_22:11:24,265 DEBUG LongType:172 - returning '9' as column: PET1_0_22:11:24,265 DEBUG StringType:172 - returning 'LIC88888' as column:LICENSE0_22:11:24,265 DEBUG StringType:172 - returning 'Arson' as column: NAME0_22:11:24,265 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT4_0_22:11:24,265 DEBUG DateType:172 - returning '14 March 1991' as column:BIRTH5_0_22:11:24,265 DEBUG BigDecimalType:172 - returning '10.95' as column:PRICE0_22:11:24,265 DEBUG LongType:172 - returning '10' as column: PET1_0_22:11:24,265 DEBUG StringType:172 - returning 'LIC99999' as column:LICENSE0_22:11:24,265 DEBUG StringType:172 - returning 'Rollins' as column:NAME0_22:11:24,265 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT4_0_22:11:24,265 DEBUG DateType:172 - returning '24 April 1992' as column:BIRTH5_0_22:11:24,265 DEBUG BigDecimalType:172 - returning '120.95' as column:PRICE0_
103
pet_id > 3 query retrieved Pet: pets.Pet@4, Pet_ID: 4, Name: Goldie,Description: Fish, Price: 39.95, Date of Birth: 2001-11-03pet_id > 3 query retrieved Pet: pets.Pet@5, Pet_ID: 5, Name: Slinky,Description: Snake, Price: 49.95, Date of Birth: 2002-12-10pet_id > 3 query retrieved Pet: pets.Pet@6, Pet_ID: 6, Name: Spot,Description: Dog, Price: 40.95, Date of Birth: 2004-06-15pet_id > 3 query retrieved Pet: pets.Pet@7, Pet_ID: 7, Name: Inky,Description: Cat, Price: 110.95, Date of Birth: 2006-01-24pet_id > 3 query retrieved Pet: pets.Pet@8, Pet_ID: 8, Name: Bubbles,Description: Fish, Price: 16.95, Date of Birth: 1992-02-14pet_id > 3 query retrieved Pet: pets.Pet@9, Pet_ID: 9, Name: Arson,Description: Dog, Price: 10.95, Date of Birth: 1991-03-14pet_id > 3 query retrieved Pet: pets.Pet@a, Pet_ID: 10, Name: Rollins,Description: Dog, Price: 120.95, Date of Birth: 1992-04-24*** Pagination - first 2 then next 2 where pet_id > 3 ***--- First 2 results22:11:24,281 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_,pet0_.LICENSE as LICENSE0_, pet0_.NAME as NAME0_, pet0_.DESCRIPTION asDESCRIPT4_0_, pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_from PET pet0_ where pet0_.PET_ID>3Hibernate: select pet0_.PET_ID as PET1_0_, pet0_.LICENSE as LICENSE0_,pet0_.NAME as NAME0_, pet0_.DESCRIPTION as DESCRIPT4_0_,pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_ from PET pet0_where pet0_.PET_ID>322:11:24,296 DEBUG LongType:172 - returning '4' as column: PET1_0_22:11:24,296 DEBUG LongType:172 - returning '5' as column: PET1_0_pet_id > 3 query retrieved Pet: pets.Pet@4, Pet_ID: 4, Name: Goldie,Description: Fish, Price: 39.95, Date of Birth: 2001-11-03pet_id > 3 query retrieved Pet: pets.Pet@5, Pet_ID: 5, Name: Slinky,Description: Snake, Price: 49.95, Date of Birth: 2002-12-10--- Second 2 results22:11:24,296 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_,pet0_.LICENSE as LICENSE0_, pet0_.NAME as NAME0_, pet0_.DESCRIPTION asDESCRIPT4_0_, pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_from PET pet0_ where pet0_.PET_ID>3Hibernate: select pet0_.PET_ID as PET1_0_, pet0_.LICENSE as LICENSE0_,pet0_.NAME as NAME0_, pet0_.DESCRIPTION as DESCRIPT4_0_,pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_ from PET pet0_where pet0_.PET_ID>322:11:24,296 DEBUG LongType:172 - returning '9' as column: PET1_0_22:11:24,296 DEBUG LongType:172 - returning '10' as column: PET1_0_pet_id > 3 query retrieved Pet: pets.Pet@9, Pet_ID: 9, Name: Arson,Description: Dog, Price: 10.95, Date of Birth: 1991-03-14pet_id > 3 query retrieved Pet: pets.Pet@a, Pet_ID: 10, Name: Rollins,Description: Dog, Price: 120.95, Date of Birth: 1992-04-24
104
*** Named Parameters **22:11:24,312 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_,pet0_.LICENSE as LICENSE0_, pet0_.NAME as NAME0_, pet0_.DESCRIPTION asDESCRIPT4_0_, pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_from PET pet0_ where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_, pet0_.LICENSE as LICENSE0_,pet0_.NAME as NAME0_, pet0_.DESCRIPTION as DESCRIPT4_0_,pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_ from PET pet0_where pet0_.PET_ID=?22:11:24,312 DEBUG LongType:133 - binding '4' to parameter: 122:11:24,312 DEBUG LongType:172 - returning '4' as column: PET1_0_Named Parameters query retrieved Pet: pets.Pet@4, Pet_ID: 4, Name:Goldie, Description: Fish, Price: 39.95, Date of Birth: 2001-11-0322:11:24,328 INFO SessionFactoryImpl:769 - closing
105
Lab 11 - Named Query
Update Pet.hbm.xml with the following Named Query.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping>
Session connect status: true07:40:44,000 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_,pet0_.LICENSE as LICENSE0_, pet0_.NAME as NAME0_, pet0_.DESCRIPTION asDESCRIPT4_0_, pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_from PET pet0_ where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_, pet0_.LICENSE as LICENSE0_,pet0_.NAME as NAME0_, pet0_.DESCRIPTION as DESCRIPT4_0_,pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_ from PET pet0_where pet0_.PET_ID=?07:40:44,187 DEBUG LongType:133 - binding '2' to parameter: 107:40:44,203 DEBUG LongType:172 - returning '2' as column: PET1_0_07:40:44,218 DEBUG StringType:172 - returning 'LIC11111' as column:LICENSE0_07:40:44,218 DEBUG StringType:172 - returning 'Rex' as column: NAME0_07:40:44,218 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT4_0_07:40:44,218 DEBUG DateType:172 - returning '05 February 1994' ascolumn: BIRTH5_0_07:40:44,234 DEBUG BigDecimalType:172 - returning '119.95' as column:PRICE0_07:40:44,250 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_,pet0_.LICENSE as LICENSE0_, pet0_.NAME as NAME0_, pet0_.DESCRIPTION asDESCRIPT4_0_, pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_from PET pet0_ where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_, pet0_.LICENSE as LICENSE0_,pet0_.NAME as NAME0_, pet0_.DESCRIPTION as DESCRIPT4_0_,pet0_.BIRTH_DATE as BIRTH5_0_, pet0_.PRICE as PRICE0_ from PET pet0_where pet0_.PET_ID=?07:40:44,250 DEBUG LongType:133 - binding '2' to parameter: 107:40:44,250 DEBUG LongType:172 - returning '2' as column: PET1_0_Size 1pets.Pet@2, Pet_ID: 2, Name: Rex, Description: Dog, Price: 119.95, Dateof Birth: 1994-02-0507:40:44,265 INFO SessionFactoryImpl:769 - closing
108
Lab 12 - Projection Query
Create a new classed named TestProjectionQuery and enter the following.
Session connect status: true07:50:43,437 DEBUG SQL:401 - select count(*) as col_0_0_ from PET pet0_Hibernate: select count(*) as col_0_0_ from PET pet0_07:50:43,500 DEBUG LongType:172 - returning '10' as column: col_0_0_Row Count: 1007:50:43,500 DEBUG SQL:401 - select count(*) as col_0_0_,count(distinct pet0_.NAME) as col_1_0_ from PET pet0_Hibernate: select count(*) as col_0_0_, count(distinct pet0_.NAME) ascol_1_0_ from PET pet0_07:50:43,562 DEBUG LongType:172 - returning '10' as column: col_0_0_07:50:43,562 DEBUG LongType:172 - returning '10' as column: col_1_0_07:50:43,562 DEBUG SQL:401 - select count(*) as col_0_0_,count(distinct pet0_.NAME) as col_1_0_ from PET pet0_Hibernate: select count(*) as col_0_0_, count(distinct pet0_.NAME) ascol_1_0_ from PET pet0_07:50:43,578 DEBUG LongType:172 - returning '10' as column: col_0_0_07:50:43,578 DEBUG LongType:172 - returning '10' as column: col_1_0_Size 1101007:50:43,578 INFO SessionFactoryImpl:769 – closing
117
Lab 14 – Context Sessions
Create a new package named utils.
118
Create a new class named HibernateUtil with the following attributes.
Update the Pet class with a field and a getter and setter to support the Inventory.
private Set inventoryRecords = new HashSet();
public Set getInventoryRecords() {return inventoryRecords;
}
public void setInventoryRecords(Set inventoryRecords) {this.inventoryRecords = inventoryRecords;
}
Add the following method to add to the Inventory.
public void addInventoryRecord(String location, int quantity) {Inventory inv = new Inventory(location,quantity);inv.setPet(this);getInventoryRecords().add(inv);
*** Retrieving with Session.get() ***17:08:26,687 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_0_,pet0_.VERSION as VERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAMEas NAME0_0_, pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE asBIRTH6_0_0_, pet0_.PRICE as PRICE0_0_ from PET pet0_ wherepet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_ from PET pet0_ where pet0_.PET_ID=?17:08:26,687 DEBUG LongType:133 - binding '1' to parameter: 117:08:26,703 DEBUG IntegerType:172 - returning '3' as column:VERSION0_0_17:08:26,703 DEBUG StringType:172 - returning 'LIC00000' as column:LICENSE0_0_17:08:26,703 DEBUG StringType:172 - returning 'Fido' as column:NAME0_0_17:08:26,703 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_17:08:26,718 DEBUG DateType:172 - returning '04 January 1992' ascolumn: BIRTH6_0_0_17:08:26,718 DEBUG BigDecimalType:172 - returning '19.95' as column:PRICE0_0_17:08:26,734 DEBUG SQL:401 - select inventoryr0_.PET_ID as PET5_1_,inventoryr0_.INVENTORY_ID as INVENTORY1_1_, inventoryr0_.INVENTORY_IDas INVENTORY1_2_0_, inventoryr0_.VERSION as VERSION2_0_,inventoryr0_.location as location2_0_, inventoryr0_.quantity asquantity2_0_, inventoryr0_.PET_ID as PET5_2_0_ from INVENTORYinventoryr0_ where inventoryr0_.PET_ID=?Hibernate: select inventoryr0_.PET_ID as PET5_1_,inventoryr0_.INVENTORY_ID as INVENTORY1_1_, inventoryr0_.INVENTORY_IDas INVENTORY1_2_0_, inventoryr0_.VERSION as VERSION2_0_,inventoryr0_.location as location2_0_, inventoryr0_.quantity asquantity2_0_, inventoryr0_.PET_ID as PET5_2_0_ from INVENTORYinventoryr0_ where inventoryr0_.PET_ID=?17:08:26,734 DEBUG LongType:133 - binding '1' to parameter: 117:08:26,750 DEBUG LongType:172 - returning '1' as column:INVENTORY1_2_0_17:08:26,750 DEBUG IntegerType:172 - returning '1' as column:VERSION2_0_17:08:26,750 DEBUG StringType:172 - returning 'Dallas' as column:location2_0_17:08:26,750 DEBUG IntegerType:172 - returning '10' as column:quantity2_0_17:08:26,750 DEBUG LongType:172 - returning '1' as column: PET5_2_0_17:08:26,750 DEBUG LongType:172 - returning '1' as column: PET5_1_17:08:26,750 DEBUG LongType:172 - returning '1' as column:
145
INVENTORY1_1_17:08:26,750 DEBUG LongType:172 - returning '2' as column:INVENTORY1_2_0_17:08:26,750 DEBUG IntegerType:172 - returning '1' as column:VERSION2_0_17:08:26,750 DEBUG StringType:172 - returning 'Ft Worth' as column:location2_0_17:08:26,765 DEBUG IntegerType:172 - returning '20' as column:quantity2_0_17:08:26,765 DEBUG LongType:172 - returning '1' as column: PET5_2_0_17:08:26,765 DEBUG LongType:172 - returning '1' as column: PET5_1_17:08:26,765 DEBUG LongType:172 - returning '2' as column:INVENTORY1_1_17:08:26,765 DEBUG LongType:172 - returning '13' as column:INVENTORY1_2_0_17:08:26,765 DEBUG IntegerType:172 - returning '0' as column:VERSION2_0_17:08:26,765 DEBUG StringType:172 - returning 'San Antonio' as column:location2_0_17:08:26,765 DEBUG IntegerType:172 - returning '10' as column:quantity2_0_17:08:26,765 DEBUG LongType:172 - returning '1' as column: PET5_2_0_17:08:26,765 DEBUG LongType:172 - returning '1' as column: PET5_1_17:08:26,765 DEBUG LongType:172 - returning '13' as column:INVENTORY1_1_Inventory: 1, Ft Worth, 20Inventory: 1, San Antonio, 10Inventory: 1, Dallas, 10*** END Retrieving with Session.get() ****** Querying with LEFT JOIN FETCH ***17:08:26,812 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_0_,inventoryr1_.INVENTORY_ID as INVENTORY1_2_1_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, inventoryr1_.VERSION as VERSION2_1_,inventoryr1_.location as location2_1_, inventoryr1_.quantity asquantity2_1_, inventoryr1_.PET_ID as PET5_2_1_, inventoryr1_.PET_ID asPET5_0__, inventoryr1_.INVENTORY_ID as INVENTORY1_0__ from PET pet0_left outer join INVENTORY inventoryr1_ onpet0_.PET_ID=inventoryr1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, inventoryr1_.INVENTORY_IDas INVENTORY1_2_1_, pet0_.VERSION as VERSION0_0_, pet0_.LICENSE asLICENSE0_0_, pet0_.NAME as NAME0_0_, pet0_.DESCRIPTION asDESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_, pet0_.PRICE asPRICE0_0_, inventoryr1_.VERSION as VERSION2_1_, inventoryr1_.locationas location2_1_, inventoryr1_.quantity as quantity2_1_,inventoryr1_.PET_ID as PET5_2_1_, inventoryr1_.PET_ID as PET5_0__,inventoryr1_.INVENTORY_ID as INVENTORY1_0__ from PET pet0_ left outerjoin INVENTORY inventoryr1_ on pet0_.PET_ID=inventoryr1_.PET_ID wherepet0_.PET_ID=?
146
17:08:26,828 DEBUG LongType:133 - binding '1' to parameter: 117:08:26,843 DEBUG LongType:172 - returning '1' as column: PET1_0_0_17:08:26,843 DEBUG LongType:172 - returning '1' as column:INVENTORY1_2_1_17:08:26,843 DEBUG IntegerType:172 - returning '3' as column:VERSION0_0_17:08:26,843 DEBUG StringType:172 - returning 'LIC00000' as column:LICENSE0_0_17:08:26,843 DEBUG StringType:172 - returning 'Fido' as column:NAME0_0_17:08:26,843 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_17:08:26,843 DEBUG DateType:172 - returning '04 January 1992' ascolumn: BIRTH6_0_0_17:08:26,843 DEBUG BigDecimalType:172 - returning '19.95' as column:PRICE0_0_17:08:26,843 DEBUG IntegerType:172 - returning '1' as column:VERSION2_1_17:08:26,843 DEBUG StringType:172 - returning 'Dallas' as column:location2_1_17:08:26,843 DEBUG IntegerType:172 - returning '10' as column:quantity2_1_17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET5_2_1_17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET5_0__17:08:26,843 DEBUG LongType:172 - returning '1' as column:INVENTORY1_0__17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET1_0_0_17:08:26,843 DEBUG LongType:172 - returning '2' as column:INVENTORY1_2_1_17:08:26,843 DEBUG IntegerType:172 - returning '1' as column:VERSION2_1_17:08:26,843 DEBUG StringType:172 - returning 'Ft Worth' as column:location2_1_17:08:26,843 DEBUG IntegerType:172 - returning '20' as column:quantity2_1_17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET5_2_1_17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET5_0__17:08:26,843 DEBUG LongType:172 - returning '2' as column:INVENTORY1_0__17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET1_0_0_17:08:26,843 DEBUG LongType:172 - returning '13' as column:INVENTORY1_2_1_17:08:26,843 DEBUG IntegerType:172 - returning '0' as column:VERSION2_1_17:08:26,843 DEBUG StringType:172 - returning 'San Antonio' as column:location2_1_17:08:26,843 DEBUG IntegerType:172 - returning '10' as column:quantity2_1_17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET5_2_1_17:08:26,843 DEBUG LongType:172 - returning '1' as column: PET5_0__17:08:26,843 DEBUG LongType:172 - returning '13' as column:INVENTORY1_0__
147
Size of list = 3Size of hashSet = 1Inventory: 1, Ft Worth, 20Inventory: 1, San Antonio, 10Inventory: 1, Dallas, 10*** END Querying with LEFT JOIN FETCH ****** Locations for Pet 1 ***17:08:26,890 DEBUG SQL:401 - select inventoryr1_.location as col_0_0_from PET pet0_ inner join INVENTORY inventoryr1_ onpet0_.PET_ID=inventoryr1_.PET_ID where pet0_.PET_ID=?Hibernate: select inventoryr1_.location as col_0_0_ from PET pet0_inner join INVENTORY inventoryr1_ on pet0_.PET_ID=inventoryr1_.PET_IDwhere pet0_.PET_ID=?17:08:26,906 DEBUG LongType:133 - binding '1' to parameter: 117:08:26,906 DEBUG StringType:172 - returning 'Dallas' as column:col_0_0_17:08:26,906 DEBUG StringType:172 - returning 'Ft Worth' as column:col_0_0_17:08:26,906 DEBUG StringType:172 - returning 'San Antonio' as column:col_0_0_DallasFt WorthSan Antonio*** End Locations for Pet 1 ***
148
Lab 19 – Inheritance
Create a new class named Dog with the following attributes.
149
Add the following code.
package pets;
import java.math.BigDecimal;import java.sql.Date;
public class Dog extends Pet {
private String tricks;
public String getTricks() {return tricks;
}
public void setTricks(String tricks) {this.tricks = tricks;
Run the Test and you should see the following results.
*** Query all Pets and Dogs Where pet_id < 10 ***21:59:21,734 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_,pet0_.VERSION as VERSION0_, pet0_.LICENSE as LICENSE0_, pet0_.NAME asNAME0_, pet0_.DESCRIPTION as DESCRIPT5_0_, pet0_.BIRTH_DATE asBIRTH6_0_, pet0_.PRICE as PRICE0_, pet0_1_.TRICKS as TRICKS2_, casewhen pet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not nullthen 0 else -1 end as clazz_ from PET pet0_ left outer join DOG pet0_1_on pet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID<10Hibernate: select pet0_.PET_ID as PET1_0_, pet0_.VERSION as VERSION0_,pet0_.LICENSE as LICENSE0_, pet0_.NAME as NAME0_, pet0_.DESCRIPTION asDESCRIPT5_0_, pet0_.BIRTH_DATE as BIRTH6_0_, pet0_.PRICE as PRICE0_,pet0_1_.TRICKS as TRICKS2_, case when pet0_1_.PET_ID is not null then 1when pet0_.PET_ID is not null then 0 else -1 end as clazz_ from PETpet0_ left outer join DOG pet0_1_ on pet0_.PET_ID=pet0_1_.PET_ID wherepet0_.PET_ID<1021:59:21,750 DEBUG LongType:172 - returning '1' as column: PET1_0_21:59:21,750 DEBUG IntegerType:172 - returning '1' as column: clazz_21:59:21,750 DEBUG IntegerType:172 - returning '3' as column: VERSION0_21:59:21,765 DEBUG StringType:172 - returning 'LIC00000' as column:LICENSE0_21:59:21,765 DEBUG StringType:172 - returning 'Fido' as column: NAME0_21:59:21,765 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_21:59:21,765 DEBUG DateType:172 - returning '04 January 1992' ascolumn: BIRTH6_0_21:59:21,765 DEBUG BigDecimalType:172 - returning '19.95' as column:PRICE0_21:59:21,765 DEBUG StringType:172 - returning 'Sit, Play Dead' ascolumn: TRICKS2_21:59:21,781 DEBUG LongType:172 - returning '2' as column: PET1_0_21:59:21,781 DEBUG IntegerType:172 - returning '1' as column: clazz_21:59:21,781 DEBUG IntegerType:172 - returning '2' as column: VERSION0_21:59:21,781 DEBUG StringType:172 - returning 'LIC11111' as column:LICENSE0_21:59:21,781 DEBUG StringType:172 - returning 'ERROR' as column: NAME0_21:59:21,781 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_21:59:21,781 DEBUG DateType:172 - returning '05 February 1994' ascolumn: BIRTH6_0_21:59:21,781 DEBUG BigDecimalType:172 - returning '119.95' as column:PRICE0_21:59:21,781 DEBUG StringType:172 - returning 'Sit, Roll Over' ascolumn: TRICKS2_21:59:21,781 DEBUG LongType:172 - returning '3' as column: PET1_0_21:59:21,781 DEBUG IntegerType:172 - returning '1' as column: clazz_21:59:21,781 DEBUG IntegerType:172 - returning '1' as column: VERSION0_21:59:21,781 DEBUG StringType:172 - returning 'LIC12222' as column:LICENSE0_
153
21:59:21,781 DEBUG StringType:172 - returning 'Fluffy' as column:NAME0_21:59:21,781 DEBUG StringType:172 - returning 'Cat' as column:DESCRIPT5_0_21:59:21,781 DEBUG DateType:172 - returning '04 May 1998' as column:BIRTH6_0_21:59:21,781 DEBUG BigDecimalType:172 - returning '29.95' as column:PRICE0_21:59:21,781 DEBUG StringType:172 - returning 'Eat, Sleep' as column:TRICKS2_21:59:21,781 DEBUG LongType:172 - returning '4' as column: PET1_0_21:59:21,781 DEBUG IntegerType:172 - returning '1' as column: clazz_21:59:21,781 DEBUG IntegerType:172 - returning '1' as column: VERSION0_21:59:21,781 DEBUG StringType:172 - returning 'LIC33333' as column:LICENSE0_21:59:21,781 DEBUG StringType:172 - returning 'Goldie' as column:NAME0_21:59:21,781 DEBUG StringType:172 - returning 'Fish' as column:DESCRIPT5_0_21:59:21,796 DEBUG DateType:172 - returning '03 November 2001' ascolumn: BIRTH6_0_21:59:21,796 DEBUG BigDecimalType:172 - returning '39.95' as column:PRICE0_21:59:21,796 DEBUG StringType:172 - returning 'Eat, Swim' as column:TRICKS2_21:59:21,796 DEBUG LongType:172 - returning '5' as column: PET1_0_21:59:21,796 DEBUG IntegerType:172 - returning '1' as column: clazz_21:59:21,796 DEBUG IntegerType:172 - returning '1' as column: VERSION0_21:59:21,796 DEBUG StringType:172 - returning 'LIC44444' as column:LICENSE0_21:59:21,796 DEBUG StringType:172 - returning 'Slinky' as column:NAME0_21:59:21,796 DEBUG StringType:172 - returning 'Snake' as column:DESCRIPT5_0_21:59:21,796 DEBUG DateType:172 - returning '10 December 2002' ascolumn: BIRTH6_0_21:59:21,796 DEBUG BigDecimalType:172 - returning '49.95' as column:PRICE0_21:59:21,796 DEBUG StringType:172 - returning 'Sleep, Eat' as column:TRICKS2_21:59:21,796 DEBUG LongType:172 - returning '6' as column: PET1_0_21:59:21,796 DEBUG IntegerType:172 - returning '0' as column: clazz_21:59:21,796 DEBUG IntegerType:172 - returning '1' as column: VERSION0_21:59:21,796 DEBUG StringType:172 - returning 'LIC55555' as column:LICENSE0_21:59:21,796 DEBUG StringType:172 - returning 'Spot' as column: NAME0_21:59:21,796 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_21:59:21,796 DEBUG DateType:172 - returning '15 June 2004' as column:BIRTH6_0_
154
21:59:21,796 DEBUG BigDecimalType:172 - returning '40.95' as column:PRICE0_21:59:21,796 DEBUG LongType:172 - returning '7' as column: PET1_0_21:59:21,796 DEBUG IntegerType:172 - returning '0' as column: clazz_21:59:21,796 DEBUG IntegerType:172 - returning '1' as column: VERSION0_21:59:21,796 DEBUG StringType:172 - returning 'LIC66666' as column:LICENSE0_21:59:21,796 DEBUG StringType:172 - returning 'Inky' as column: NAME0_21:59:21,796 DEBUG StringType:172 - returning 'Cat' as column:DESCRIPT5_0_21:59:21,796 DEBUG DateType:172 - returning '24 January 2006' ascolumn: BIRTH6_0_21:59:21,796 DEBUG BigDecimalType:172 - returning '110.95' as column:PRICE0_21:59:21,796 DEBUG LongType:172 - returning '8' as column: PET1_0_21:59:21,796 DEBUG IntegerType:172 - returning '0' as column: clazz_21:59:21,796 DEBUG IntegerType:172 - returning '1' as column: VERSION0_21:59:21,796 DEBUG StringType:172 - returning 'LIC77777' as column:LICENSE0_21:59:21,796 DEBUG StringType:172 - returning 'Bubbles' as column:NAME0_21:59:21,796 DEBUG StringType:172 - returning 'Fish' as column:DESCRIPT5_0_21:59:21,796 DEBUG DateType:172 - returning '14 February 1992' ascolumn: BIRTH6_0_21:59:21,796 DEBUG BigDecimalType:172 - returning '16.95' as column:PRICE0_21:59:21,796 DEBUG LongType:172 - returning '9' as column: PET1_0_21:59:21,796 DEBUG IntegerType:172 - returning '0' as column: clazz_21:59:21,796 DEBUG IntegerType:172 - returning '1' as column: VERSION0_21:59:21,796 DEBUG StringType:172 - returning 'LIC88888' as column:LICENSE0_21:59:21,796 DEBUG StringType:172 - returning 'Arson' as column: NAME0_21:59:21,796 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_21:59:21,796 DEBUG DateType:172 - returning '14 March 1991' as column:BIRTH6_0_21:59:21,812 DEBUG BigDecimalType:172 - returning '10.95' as column:PRICE0_
for (Object pet : crit.list()) {System.out.println(pet);
}
// Select Pets with price < 12 and id > 1System.out.println("*** Criteria and query for price < 13 and " +"pet_id > 1 ***");crit = s.createCriteria(Pet.class)
.add(Restrictions.and(Restrictions.lt("price",
new BigDecimal("13.00")),Restrictions.gt("pet_id",
new Long(1))));
for (Object pet : crit.list()) {System.out.println(pet);
}
// Select Pets with price < 13 and// pet_id > 1 using conjunctionSystem.out.println(
new Integer("15")));crit2.add(Restrictions.eq("i.pet_id",
new Long (1)) );for (Object pet : crit.list()) {
System.out.println(pet);}
162
// Eager join on inventory recordsSystem.out.println(
"*** Eager join on Inventory Records ***");crit = s.createCriteria(Pet.class)
.setFetchMode("inventoryRecords",FetchMode.JOIN);
for (Object pet : crit.list()) {System.out.println(((Pet)pet).
getInventoryRecords().size());}
System.out.println("*** Regular query on Inventory for quantity " +">= 15 and pet.pet_id = 1 ***");
Query q = s.createQuery("SELECT inv FROM Inventory inv JOIN inv.pet i " +"WHERE quantity >= 25 AND i.pet_id = 1" );
for (Object pet : q.list()) {System.out.println(pet);
}
// Example querySystem.out.println(
"*** Example Query for Rollins ***");Pet pi = new Pet();pi.setName("Rollins");Example ex = Example.create(pi);crit = s.createCriteria(Pet.class).add(ex);for (Object pet : crit.list()) {
*** Criteria query for all Pets ***18:34:06,546 DEBUG SQL:401 - select this_.PET_ID as PET1_0_0_,this_.VERSION as VERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAMEas NAME0_0_, this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE asBIRTH6_0_0_, this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_,case when this_1_.PET_ID is not null then 1 when this_.PET_ID is notnull then 0 else -1 end as clazz_0_ from PET this_ left outer join DOGthis_1_ on this_.PET_ID=this_1_.PET_IDHibernate: select this_.PET_ID as PET1_0_0_, this_.VERSION asVERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAME as NAME0_0_,this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE as BIRTH6_0_0_,this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_, case whenthis_1_.PET_ID is not null then 1 when this_.PET_ID is not null then 0else -1 end as clazz_0_ from PET this_ left outer join DOG this_1_ onthis_.PET_ID=this_1_.PET_ID18:34:06,546 DEBUG LongType:172 - returning '1' as column: PET1_0_0_18:34:06,546 DEBUG IntegerType:172 - returning '1' as column: clazz_0_18:34:06,546 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,546 DEBUG StringType:172 - returning 'LIC00000' as column:LICENSE0_0_18:34:06,546 DEBUG StringType:172 - returning 'Fido' as column:NAME0_0_18:34:06,546 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_18:34:06,561 DEBUG DateType:172 - returning '04 January 1992' ascolumn: BIRTH6_0_0_18:34:06,561 DEBUG BigDecimalType:172 - returning '19.95' as column:PRICE0_0_18:34:06,561 DEBUG StringType:172 - returning 'Sit, Play Dead' ascolumn: TRICKS2_0_18:34:06,561 DEBUG LongType:172 - returning '2' as column: PET1_0_0_18:34:06,561 DEBUG IntegerType:172 - returning '1' as column: clazz_0_18:34:06,561 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,561 DEBUG StringType:172 - returning 'LIC11111' as column:LICENSE0_0_18:34:06,561 DEBUG StringType:172 - returning 'Rex' as column: NAME0_0_18:34:06,561 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_18:34:06,577 DEBUG DateType:172 - returning '05 February 1994' ascolumn: BIRTH6_0_0_18:34:06,577 DEBUG BigDecimalType:172 - returning '119.95' as column:PRICE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Sit, Roll Over' ascolumn: TRICKS2_0_
164
18:34:06,577 DEBUG LongType:172 - returning '3' as column: PET1_0_0_18:34:06,577 DEBUG IntegerType:172 - returning '1' as column: clazz_0_18:34:06,577 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,577 DEBUG StringType:172 - returning 'LIC12222' as column:LICENSE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Fluffy' as column:NAME0_0_18:34:06,577 DEBUG StringType:172 - returning 'Cat' as column:DESCRIPT5_0_0_18:34:06,577 DEBUG DateType:172 - returning '04 May 1998' as column:BIRTH6_0_0_18:34:06,577 DEBUG BigDecimalType:172 - returning '29.95' as column:PRICE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Eat, Sleep' as column:TRICKS2_0_18:34:06,577 DEBUG LongType:172 - returning '4' as column: PET1_0_0_18:34:06,577 DEBUG IntegerType:172 - returning '1' as column: clazz_0_18:34:06,577 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,577 DEBUG StringType:172 - returning 'LIC33333' as column:LICENSE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Goldie' as column:NAME0_0_18:34:06,577 DEBUG StringType:172 - returning 'Fish' as column:DESCRIPT5_0_0_18:34:06,577 DEBUG DateType:172 - returning '03 November 2001' ascolumn: BIRTH6_0_0_18:34:06,577 DEBUG BigDecimalType:172 - returning '39.95' as column:PRICE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Eat, Swim' as column:TRICKS2_0_18:34:06,577 DEBUG LongType:172 - returning '5' as column: PET1_0_0_18:34:06,577 DEBUG IntegerType:172 - returning '1' as column: clazz_0_18:34:06,577 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,577 DEBUG StringType:172 - returning 'LIC44444' as column:LICENSE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Slinky' as column:NAME0_0_18:34:06,577 DEBUG StringType:172 - returning 'Snake' as column:DESCRIPT5_0_0_18:34:06,577 DEBUG DateType:172 - returning '10 December 2002' ascolumn: BIRTH6_0_0_18:34:06,577 DEBUG BigDecimalType:172 - returning '49.95' as column:PRICE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Sleep, Eat' as column:TRICKS2_0_
165
18:34:06,577 DEBUG LongType:172 - returning '6' as column: PET1_0_0_18:34:06,577 DEBUG IntegerType:172 - returning '0' as column: clazz_0_18:34:06,577 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,577 DEBUG StringType:172 - returning 'LIC55555' as column:LICENSE0_0_18:34:06,577 DEBUG StringType:172 - returning 'Spot' as column:NAME0_0_18:34:06,577 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_18:34:06,577 DEBUG DateType:172 - returning '15 June 2004' as column:BIRTH6_0_0_18:34:06,577 DEBUG BigDecimalType:172 - returning '40.95' as column:PRICE0_0_18:34:06,577 DEBUG LongType:172 - returning '7' as column: PET1_0_0_18:34:06,592 DEBUG IntegerType:172 - returning '0' as column: clazz_0_18:34:06,592 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,592 DEBUG StringType:172 - returning 'LIC66666' as column:LICENSE0_0_18:34:06,592 DEBUG StringType:172 - returning 'Inky' as column:NAME0_0_18:34:06,592 DEBUG StringType:172 - returning 'Cat' as column:DESCRIPT5_0_0_18:34:06,592 DEBUG DateType:172 - returning '24 January 2006' ascolumn: BIRTH6_0_0_18:34:06,592 DEBUG BigDecimalType:172 - returning '110.95' as column:PRICE0_0_18:34:06,592 DEBUG LongType:172 - returning '8' as column: PET1_0_0_18:34:06,592 DEBUG IntegerType:172 - returning '0' as column: clazz_0_18:34:06,592 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,592 DEBUG StringType:172 - returning 'LIC77777' as column:LICENSE0_0_18:34:06,592 DEBUG StringType:172 - returning 'Bubbles' as column:NAME0_0_18:34:06,592 DEBUG StringType:172 - returning 'Fish' as column:DESCRIPT5_0_0_18:34:06,592 DEBUG DateType:172 - returning '14 February 1992' ascolumn: BIRTH6_0_0_18:34:06,592 DEBUG BigDecimalType:172 - returning '16.95' as column:PRICE0_0_18:34:06,592 DEBUG LongType:172 - returning '9' as column: PET1_0_0_18:34:06,592 DEBUG IntegerType:172 - returning '0' as column: clazz_0_18:34:06,592 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,592 DEBUG StringType:172 - returning 'LIC88888' as column:LICENSE0_0_18:34:06,592 DEBUG StringType:172 - returning 'Arson' as column:NAME0_0_
166
18:34:06,592 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_18:34:06,592 DEBUG DateType:172 - returning '14 March 1991' as column:BIRTH6_0_0_18:34:06,592 DEBUG BigDecimalType:172 - returning '10.95' as column:PRICE0_0_18:34:06,592 DEBUG LongType:172 - returning '10' as column: PET1_0_0_18:34:06,592 DEBUG IntegerType:172 - returning '0' as column: clazz_0_18:34:06,592 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:34:06,592 DEBUG StringType:172 - returning 'LIC99999' as column:LICENSE0_0_18:34:06,592 DEBUG StringType:172 - returning 'Rollins' as column:NAME0_0_18:34:06,592 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_18:34:06,592 DEBUG DateType:172 - returning '24 April 1992' as column:BIRTH6_0_0_18:34:06,592 DEBUG BigDecimalType:172 - returning '120.95' as column:PRICE0_0_pets.Dog@1, Pet_ID: 1, Name: Fido, Description: Dog, Price: 19.95, Dateof Birth: 1992-01-04Tricks: Sit, Play Deadpets.Dog@2, Pet_ID: 2, Name: Rex, Description: Dog, Price: 119.95, Dateof Birth: 1994-02-05Tricks: Sit, Roll Overpets.Dog@3, Pet_ID: 3, Name: Fluffy, Description: Cat, Price: 29.95,Date of Birth: 1998-05-04Tricks: Eat, Sleeppets.Dog@4, Pet_ID: 4, Name: Goldie, Description: Fish, Price: 39.95,Date of Birth: 2001-11-03Tricks: Eat, Swimpets.Dog@5, Pet_ID: 5, Name: Slinky, Description: Snake, Price: 49.95,Date of Birth: 2002-12-10Tricks: Sleep, Eatpets.Pet@6, Pet_ID: 6, Name: Spot, Description: Dog, Price: 40.95, Dateof Birth: 2004-06-15pets.Pet@7, Pet_ID: 7, Name: Inky, Description: Cat, Price: 110.95,Date of Birth: 2006-01-24pets.Pet@8, Pet_ID: 8, Name: Bubbles, Description: Fish, Price: 16.95,Date of Birth: 1992-02-14pets.Pet@9, Pet_ID: 9, Name: Arson, Description: Dog, Price: 10.95,Date of Birth: 1991-03-14pets.Pet@a, Pet_ID: 10, Name: Rollins, Description: Dog, Price: 120.95,Date of Birth: 1992-04-24
167
*** Criteria query Pet for pet_id = 1 ***18:34:06,639 DEBUG SQL:401 - select this_.PET_ID as PET1_0_0_,this_.VERSION as VERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAMEas NAME0_0_, this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE asBIRTH6_0_0_, this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_,case when this_1_.PET_ID is not null then 1 when this_.PET_ID is notnull then 0 else -1 end as clazz_0_ from PET this_ left outer join DOGthis_1_ on this_.PET_ID=this_1_.PET_ID where this_.PET_ID = ?Hibernate: select this_.PET_ID as PET1_0_0_, this_.VERSION asVERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAME as NAME0_0_,this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE as BIRTH6_0_0_,this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_, case whenthis_1_.PET_ID is not null then 1 when this_.PET_ID is not null then 0else -1 end as clazz_0_ from PET this_ left outer join DOG this_1_ onthis_.PET_ID=this_1_.PET_ID where this_.PET_ID = ?18:34:06,639 DEBUG LongType:133 - binding '1' to parameter: 118:34:06,639 DEBUG LongType:172 - returning '1' as column: PET1_0_0_pets.Dog@1, Pet_ID: 1, Name: Fido, Description: Dog, Price: 19.95, Dateof Birth: 1992-01-04Tricks: Sit, Play Dead*** Criteria query Pet for license = LIC22222 ***18:34:06,639 DEBUG SQL:401 - select this_.PET_ID as PET1_0_0_,this_.VERSION as VERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAMEas NAME0_0_, this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE asBIRTH6_0_0_, this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_,case when this_1_.PET_ID is not null then 1 when this_.PET_ID is notnull then 0 else -1 end as clazz_0_ from PET this_ left outer join DOGthis_1_ on this_.PET_ID=this_1_.PET_ID where this_.LICENSE=?Hibernate: select this_.PET_ID as PET1_0_0_, this_.VERSION asVERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAME as NAME0_0_,this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE as BIRTH6_0_0_,this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_, case whenthis_1_.PET_ID is not null then 1 when this_.PET_ID is not null then 0else -1 end as clazz_0_ from PET this_ left outer join DOG this_1_ onthis_.PET_ID=this_1_.PET_ID where this_.LICENSE=?18:34:06,639 DEBUG StringType:133 - binding 'LIC22222' to parameter: 1*** Criteria and query for price < 13 and pet_id > 1 ***18:34:06,655 DEBUG SQL:401 - select this_.PET_ID as PET1_0_0_,this_.VERSION as VERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAMEas NAME0_0_, this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE asBIRTH6_0_0_, this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_,case when this_1_.PET_ID is not null then 1 when this_.PET_ID is notnull then 0 else -1 end as clazz_0_ from PET this_ left outer join DOGthis_1_ on this_.PET_ID=this_1_.PET_ID where (this_.PRICE<? andthis_.PET_ID>?)
168
Hibernate: select this_.PET_ID as PET1_0_0_, this_.VERSION asVERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAME as NAME0_0_,this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE as BIRTH6_0_0_,this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_, case whenthis_1_.PET_ID is not null then 1 when this_.PET_ID is not null then 0else -1 end as clazz_0_ from PET this_ left outer join DOG this_1_ onthis_.PET_ID=this_1_.PET_ID where (this_.PRICE<? and this_.PET_ID>?)18:34:06,655 DEBUG BigDecimalType:133 - binding '13.00' to parameter: 118:34:06,655 DEBUG LongType:133 - binding '1' to parameter: 218:34:06,655 DEBUG LongType:172 - returning '9' as column: PET1_0_0_pets.Pet@9, Pet_ID: 9, Name: Arson, Description: Dog, Price: 10.95,Date of Birth: 1991-03-14*** Criteria conjunction query for price < 13 and pet_id > 1 ***18:34:06,671 DEBUG SQL:401 - select this_.PET_ID as PET1_0_0_,this_.VERSION as VERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAMEas NAME0_0_, this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE asBIRTH6_0_0_, this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_,case when this_1_.PET_ID is not null then 1 when this_.PET_ID is notnull then 0 else -1 end as clazz_0_ from PET this_ left outer join DOGthis_1_ on this_.PET_ID=this_1_.PET_ID where (this_.PRICE<? andthis_.PET_ID>?)Hibernate: select this_.PET_ID as PET1_0_0_, this_.VERSION asVERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAME as NAME0_0_,this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE as BIRTH6_0_0_,this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_, case whenthis_1_.PET_ID is not null then 1 when this_.PET_ID is not null then 0else -1 end as clazz_0_ from PET this_ left outer join DOG this_1_ onthis_.PET_ID=this_1_.PET_ID where (this_.PRICE<? and this_.PET_ID>?)18:34:06,671 DEBUG BigDecimalType:133 - binding '13.00' to parameter: 118:34:06,671 DEBUG LongType:133 - binding '1' to parameter: 218:34:06,671 DEBUG LongType:172 - returning '9' as column: PET1_0_0_pets.Pet@9, Pet_ID: 9, Name: Arson, Description: Dog, Price: 10.95,Date of Birth: 1991-03-14
169
*** createAlias query on Inventory for quantity >= 15 and pet.pet_id =1 ***18:34:06,686 DEBUG SQL:401 - select this_.INVENTORY_ID asINVENTORY1_3_1_, this_.VERSION as VERSION3_1_, this_.location aslocation3_1_, this_.quantity as quantity3_1_, this_.PET_ID asPET5_3_1_, i1_.PET_ID as PET1_0_0_, i1_.VERSION as VERSION0_0_,i1_.LICENSE as LICENSE0_0_, i1_.NAME as NAME0_0_, i1_.DESCRIPTION asDESCRIPT5_0_0_, i1_.BIRTH_DATE as BIRTH6_0_0_, i1_.PRICE as PRICE0_0_,i1_1_.TRICKS as TRICKS2_0_, case when i1_1_.PET_ID is not null then 1when i1_.PET_ID is not null then 0 else -1 end as clazz_0_ fromINVENTORY this_ inner join PET i1_ on this_.PET_ID=i1_.PET_ID leftouter join DOG i1_1_ on i1_.PET_ID=i1_1_.PET_ID where this_.quantity>=?and i1_.PET_ID=?Hibernate: select this_.INVENTORY_ID as INVENTORY1_3_1_, this_.VERSIONas VERSION3_1_, this_.location as location3_1_, this_.quantity asquantity3_1_, this_.PET_ID as PET5_3_1_, i1_.PET_ID as PET1_0_0_,i1_.VERSION as VERSION0_0_, i1_.LICENSE as LICENSE0_0_, i1_.NAME asNAME0_0_, i1_.DESCRIPTION as DESCRIPT5_0_0_, i1_.BIRTH_DATE asBIRTH6_0_0_, i1_.PRICE as PRICE0_0_, i1_1_.TRICKS as TRICKS2_0_, casewhen i1_1_.PET_ID is not null then 1 when i1_.PET_ID is not null then 0else -1 end as clazz_0_ from INVENTORY this_ inner join PET i1_ onthis_.PET_ID=i1_.PET_ID left outer join DOG i1_1_ oni1_.PET_ID=i1_1_.PET_ID where this_.quantity>=? and i1_.PET_ID=?18:34:06,686 DEBUG IntegerType:133 - binding '15' to parameter: 118:34:06,686 DEBUG LongType:133 - binding '1' to parameter: 218:34:06,686 DEBUG LongType:172 - returning '1' as column: PET1_0_0_18:34:06,686 DEBUG LongType:172 - returning '2' as column:INVENTORY1_3_1_18:34:06,686 DEBUG IntegerType:172 - returning '1' as column:VERSION3_1_18:34:06,686 DEBUG StringType:172 - returning 'Ft Worth' as column:location3_1_18:34:06,686 DEBUG IntegerType:172 - returning '20' as column:quantity3_1_18:34:06,686 DEBUG LongType:172 - returning '1' as column: PET5_3_1_Inventory: 1, Ft Worth, 20
170
*** createCriteria join on Inventory for quantity >= 15 and pet.pet_id= 1 ***18:34:06,686 DEBUG SQL:401 - select this_.INVENTORY_ID asINVENTORY1_3_1_, this_.VERSION as VERSION3_1_, this_.location aslocation3_1_, this_.quantity as quantity3_1_, this_.PET_ID asPET5_3_1_, i1_.PET_ID as PET1_0_0_, i1_.VERSION as VERSION0_0_,i1_.LICENSE as LICENSE0_0_, i1_.NAME as NAME0_0_, i1_.DESCRIPTION asDESCRIPT5_0_0_, i1_.BIRTH_DATE as BIRTH6_0_0_, i1_.PRICE as PRICE0_0_,i1_1_.TRICKS as TRICKS2_0_, case when i1_1_.PET_ID is not null then 1when i1_.PET_ID is not null then 0 else -1 end as clazz_0_ fromINVENTORY this_ inner join PET i1_ on this_.PET_ID=i1_.PET_ID leftouter join DOG i1_1_ on i1_.PET_ID=i1_1_.PET_ID where this_.quantity>=?and i1_.PET_ID=?Hibernate: select this_.INVENTORY_ID as INVENTORY1_3_1_, this_.VERSIONas VERSION3_1_, this_.location as location3_1_, this_.quantity asquantity3_1_, this_.PET_ID as PET5_3_1_, i1_.PET_ID as PET1_0_0_,i1_.VERSION as VERSION0_0_, i1_.LICENSE as LICENSE0_0_, i1_.NAME asNAME0_0_, i1_.DESCRIPTION as DESCRIPT5_0_0_, i1_.BIRTH_DATE asBIRTH6_0_0_, i1_.PRICE as PRICE0_0_, i1_1_.TRICKS as TRICKS2_0_, casewhen i1_1_.PET_ID is not null then 1 when i1_.PET_ID is not null then 0else -1 end as clazz_0_ from INVENTORY this_ inner join PET i1_ onthis_.PET_ID=i1_.PET_ID left outer join DOG i1_1_ oni1_.PET_ID=i1_1_.PET_ID where this_.quantity>=? and i1_.PET_ID=?18:34:06,702 DEBUG IntegerType:133 - binding '15' to parameter: 118:34:06,702 DEBUG LongType:133 - binding '1' to parameter: 218:34:06,702 DEBUG LongType:172 - returning '1' as column: PET1_0_0_18:34:06,702 DEBUG LongType:172 - returning '2' as column:INVENTORY1_3_1_Inventory: 1, Ft Worth, 20
171
*** Eager join on Inventory Records ***18:34:06,702 DEBUG SQL:401 - select this_.PET_ID as PET1_0_1_,this_.VERSION as VERSION0_1_, this_.LICENSE as LICENSE0_1_, this_.NAMEas NAME0_1_, this_.DESCRIPTION as DESCRIPT5_0_1_, this_.BIRTH_DATE asBIRTH6_0_1_, this_.PRICE as PRICE0_1_, this_1_.TRICKS as TRICKS2_1_,case when this_1_.PET_ID is not null then 1 when this_.PET_ID is notnull then 0 else -1 end as clazz_1_, inventoryr2_.PET_ID as PET5_3_,inventoryr2_.INVENTORY_ID as INVENTORY1_3_, inventoryr2_.INVENTORY_IDas INVENTORY1_3_0_, inventoryr2_.VERSION as VERSION3_0_,inventoryr2_.location as location3_0_, inventoryr2_.quantity asquantity3_0_, inventoryr2_.PET_ID as PET5_3_0_ from PET this_ leftouter join DOG this_1_ on this_.PET_ID=this_1_.PET_ID left outer joinINVENTORY inventoryr2_ on this_.PET_ID=inventoryr2_.PET_IDHibernate: select this_.PET_ID as PET1_0_1_, this_.VERSION asVERSION0_1_, this_.LICENSE as LICENSE0_1_, this_.NAME as NAME0_1_,this_.DESCRIPTION as DESCRIPT5_0_1_, this_.BIRTH_DATE as BIRTH6_0_1_,this_.PRICE as PRICE0_1_, this_1_.TRICKS as TRICKS2_1_, case whenthis_1_.PET_ID is not null then 1 when this_.PET_ID is not null then 0else -1 end as clazz_1_, inventoryr2_.PET_ID as PET5_3_,inventoryr2_.INVENTORY_ID as INVENTORY1_3_, inventoryr2_.INVENTORY_IDas INVENTORY1_3_0_, inventoryr2_.VERSION as VERSION3_0_,inventoryr2_.location as location3_0_, inventoryr2_.quantity asquantity3_0_, inventoryr2_.PET_ID as PET5_3_0_ from PET this_ leftouter join DOG this_1_ on this_.PET_ID=this_1_.PET_ID left outer joinINVENTORY inventoryr2_ on this_.PET_ID=inventoryr2_.PET_ID18:34:06,702 DEBUG LongType:172 - returning '1' as column:INVENTORY1_3_0_18:34:06,702 DEBUG LongType:172 - returning '1' as column: PET1_0_1_18:34:06,702 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,717 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,717 DEBUG IntegerType:172 - returning '10' as column:quantity3_0_18:34:06,717 DEBUG LongType:172 - returning '1' as column: PET5_3_0_18:34:06,717 DEBUG LongType:172 - returning '1' as column: PET5_3_18:34:06,717 DEBUG LongType:172 - returning '1' as column:INVENTORY1_3_18:34:06,717 DEBUG LongType:172 - returning '2' as column:INVENTORY1_3_0_18:34:06,717 DEBUG LongType:172 - returning '1' as column: PET1_0_1_18:34:06,717 DEBUG LongType:172 - returning '1' as column: PET5_3_18:34:06,717 DEBUG LongType:172 - returning '2' as column:INVENTORY1_3_18:34:06,717 DEBUG LongType:172 - returning '3' as column:INVENTORY1_3_0_
172
18:34:06,717 DEBUG LongType:172 - returning '2' as column: PET1_0_1_18:34:06,717 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,717 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,717 DEBUG IntegerType:172 - returning '15' as column:quantity3_0_18:34:06,717 DEBUG LongType:172 - returning '2' as column: PET5_3_0_18:34:06,717 DEBUG LongType:172 - returning '2' as column: PET5_3_18:34:06,717 DEBUG LongType:172 - returning '3' as column:INVENTORY1_3_18:34:06,717 DEBUG LongType:172 - returning '4' as column:INVENTORY1_3_0_18:34:06,717 DEBUG LongType:172 - returning '3' as column: PET1_0_1_18:34:06,717 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '5' as column:quantity3_0_18:34:06,733 DEBUG LongType:172 - returning '3' as column: PET5_3_0_18:34:06,733 DEBUG LongType:172 - returning '3' as column: PET5_3_18:34:06,733 DEBUG LongType:172 - returning '4' as column:INVENTORY1_3_18:34:06,733 DEBUG LongType:172 - returning '5' as column:INVENTORY1_3_0_18:34:06,733 DEBUG LongType:172 - returning '4' as column: PET1_0_1_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '8' as column:quantity3_0_18:34:06,733 DEBUG LongType:172 - returning '4' as column: PET5_3_0_18:34:06,733 DEBUG LongType:172 - returning '4' as column: PET5_3_18:34:06,733 DEBUG LongType:172 - returning '5' as column:INVENTORY1_3_18:34:06,733 DEBUG LongType:172 - returning '6' as column:INVENTORY1_3_0_18:34:06,733 DEBUG LongType:172 - returning '5' as column: PET1_0_1_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '18' as column:quantity3_0_18:34:06,733 DEBUG LongType:172 - returning '5' as column: PET5_3_0_18:34:06,733 DEBUG LongType:172 - returning '5' as column: PET5_3_18:34:06,733 DEBUG LongType:172 - returning '6' as column:INVENTORY1_3_
173
18:34:06,733 DEBUG LongType:172 - returning '7' as column:INVENTORY1_3_0_18:34:06,733 DEBUG LongType:172 - returning '6' as column: PET1_0_1_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '3' as column:quantity3_0_18:34:06,733 DEBUG LongType:172 - returning '6' as column: PET5_3_0_18:34:06,733 DEBUG LongType:172 - returning '6' as column: PET5_3_18:34:06,733 DEBUG LongType:172 - returning '7' as column:INVENTORY1_3_18:34:06,733 DEBUG LongType:172 - returning '8' as column:INVENTORY1_3_0_18:34:06,733 DEBUG LongType:172 - returning '7' as column: PET1_0_1_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '21' as column:quantity3_0_18:34:06,733 DEBUG LongType:172 - returning '7' as column: PET5_3_0_18:34:06,733 DEBUG LongType:172 - returning '7' as column: PET5_3_18:34:06,733 DEBUG LongType:172 - returning '8' as column:INVENTORY1_3_18:34:06,733 DEBUG LongType:172 - returning '9' as column:INVENTORY1_3_0_18:34:06,733 DEBUG LongType:172 - returning '8' as column: PET1_0_1_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '4' as column:quantity3_0_18:34:06,733 DEBUG LongType:172 - returning '8' as column: PET5_3_0_18:34:06,733 DEBUG LongType:172 - returning '8' as column: PET5_3_18:34:06,733 DEBUG LongType:172 - returning '9' as column:INVENTORY1_3_18:34:06,733 DEBUG LongType:172 - returning '10' as column:INVENTORY1_3_0_18:34:06,733 DEBUG LongType:172 - returning '9' as column: PET1_0_1_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_
174
18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '2' as column:quantity3_0_18:34:06,733 DEBUG LongType:172 - returning '9' as column: PET5_3_0_18:34:06,733 DEBUG LongType:172 - returning '9' as column: PET5_3_18:34:06,733 DEBUG LongType:172 - returning '10' as column:INVENTORY1_3_18:34:06,733 DEBUG LongType:172 - returning '11' as column:INVENTORY1_3_0_18:34:06,733 DEBUG LongType:172 - returning '10' as column: PET1_0_1_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:34:06,733 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:34:06,733 DEBUG IntegerType:172 - returning '1' as column:quantity3_0_18:34:06,749 DEBUG LongType:172 - returning '10' as column: PET5_3_0_18:34:06,749 DEBUG LongType:172 - returning '10' as column: PET5_3_18:34:06,749 DEBUG LongType:172 - returning '11' as column:INVENTORY1_3_22111111111
175
*** Regular query on Inventory for quantity >= 15 and pet.pet_id = 1***18:34:06,764 DEBUG SQL:401 - select inventory0_.INVENTORY_ID asINVENTORY1_3_, inventory0_.VERSION as VERSION3_, inventory0_.locationas location3_, inventory0_.quantity as quantity3_, inventory0_.PET_IDas PET5_3_ from INVENTORY inventory0_ inner join PET pet1_ oninventory0_.PET_ID=pet1_.PET_ID where quantity>=25 and pet1_.PET_ID=1Hibernate: select inventory0_.INVENTORY_ID as INVENTORY1_3_,inventory0_.VERSION as VERSION3_, inventory0_.location as location3_,inventory0_.quantity as quantity3_, inventory0_.PET_ID as PET5_3_ fromINVENTORY inventory0_ inner join PET pet1_ oninventory0_.PET_ID=pet1_.PET_ID where quantity>=25 and pet1_.PET_ID=1*** Example Query for Rollins ***18:34:06,780 DEBUG SQL:401 - select this_.PET_ID as PET1_0_0_,this_.VERSION as VERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAMEas NAME0_0_, this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE asBIRTH6_0_0_, this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_,case when this_1_.PET_ID is not null then 1 when this_.PET_ID is notnull then 0 else -1 end as clazz_0_ from PET this_ left outer join DOGthis_1_ on this_.PET_ID=this_1_.PET_ID where (this_.NAME=?)Hibernate: select this_.PET_ID as PET1_0_0_, this_.VERSION asVERSION0_0_, this_.LICENSE as LICENSE0_0_, this_.NAME as NAME0_0_,this_.DESCRIPTION as DESCRIPT5_0_0_, this_.BIRTH_DATE as BIRTH6_0_0_,this_.PRICE as PRICE0_0_, this_1_.TRICKS as TRICKS2_0_, case whenthis_1_.PET_ID is not null then 1 when this_.PET_ID is not null then 0else -1 end as clazz_0_ from PET this_ left outer join DOG this_1_ onthis_.PET_ID=this_1_.PET_ID where (this_.NAME=?)18:34:06,780 DEBUG StringType:133 - binding 'Rollins' to parameter: 118:34:06,780 DEBUG LongType:172 - returning '10' as column: PET1_0_0_pets.Pet@a, Pet_ID: 10, Name: Rollins, Description: Dog, Price: 120.95,Date of Birth: 1992-04-24
176
Lab 22 – JPA
Download and Install from www.hibernate.org:
hibernate-annotations-3.2.1.GA.zip
hibernate-entitymanager-3.2.1.GA.zip
Add the following 2 JAR files to the User Library from c:\hibernate-3.2\lib.
public Set getInventoryRecords() {return inventoryRecords;
}
public void setInventoryRecords(Set inventoryRecords) {this.inventoryRecords = inventoryRecords;
}
public void addInventoryRecord(String location, int quantity) {Inventory inv = new Inventory(location, quantity);inv.setPet(this);getInventoryRecords().add(inv);
}
}
187
Create a new class named TestJPA and add the following.
Run the Test and you should see the following results.
*** Session connect status: true18:54:06,796 DEBUG SQL:401 - select pet0_.PET_ID as PET1_0_0_,pet0_.VERSION as VERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAMEas NAME0_0_, pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE asBIRTH6_0_0_, pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_,case when pet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is notnull then 0 else -1 end as clazz_0_ from PET pet0_ left outer join DOGpet0_1_ on pet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?18:54:06,796 DEBUG LongType:133 - binding '1' to parameter: 118:54:06,812 DEBUG IntegerType:172 - returning '1' as column: clazz_0_18:54:06,812 DEBUG IntegerType:172 - returning '1' as column:VERSION0_0_18:54:06,812 DEBUG StringType:172 - returning 'LIC00000' as column:LICENSE0_0_18:54:06,812 DEBUG StringType:172 - returning 'Fido' as column:NAME0_0_18:54:06,812 DEBUG StringType:172 - returning 'Dog' as column:DESCRIPT5_0_0_18:54:06,828 DEBUG DateType:172 - returning '04 January 1992' ascolumn: BIRTH6_0_0_18:54:06,828 DEBUG BigDecimalType:172 - returning '19.95' as column:PRICE0_0_18:54:06,828 DEBUG StringType:172 - returning 'Sit, Play Dead' ascolumn: TRICKS2_0_18:54:06,875 DEBUG SQL:401 - select inventoryr0_.PET_ID as PET5_1_,inventoryr0_.INVENTORY_ID as INVENTORY1_1_, inventoryr0_.INVENTORY_IDas INVENTORY1_3_0_, inventoryr0_.VERSION as VERSION3_0_,inventoryr0_.location as location3_0_, inventoryr0_.quantity asquantity3_0_, inventoryr0_.PET_ID as PET5_3_0_ from INVENTORYinventoryr0_ where inventoryr0_.PET_ID=?Hibernate: select inventoryr0_.PET_ID as PET5_1_,inventoryr0_.INVENTORY_ID as INVENTORY1_1_, inventoryr0_.INVENTORY_IDas INVENTORY1_3_0_, inventoryr0_.VERSION as VERSION3_0_,inventoryr0_.location as location3_0_, inventoryr0_.quantity asquantity3_0_, inventoryr0_.PET_ID as PET5_3_0_ from INVENTORYinventoryr0_ where inventoryr0_.PET_ID=?18:54:06,890 DEBUG LongType:133 - binding '1' to parameter: 118:54:06,890 DEBUG LongType:172 - returning '1' as column:INVENTORY1_3_0_18:54:06,890 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_
196
18:54:06,890 DEBUG StringType:172 - returning 'Dallas' as column:location3_0_18:54:06,906 DEBUG IntegerType:172 - returning '10' as column:quantity3_0_18:54:06,906 DEBUG LongType:172 - returning '1' as column: PET5_3_0_18:54:06,906 DEBUG LongType:172 - returning '1' as column: PET5_1_18:54:06,906 DEBUG LongType:172 - returning '1' as column:INVENTORY1_1_18:54:06,906 DEBUG LongType:172 - returning '2' as column:INVENTORY1_3_0_18:54:06,906 DEBUG IntegerType:172 - returning '1' as column:VERSION3_0_18:54:06,906 DEBUG StringType:172 - returning 'Ft Worth' as column:location3_0_18:54:06,906 DEBUG IntegerType:172 - returning '20' as column:quantity3_0_18:54:06,906 DEBUG LongType:172 - returning '1' as column: PET5_3_0_18:54:06,906 DEBUG LongType:172 - returning '1' as column: PET5_1_18:54:06,906 DEBUG LongType:172 - returning '2' as column:INVENTORY1_1_Inventory: 1, Ft Worth, 20Inventory: 1, Dallas, 10After commit session open state = false
197
Lab 24 – JNDI, Connection Pool, Web Application and Hibernate
Create a simple DBCP Connection Pool in Tomcat.
DBCP uses the Jakarta-Commons Database Connection Pool. It relies on number ofJakarta-Commons components:
Jakarta-Commons DBCP Jakarta-Commons Collections Jakarta-Commons Pool
Copy the derbyclient.jar file to C:\apache-tomcat-5.5.26\common\lib.
198
Start the Tomcat Server.
199
Add the Project to the Server.
200
Add the Project.
201
Restart Tomcat.
202
Open server.xml in the Servers folder and go to the bottom of the file to find thefollowing.
Run the Servlet on the Server and you should see the following.
222
And in the Consloe.
ConnectIn HibernateAppListener.contextInitializedIn HibernateAppListener, Class.forName for utils.HibernateUtilsuccessfulHibernate: select pet0_.PET_ID as col_0_0_ from PET pet0_Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,
223
pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?Hibernate: select pet0_.PET_ID as PET1_0_0_, pet0_.VERSION asVERSION0_0_, pet0_.LICENSE as LICENSE0_0_, pet0_.NAME as NAME0_0_,pet0_.DESCRIPTION as DESCRIPT5_0_0_, pet0_.BIRTH_DATE as BIRTH6_0_0_,pet0_.PRICE as PRICE0_0_, pet0_1_.TRICKS as TRICKS2_0_, case whenpet0_1_.PET_ID is not null then 1 when pet0_.PET_ID is not null then 0else -1 end as clazz_0_ from PET pet0_ left outer join DOG pet0_1_ onpet0_.PET_ID=pet0_1_.PET_ID where pet0_.PET_ID=?