vb.net generate 2d barcode OBJECT RELATIONAL MAPPING WITH HIBERNATE in Java

Paint PDF 417 in Java OBJECT RELATIONAL MAPPING WITH HIBERNATE

CHAPTER 4 OBJECT RELATIONAL MAPPING WITH HIBERNATE
Encoding PDF417 In Java
Using Barcode creator for Java Control to generate, create PDF417 image in Java applications.
www.OnBarcode.com
PDF417 Reader In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Listing 4-19. Track POJO package com.integrallis.techconf.domain; ... public class Track implements Serializable { ... // primary key private Integer id; // fields private String title; private String subtitle; private String description; // tracks belong to a conference private Conference conference; // constructors public Track() { } // getters and setters ... public Conference getConference() { return conference; } public void setConference(Conference conference) { this.conference = conference; } ... }
Making 2D In Java
Using Barcode generator for Java Control to generate, create 2D image in Java applications.
www.OnBarcode.com
GS1 DataBar-14 Printer In Java
Using Barcode generation for Java Control to generate, create GS1 DataBar-14 image in Java applications.
www.OnBarcode.com
Testing Conference and Tracks
Barcode Generation In Java
Using Barcode drawer for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Encoding UCC - 12 In Java
Using Barcode generation for Java Control to generate, create UPC-A image in Java applications.
www.OnBarcode.com
Before we delve into testing the mappings we just created, let s take a look at a Hibernate configuration file tailored to test the mappings for the classes shown in Figure 4-13. Listing 4-20 shows a Hibernate XML configuration file that does the equivalent of what we have done until now in Java code. This Hibernate configuration file is showing all of the mappings for the TechConf application. Most Hibernate applications use the XML format for their configurations, and it is the recommended way to configure Hibernate in your application. For a single database application, this file is usually named hibernate.cfg.xml.
Paint Linear In Java
Using Barcode creation for Java Control to generate, create Linear image in Java applications.
www.OnBarcode.com
International Standard Book Number Encoder In Java
Using Barcode encoder for Java Control to generate, create International Standard Book Number image in Java applications.
www.OnBarcode.com
CHAPTER 4 OBJECT RELATIONAL MAPPING WITH HIBERNATE
Generating PDF417 In None
Using Barcode printer for Office Excel Control to generate, create PDF417 image in Microsoft Excel applications.
www.OnBarcode.com
PDF 417 Maker In .NET
Using Barcode creation for Reporting Service Control to generate, create PDF417 image in Reporting Service applications.
www.OnBarcode.com
Listing 4-20. Hibernate XML Configuration File < xml version="1.0" encoding="utf-8" > <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <!-- =================================================================== --> <!-- SessionFactory used for Testing --> <!-- =================================================================== --> <session-factory> <property name="hibernate.connection.url"> jdbc:mysql://localhost/test</property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="hibernate.connection.username">yourUserName</property> <property name="hibernate.connection.password">yourPassword</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">true</property> <!-- =================================================================== --> <!-- Mappings --> <!-- =================================================================== --> <mapping resource="com/integrallis/techconf/domain/Abstract.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/AbstractStatus.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Address.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Answer.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/AttendeeGroup.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/BlogLink.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Booth.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/ChoiceAnswer.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Conference.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/News.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Presentation.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/PresentationLevel.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/PresentationTopic.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/PresentationType.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/PricingRule.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Question.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/QuestionChoice.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Questionnaire.hbm.xml" />
EAN13 Encoder In Java
Using Barcode creator for Android Control to generate, create EAN / UCC - 13 image in Android applications.
www.OnBarcode.com
Painting Barcode In .NET Framework
Using Barcode creator for Visual Studio .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
CHAPTER 4 OBJECT RELATIONAL MAPPING WITH HIBERNATE
Printing Barcode In Java
Using Barcode printer for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
Drawing USS Code 128 In None
Using Barcode maker for Online Control to generate, create Code 128A image in Online applications.
www.OnBarcode.com
<mapping resource="com/integrallis/techconf/domain/QuestionType.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Reminder.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Role.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Room.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/ScheduleEntry.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Session.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Track.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/User.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/UserRole.hbm.xml" /> <mapping resource="com/integrallis/techconf/domain/Venue.hbm.xml" /> </session-factory> </hibernate-configuration>
ECC200 Drawer In None
Using Barcode creation for Online Control to generate, create ECC200 image in Online applications.
www.OnBarcode.com
Code 39 Full ASCII Printer In None
Using Barcode generator for Office Excel Control to generate, create USS Code 39 image in Office Excel applications.
www.OnBarcode.com
Note The Hibernate configuration file shown in Listing 4-20 references all of the mappings in the TechConf application. If you are coding along for the example at hand, you can comment out the mappings that have not been created yet to have a working Hibernate XML configuration.
UPC-A Maker In Java
Using Barcode drawer for Android Control to generate, create UPC Symbol image in Android applications.
www.OnBarcode.com
Print ANSI/AIM Code 39 In Objective-C
Using Barcode encoder for iPad Control to generate, create Code 3 of 9 image in iPad applications.
www.OnBarcode.com
To load the XML configuration you ll need code similar to that shown in Listing 4-21. Listing 4-21. Java Code to Load a Hibernate XML Configuration File File configFile = new File("hibernate.cfg.xml"); Configuration configuration = new Configuration().configure(configFile); SessionFactory factory = configuration.buildSessionFactory(); The code in Listing 4-22 creates a Conference object with its associated Tracks and then persist the Conference to the database. Listing 4-22. Testing the One-To-Many Set Mapping public static void main(String[] args) { File configFile = new File("hibernate.cfg.xml"); Configuration configuration = new Configuration().configure(configFile); SessionFactory factory = configuration.buildSessionFactory(); Session session = null; Transaction tx = null; try { // create a conference Conference conference = new Conference();
Code 39 Extended Drawer In VB.NET
Using Barcode printer for .NET framework Control to generate, create Code-39 image in Visual Studio .NET applications.
www.OnBarcode.com
Scanning UPC-A Supplement 2 In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
CHAPTER 4 OBJECT RELATIONAL MAPPING WITH HIBERNATE
conference.setAbstractSubmissionEndDate(new Date()); conference.setAbstractSubmissionStartDate(new Date()); conference.setDescription("A Test Conference"); conference.setEndDate(new Date()); conference.setName("TestConf 2005"); conference.setStartDate(new Date()); // create some tracks Track jseTrack = new Track(); jseTrack.setDescription( "Learn how to build powerful Java desktop applications"); jseTrack.setSubtitle("Java Standard Edition"); jseTrack.setTitle("JSE"); Track jeeTrack = new Track(); jeeTrack.setDescription( "Learn how to build powerful Enterprise applications"); jeeTrack.setSubtitle("Java Enterprise Edition"); jeeTrack.setTitle("JEE"); Track jmeTrack = new Track(); jmeTrack.setTitle("JME"); jmeTrack.setDescription( "Learn how to bring cellphone and PDAs alive with Java"); jmeTrack.setSubtitle("Java Micro Edition"); // add the tracks to the conference conference.addTrack(jseTrack); conference.addTrack(jeeTrack); conference.addTrack(jmeTrack); // persist the conference session = factory.openSession(); tx = session.beginTransaction(); session.persist(conference); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } } finally { session.close(); } }
CHAPTER 4 OBJECT RELATIONAL MAPPING WITH HIBERNATE
The code in Listing 4-22 will produce output similar to that shown here: Hibernate: insert into conference (AbstractSubmissionStartDate, Name, Description, AbstractSubmissionEndDate, EndDate, StartDate, FK_VENUE_ID) values ( , , , , , , ) Hibernate: insert into track (TITLE, SUBTITLE, DESCRIPTION, FK_CONFERENCE_ID) values ( , , , ) Hibernate: insert into track (TITLE, SUBTITLE, DESCRIPTION, FK_CONFERENCE_ID) values ( , , , ) Hibernate: insert into track (TITLE, SUBTITLE, DESCRIPTION, FK_CONFERENCE_ID) values ( , , , ) As you can see from the sample output, Hibernate produced four SQL INSERTS, one for the Conference object and three for the Track objects. If you take a look back at the mapping shown in Listing 4-17 you ll notice that there is an attribute named cascade with a value of all . In Hibernate every association can have a cascading style. The cascading style tells Hibernate how to treat associated objects in the scope of persistence operations. For example, if you set the cascading style to save-update in a one-to-many association, Hibernate will determine if any of the associated objects are dirty and generate SQL UPDATES for those objects, and similarly it will generate SQL INSERTS for new objects. The values for the cascade attribute are none , persist , merge , delete , save-update , evict , replicate , lock , refresh , delete-orphan , and all . These values can be combined in a comma-separated list and correspond closely to the operations available on the Session class. Consult the Hibernate online reference for an in-depth coverage of cascading behavior and transitive persistence. If you inspect the CONFERENCE and TRACK tables you should output results similar to that shown next. mysql> select PK_ID, NAME from CONFERENCE; +-------+---------------+ | PK_ID | NAME | +-------+---------------+ | 1 | TestConf 2005 | +-------+---------------+ 1 row in set (0.00 sec)mysql> select PK_ID, TITLE, SUBTITLE from TRACK; +-------+-------+-------------------------+ | PK_ID | TITLE | SUBTITLE | +-------+-------+-------------------------+ | 1 | JSE | Java Standard Edition | | 2 | JEE | Java Enterprise Edition | | 3 | JME | Java Micro Edition | +-------+-------+-------------------------+ 3 rows in set (0.00 sec)
Copyright © OnBarcode.com . All rights reserved.