-
MySQL Cluster 7.1.5 binaries released
Posted on August 23rd, 2010 No comments
The binary version for MySQL Cluster 7.1.5 has now been made available at http://www.mysql.com/downloads/cluster/A description of all of the changes (fixes) that have gone into MySQL Cluster 7.1.5 (compared to 7.1.4) can be found in the MySQL Cluster 7.1.5 Change Log.
-
Upcoming webinar: MySQL Cluster deployment best practices
Posted on August 2nd, 2010 No commentsOn Wednesday 25 August, Johan Anderson and Mat keep will be presenting a free webinar on the best practices for deploying MySQL Cluster. If you’d like to attend then just register here.
Johan has years of MySQL Cluster professional services experience – and so if you’re interested in deploying a product ready MySQL Cluster database then this is a must-view session. Even if you can’t make it live, register anyway and you’ll be sent a link to the recording and charts afterwards.
Content
An invaluable session for those who are about to, or who already have, deployed MySQL Cluster. Delivered by the lead MySQL Cluster professional services consultant in Oracle, this session will present best practices on deploying MySQL Cluster in order to accelerate time to service with the highest levels of availability and performance to support your most critical web and telecoms applications.
The session will cover:
- identifying suitable applications for MySQL Cluster
- comparing differences in functionality and configuration with InnoDB
- using triggers and stored procedures to implement foreign key functionality
- hardware, networking and file system selection
- dimensioning and capacity planning
- configuration best practices
- disk data deployment
- administration and monitoring
- services available to get started
WHEN
Wednesday, August 25, 2010: 09:00 Pacific time (America)Wed, Aug 25: 06:00 Hawaii timeWed, Aug 25: 10:00 Mountain time (America)Wed, Aug 25: 11:00 Central time (America)Wed, Aug 25: 12:00 Eastern time (America)Wed, Aug 25: 16:00 UTCWed, Aug 25: 17:00 Western European timeWed, Aug 25: 18:00 Central European timeWed, Aug 25: 19:00 Eastern European time -
Install, configure and run MySQL Cluster – demo video
Posted on July 23rd, 2010 4 commentsThere is a new video available: Demonstration of installing, configuring and running MySQL Cluster (LINUX) to accompany the MySQL Cluster Quick Start guides. The Flash video video lasts for about 7 minutes.
If you aren’t able to view Flash on your device then a (poorer quality) version is included here – watch the Flash version if you’re able to!
-
MySQL Cluster presentation at Oracle Open World 2010
Posted on June 28th, 2010 No comments
As part of “MySQL Sunday” at this year’s Oracle Open World, Mat Keep and I will be presenting on the latest MySQL Cluster features. We’ll be presenting at 15:30 (Pacific Time) on 19th September (the event starts with a key note at 12:30).If you’re attending Oracle Open World then please indicate that you’d like to attend the MySQL Sunday when you register. If you aren’t planning to go to Oracle Open World but will be in the San Francisco area then buying a Discover pass (only $50 if you register by 16 July) will get you into the MySQL Sunday sessions. Register here.
-
Breakfast seminar on what’s new with MySQL – London
Posted on June 17th, 2010 No commentsIf you’re in London on Thursday 24th June then there’s a great chance to find out what’s new in MySQL.

Join us for an Oracle MySQL Breakfast Seminar to better understand Oracle’s MySQL strategy and what’s new with MySQL!
Agenda:
09:00 a.m. Welcome Coffee/Tea
09:30 a.m. Oracle’s MySQL Strategy
10:00 a.m. What’s New – The MySQL Server & MySQL Cluster
10.45 a.m. Coffee/Tea Break
11:00 a.m. What’s New – MySQL Enterprise & MySQL Workbench
11:45 a.m. Q&A
12:00 noon End of the Breakfast SeminarCost?
None, it’s a free event! But places are limited and the seminar is held on a first come first served basis, so register quickly!Location:
Sun Microsystem’s Customer Briefing Center
Regis House
45 King William Street
London EC4R 9AN
Tel: (020) 7628 3000Image courtesy of Anirudh Koul.
Join us for an Oracle MySQL Breakfast Seminar in London, Thursday June 24th 2010, to better understand Oracle’s MySQL strategy and what’s new with MySQL!
Agenda: 09:00 a.m. Welcome Coffee/Tea 09:30 a.m. Oracle’s MySQL Strategy 10:00 a.m. What’s New – The MySQL Server & MySQL Cluster 10.45 a.m. Coffee/Tea Break 11:00 a.m. What’s New – MySQL Enterprise & MyQL Workbench 11:45 a.m. Q&A 12:00 noon End of the Breakfast Seminar * Agenda subject to change
Cost?
None, it’s a free event! But places are limited and the seminar is held on a first come first served basis, so register quickly! -
MySQL Cluster Scores with Pyro and Cell C at the FIFA World Cup – new case study
Posted on June 9th, 2010 No comments
The Pyro Group has selected the MySQL Cluster database to power their InRoam SDP (Service Delivery Platform). InRoam enables Cell C and their network partners to provide low cost, border-less mobile communications services to hundreds of thousands of football fans from around the world as they descend on South Africa for the 2010 FIFA World Cup tournament.This new case study can be downloaded from http://www.mysql.com/why-mysql/case-studies/mysql_cs-pyro_telecoms.php
Solution Overview
- Pyro InRoam SDP is an intelligent application enabling subscribers to communicate with ease across borders
- Migrated from a Microsoft platform with SQL Server to offer greater choice and less restrictive licensing
- MySQL Cluster selected to power the SDP as a result of high transactional throughput, low latency, carrier-grade availability and low cost
- MySQL Cluster database supports 7 million roaming subscribers per day, performing 1,000 reads or 500 writes per second on up to 1TB of data accessed over SQL and the native NDB C++ API
MySQL Cluster Scores with Pyro and Cell C at the FIFA World Cup -
Configure MySQL Enterprise Monitor to monitor MySQL Cluster
Posted on May 20th, 2010 No comments
MySQL Cluster 7.1 introduced the ndbinfo database which contains views giving real-time access to a whole host of information that helps you monitor and tune your MySQL Cluster deployment. Because this data can be accessed through regular SQL, various systems can be configured to monitor the Cluster. This post gives one example, extending MySQL Enterprise Monitor to keep an eye on the amount of free memory on the data nodes (through a graph) and then raise an alarm when it starts to run low – even generating SNMP traps if that’s what you need.One of the features of MySQL Enterprise Monitor is that you can define custom data collectors and that those data collectors can run SQL queries to get the data. The information retrieved by those custom data collectors can then be used with rules that the user defines through the MySQL Enterprise Monitor GUI to create warning/alarms.
In this example, I create two new data collectors in the file”<MySQL Enterprise Monitor installation directory>/agent/share/mysql-proxy/items/cluster.xml” before starting up the MySQL Enterprise Monitor agent (note that these should be created for the agent of each MySQL Server in the Cluster that you would like to use to present the information from the data nodes):
cluster.xml:
<?xml version="1.0" encoding="utf-8"?> <classes> <class> <namespace>mysql</namespace> <classname>cluster_max_used</classname> <query><![CDATA[SELECT MAX(used) AS Used FROM ndbinfo.memoryusage WHERE memory_type = 'Data Memory';]]></query> </class> <class> <namespace>mysql</namespace> <classname>cluster_min_avail</classname> <query><![CDATA[SELECT MIN(total) AS Total FROM ndbinfo.memoryusage WHERE memory_type = 'Data Memory';]]></query> </class> </classes>So that the agent picks up this file, it should be referenced within <MySQL Enterprise Monitor installation directory>/agent/mysql-monitor-agent.ini:
agent-item-files = share/mysql-monitor-agent/items/quan.lua,share/mysql-monitor-agent/items/items-mysql-monitor.xml, share/mysql-monitor-agent/items/custom.xml,share/mysql-monitor-agent/items/cluster.xmlIn MySQL Enterprise Monitor, events are raised by rules. Rules are grouped together into Advisors and so I create a new Advisor called “MySQL Cluster” and then create just one new rule within that Advisor group.
As shown in Fig. 1 the rule is called “Data Node Low Memory”. The “Variable Assignment” section is used to define 2 variables %used_mem% and %config_mem% which are populated from the Used and Total results from the 2 new data collectors. The “Expression” section is used to test “((Total - Used)/Total)x100< THRESHOLD” and then the values to be substituted for THRESHOLD are defined in the “Thresholds” section – indicating at what points the Info, Warning and Critical Alters should be raised.
There are then a number of optional sections that you can use to add useful information to the person investigating the alert.
Once the rule has been created, the next step is to schedule and (if desired) tag that the alerts should also result in SNMP traps being raised. This is standard MySQL Enterprise Monitor practice and so it isn’t explained here except to point out that this rule is monitoring information from the data nodes but the rule has to be applied to a MySQL Server in the Cluster (MySQL Enterprise Monitor has no idea what a data node is) and so you need to schedule the rule against one or more arbitrary MySQL Server instances in the Cluster).
To test the functionality, start adding more data to your MySQL Cluster until the Warning alert is triggered as shown in Fig. 2. As you can see, the optional information we included is shown – including values from Used and Total.
I then add more data to the database until the critical alert is raised and confirm that it’s displayed on the main monitoring panel of the MySQL Enterprise Monitor dashboard. Note that if you requested these alerts be included with the SNMP feed then SNMP traps will also be raised.
Please note that this example is intended to illustrate the mechanics of setting up monitoring on an arbitrary piece of data from ndbinfo and obviously in the real world you would want to monitor more than just the memory and even for the memory, you might want to use a more sophisticated rule.
It is sometimes more useful to see how a value changes over time. For this, MySQL Enterprise Monitor provides graphs. The data collectors created for the rule can also be used to add a new graph to Enterprise monitor. The graph is defined by creating the following file:
<com_mysql_merlin_server_graph_Design> <version>1.0</version> <uuid>b0bc2bba-ea9b-102b-b396-94aca32b0b28</uuid> <tag></tag> <name>Per Data Node Data Memory Use</name> <rangeLabel>MB</rangeLabel> <frequency>00:01:00</frequency> <series> <label>Used</label> <expression>cluster_data_node_used_data_memory/1024/1024</expression> </series> <series> <label>Avail</label> <expression>cluster_data_node_config_data_memory/1024/1024</expression> </series> <variables> <name>cluster_data_node_used_data_memory</name> <dcItem> <nameSpace>mysql</nameSpace> <className>cluster_max_used</className> <attribName>Used</attribName> </dcItem> <instance>local</instance> </variables> <variables> <name>cluster_data_node_config_data_memory</name> <dcItem> <nameSpace>mysql</nameSpace> <className>cluster_min_avail</className> <attribName>Total</attribName> </dcItem> <instance>local</instance> </variables> </com_mysql_merlin_server_graph_Design>
Click on Import/Export in the Graphs tab in Enterprise Monitor (2.2) and then import the file defining the graph.
The graph will then appear on the graphs tab and can also be configured to appear on the main dashboard as shown in Fig. 5
-
Free webinar – learn about MySQL Cluster 7.1
Posted on April 29th, 2010 No comments
MySQL Cluster 7.1 was declared GA earlier this month and today (29 April) you have the chance to learn all about it by registering for this free webinar.In blazing speed we will cover the most important features of MySQL Cluster 7.1: NDB$INFO; MySQL Cluster Connector/Java and other features that push the limits of MySQL Cluster into new workloads and communities.
NDB$INFO presents real-time usage statistics from the MySQL Cluster data nodes as a series of SQL tables, enabling developers and administrators to monitor database performance and optimize their applications.
Designed for Java developers, the MySQL Cluster Connector for Java implements an easy-to-use and high performance native Java interface and OpenJPA plug-in that maps Java classes to tables stored in the MySQL Cluster database.
It’s worth registering even if you can’t attend as you should then receive a link to the replay and the charts.
It starts at 9:00 Pacific / 5 pm UK / 6pm CET.
-
MySQL Cluster 7.1 is GA
Posted on April 13th, 2010 1 commentMySQL Cluster 7.1 has been declared GA – including MySQL Cluster Connector for Java and MySQL Cluster Manager – see http://www.mysql.com/products/database/cluster/ for details.
-
Using ClusterJPA (part of MySQL Cluster Connector for Java) – a tutorial
Posted on March 31st, 2010 3 commentsThis is a follow up to the earlier post Using ClusterJ (part of MySQL Cluster Connector for Java) – a tutorial but covers the ClusterJPA interface rather than ClusterJ.
JPA is the Java standard for persistence and different vendors can implement their own implementation of this API and they can (and do) add proprietary extensions. Three of the most common implementations are OpenJPA, Hibernate and Toplink. JPA can be used within server containers or outside of them (i.e. with either J2EE or J2SE).
Typically a JPA implementation would access the database (for example, MySQL Cluster) using JDBC. JDBC gives a great deal of flexibility to the JPA implementer but it cannot give the best performance when using MySQL Cluster as there is an internal conversion to SQL by Connector/J and a subsequent translation from SQL to the C++ NDB API by the MySQL Server. As of MySQL Cluster 7.1, OpenJPA can be configured to use the high performance NDB API (via ClusterJ) for most operations but fall back on JDBC for more complex queries.
The first implementation of ClusterJPA is as an OpenJPA BrokerFactory but in the future, it may be extended to work with other JPA implementations.
ClusterJPA overcomes ClusterJ limitations, notably:
- Persistent classes
- Relationships
- Joins in queries
- Lazy loading
- Table and index creation from object model
Typically users base their selection of a JPA solution on factors such as proprietary extensions, what existing applications already use and (increasingly with ClusterJPA) performance.
The performance of ClusterJPA (OpenJPA using ClusterJ) has been compared with OpenJPA using JDBC in Figure 2. It should be noted that the performance is significantly better when using ClusterJPA (the yellow bar). It is hoped that in the future the performance can be improved even further for finds, updates and deletes.
Adapting an OpenJPA based application to use ClusterJPA with MySQL Cluster should be fairly straight-forward with the main change being in the definition of the persistence unit in persistence.xml:
<persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <persistence-unit name="clusterdb" transaction-type="RESOURCE_LOCAL“> <provider> org.apache.openjpa.persistence.PersistenceProviderImpl </provider> <class>Employee</class> <class>Department</class> <properties> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" /> <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" /> <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/clusterdb" /> <property name="openjpa.ConnectionUserName" value="root" /> <property name="openjpa.ConnectionPassword" value="" /> <property name="openjpa.BrokerFactory" value="ndb" /> <property name="openjpa.jdbc.DBDictionary" value="TableType=ndbcluster" /> <property name="openjpa.ndb.connectString" value="localhost:1186" /> <property name="openjpa.ndb.database" value="clusterdb" / </properties> </persistence-unit> </persistence>Defining the object-to-table mappings is performed by annotating the persistent class for the domain object. If not already in existence, OpenJPA will create the table. The property openjpa.jdbc.DBDictionary tells OpenJPA to create the tables using ndb as the storage engine.
This paper does not go into the use of JPA in great depth – focusing instead on the specifics of using OpenJPA with MySQL Cluster/ClusterJPA. For more information on the use of JPA and OpenJPA, refer to http://openjpa.apache.org/ and in particular, http://openjpa.apache.org/builds/latest/docs/manual/manual.html
The tutorials are using MySQL Cluster 7.1.2a on Fedora 12. If using earlier or more recent versions of MySQL Cluster then you may need to change the class-paths as explained in http://dev.mysql.com/doc/ndbapi/en/mccj-using-jpa.html
For this tutorial, it is necessary to have MySQL Cluster up and running. For simplicity all of the nodes (processes) making up the Cluster will be run on the same physical host, along with the application.
Although most of the database access is performed through the NDB API, the Cluster includes a MySQL Server process for OpenJPA to use for complex queries and to allow the user to check the contents of the database manually.
These are the MySQL Cluster configuration files being used :
config.ini:
[ndbd default] noofreplicas=2 datadir=/home/billy/mysql/my_cluster/data [ndbd] hostname=localhost id=3 [ndbd] hostname=localhost id=4 [ndb_mgmd] id = 1 hostname=localhost datadir=/home/billy/mysql/my_cluster/data [mysqld] hostname=localhost id=101 [api] hostname=localhostmy.cnf:
[mysqld] ndbcluster datadir=/home/billy/mysql/my_cluster/data basedir=/usr/local/mysqlThis tutorial focuses on ClusterJPA rather than on running MySQL Cluster; if you are new to MySQL Cluster then refer to Running a simple Cluster before trying these tutorials.
JPA/OpenJPA/ClusterJPA can be used within or outside a container (i.e. it can be used with J2EE or J2SE) – for simplicity, this tutorial does not use a container (i.e. it is written using J2SE).
Before being able to run any ClusterJPA code, you first need to download and install OpenJPA from http://openjpa.apache.org/ – this tutorial uses OpenJPA 1.2.1. Simply extract the contents of the binary tar ball to the host you want to run your application on; for this tutorial, I use /usr/local/openjpa.
Additionally, ClusterJPA must sometimes use JDBC to satisfy certain queries and so “JDBC Driver for MySQL (Connector/J)” should also be installed – this can be downloaded from http://dev.mysql.com/downloads/connector/j/ Again, simply extract the contents of the tar ball, for this tutorial the files are stored in /usr/local/connectorj and version 5.1.12 is used.
If the ClusterJ tutorial has already been run on this MySQL Cluster database then drop the tables from the cluster so that you can observe them being created automatically – though in a real application, you may prefer to create them manually.
A configuration file is required to indicate how persistence is to be handled for the application. Create a new directory called META-INF in the application source directory and within there create a file called persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <persistence-unit name="clusterdb" transaction-type="RESOURCE_LOCAL"> <provider> org.apache.openjpa.persistence.PersistenceProviderImpl </provider> <class>Employee</class> <class>Department</class> <properties> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" /> <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" /> <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/clusterdb" /> <property name="openjpa.ConnectionUserName" value="root" /> <property name="openjpa.ConnectionPassword" value="" /> <property name="openjpa.BrokerFactory" value="ndb" /> <property name="openjpa.jdbc.DBDictionary" value="TableType=ndb"/> <property name="openjpa.ndb.connectString" value="localhost:1186" /> <property name="openjpa.ndb.database" value="clusterdb" /> </properties> </persistence-unit> </persistence>A persistence unit called ‘clusterdb’ is created; the provider (implementation for the persistence) is set to openjpa (as opposed for example to hibernate). Two classes are specified – ‘Employee’ and ‘Department’ which relate to the persistent classes that the application will define. Connector/J is defined as the JDBC connection (together with the host and the port of the MySQL Server to be used). The key to having OpenJPA use ClusterJPA is to set the BrokerFactory to ndb and specify the connect string (host:port) for the MySQL Cluster management node. The database is defined to be ‘clusterdb’ for both the JDBC and ClusterJ connections. The engine type when creating tables is set to ndb.
If not already done so, create the ‘clusterdb’ database (if it already contains tables from the ClusterJ tutorial then drop them):
mysql> create database clusterdb;The next step is to create the persistent class definitions for the Department and Employee Entities:
Department.java:
import javax.persistence.*; @Entity(name = "department") public class Department { private int Id; private String Site; public Department(){} @Id public int getId() {return Id;} public void setId(int id) {Id=id;} @Column(name="location") public String getSite() {return Site;} public void setSite(String site) {Site=site;} public String toString() { return "Department: " + getId() + " based in " + getSite(); } }Using the @Entity tag, the table name is specified to be ‘department’. Note that unlike ClusterJ, ClusterJPA uses persistent classes (rather than interfaces) and so it is necessary to define the properties as well as the getter/setter methods. The primary key is defined using the @Id tag and we specify that the column associated with the Site property should be called ‘location’ using the @Column tag.
As this is a class, it is possible to add other useful methods – in this case toString().
Employee.java:
import javax.persistence.*; @Entity(name = "employee") //Name of the table public class Employee { private int Id; private String First; private String Last; private String City; private String Started; private String Ended; private int Department; public Employee(){} @Id public int getId() {return Id;} public void setId(int id) {Id=id;} public String getFirst() {return First;} public void setFirst(String first) {First=first;} public String getLast() {return Last;} public void setLast(String last) {Last=last;} @Column(name="municipality") public String getCity() {return City;} public void setCity(String city) {City=city;} public String getStarted() {return Started;} public void setStarted(String date) {Started=date;} public String getEnded() {return Ended;} public void setEnded(String date) {Ended=date;} public int getDepartment() {return Department;} public void setDepartment(int department) {Department=department;} public String toString() { return getFirst() + " " + getLast() + " (Dept " + getDepartment()+ ") from " + getCity() + " started on " + getStarted() + " & left on " + getEnded(); } }The next step is to write the application code which we step through here block by block; the first of which simply contains the import statements and then:
Main.java (part 1):
import java.util.List; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import javax.persistence.Query; import java.io.*;public class Main {public static void main (String[] args) throws java.io.IOException {EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("clusterdb"); EntityManager em = entityManagerFactory.createEntityManager(); EntityTransaction userTransaction = em.getTransaction();BufferedReader br = new BufferedReader(new InputStreamReader(System.in));System.out.println("The tables will now have been created - check through SQL."); System.out.println("mysql> use clusterdb;"); System.out.println("mysql> show tables;"); System.out.println("Hit return when you are done"); String ignore = br.readLine();As part of creating the EntityManagerFactory and EntityManager, OpenJPA creates the tables for the two classes specified for the ‘clusterdb’ persistence unit. While the application waits for the user to press return, this can be checked:
mysql> use clusterdb mysql> show tables; +---------------------+ | Tables_in_clusterdb | +---------------------+ | department | | employee | +---------------------+After hitting return, the application can create an Employee object and then persist it – at which point it will be stored in the ‘employee’ table. A second Employee object is then created and populated with the data read back from the database (using a primary key look up on the Id property with a value of 1):
Main.java (part 2):
userTransaction.begin(); Employee emp = new Employee(); emp.setId(1); emp.setDepartment(666); emp.setFirst("Billy"); emp.setLast("Fish"); emp.setStarted("1st February 2009"); em.persist(emp); userTransaction.commit();userTransaction.begin(); Employee theEmployee = em.find(Employee.class, 1); userTransaction.commit();System.out.println(theEmployee.toString());System.out.println("Chance to check the database before City is set"); System.out.println("Hit return when you are done"); ignore = br.readLine();The Employee object read back from the database is displayed:
Billy Fish (Dept 666) from null started on 1st February 2009 & left on null Chance to check the database before City is set Hit return when you are doneAt this point, the application waits to give the user a chance to confirm that the Employee really has been written to the database:
mysql> select * from employee; +----+--------------+------------+-------+-------+------+-------------------+ | id | municipality | department | ended | first | last | started | +----+--------------+------------+-------+-------+------+-------------------+ | 1 | NULL | 666 | NULL | Billy | Fish | 1st February 2009 | +----+--------------+------------+-------+-------+------+-------------------+After hitting return, the application continues and an update is made to the persisted Employee object – note that there is no need to explicitly ask for the changes to be persisted, this happens automatically when the transaction is committed:
Main.java (part 3):
userTransaction.begin(); theEmployee.setCity("London"); theEmployee.setDepartment(777); userTransaction.commit();System.out.println("Chance to check the City is set in the database"); System.out.println("Hit return when you are done"); ignore = br.readLine();At this point, the application again waits while the user has a chance to confirm that the changes did indeed get written through to the database:
mysql> select * from employee; +----+--------------+------------+-------+-------+------+-------------------+ | id | municipality | department | ended | first | last | started | +----+--------------+------------+-------+-------+------+-------------------+ | 1 | London | 777 | NULL | Billy | Fish | 1st February 2009 | +----+--------------+------------+-------+-------+------+-------------------+When allowed to continue, the application creates and persists an additional 100 Employee & Department entities. It then goes on to create and execute a query to find all employees with a department number of 777 and then looks up the location of the site for that department.
Main.java (part 4):
Department dept;userTransaction.begin(); for (int i=700;i<800;i++) { emp = new Employee(); dept = new Department(); emp.setId(i+1000); emp.setDepartment(i); emp.setFirst("Billy"); emp.setLast("No-Mates-"+i); emp.setStarted("1st February 2009"); em.persist(emp); dept.setId(i); dept.setSite("Building-"+i); em.persist(dept); } userTransaction.commit();userTransaction.begin();Query q = em.createQuery("select x from Employee x where x.department=777"); Query qd;for (Employee m : (List<Employee>) q.getResultList()) { System.out.println(m.toString()); qd = em.createQuery("select x from Department x where x.id=777"); for (Department d : (List<Department>) qd.getResultList()) { System.out.println(d.toString()); } } userTransaction.commit();These are the results displayed:
Billy No-Mates-777 (Dept 777) from null started on 1st February 2009 & left on null Department: 777 based in Building-777 Billy Fish (Dept 777) from London started on 1st February 2009 & left on null Department: 777 based in Building-777Note that joins between tables are possible with JPA but that is beyond the scope of this tutorial.
Finaly, the EntityManager and EntityManagerFactory are closed:
Main.java (part 5):
em.close(); entityManagerFactory.close(); } }Compiling and running the ClusterJPA tutorial code
javac -classpath /usr/local/mysql/share/mysql/java/clusterjpa.jar:/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/geronimo-jpa_3.0_spec-1.0.jar:. Main.java Employee.java Department.javajava -Djava.library.path=/usr/local/mysql/lib/ -classpath /usr/local/mysql/share/mysql/java/clusterjpa.jar:/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/*:/usr/local/connectorj/mysql-connector-java-5.1.12-bin.jar:. Main
Download the source code for this tutorial from here (together with the code for the previous ClusterJ tutorial).










