I don't want to discuss the differences between JDO and JPA, nor the JDO specifications. I just want to give an overview from the perspective of JDO usage and application integration.
1. Download the JDO standard implementation open source package. Currently, mainstream JDO implementations include:
*. TJDO http://tjdo.sf.net
*. Speedo http://speedo.objectweb.org
*. JORM http://jorm.objectweb.org
*. XORM http://xorm.sourceforge.net
*. JPOX http://jpox.sourceforge.net
* OJB http://db.apache.org/ojb/
*. DataNucleus http://www.datanucleus.org/
2. Select DataNucleus as the implementation of JDO, because I personally think that datanucleus has a general O/R Mapping architecture. The front-end supports the JDO/JPA specifications, followed by a variety of data storage platforms (RDBMS, ODBMS, Map-based, Web-based, documents, etc ). and can be directly integrated with distributed databases such as bigtable and hbase. It is really powerful.
* Download the DataNucleus package
* Download the extension plug-in of DataNucleus in eclipse.
3. If you use dataNucleus to connect to the DBMS database (Mysql), add the following jar packages:
Datanucleus-enhancer-3.0.0-m4.jar jdo-api-3.1-SNAPSHOT-20110319.jar datanucleus-api-jdo-3.0.0-m4.jar asm. jar
Mysql-connector-java-5.0.4-bin.jar datanucleus-cache-3.0.0-m2.jar datanucleus-management-1.0.2.jar datanucleus-core-3.0.0-m4.jar
4. Create an entity class and configure the ing file as follows:
Entity class:
@ PersistenceCapable
Public class Person {
@ PrimaryKey
Private String name;
Private int age;
Private String mail;
.......
}
Mapping xml
<Jdo>
<Package name = "com. jdo. data. nucleus. model">
<Class name = "Person">
<Field name = "name" persistence-modifier = "persistent">
<Column length = "100" type = "parmname" text = "parmname"/>
</Field>
<Field name = "age" persistence-modifier = "persistent"/>
<Field name = "mail" persistence-modifier = "persistent"/>
</Class>
</Package>
</Jdo>
5. Create a JDO operation class:
Map <String, String> JDOConfig = new HashMap <String, String> ();
JDOConfig. put ("javax. jdo. PersistenceManagerFactoryClass", "org. datanucleus. api. jdo. JDOPersistenceManagerFactory ");
JDOConfig. put ("javax. jdo. option. ConnectionURL", "jdbc: mysql: // localhost/acegi ");
JDOConfig. put ("javax. jdo. option. ConnectionDriverName", "com. mysql. jdbc. Driver ");
JDOConfig. put ("javax. jdo. option. ConnectionUserName", "root ");
JDOConfig. put ("javax. jdo. option. ConnectionPassword", "root ");
JDOConfig. put ("javax. jdo. option. NontransactionalRead", "true ");
JDOConfig. put ("javax. jdo. option. NontransactionalWrite", "true ");
JDOConfig. put ("datanucleus. autoCreateSchema", "true ");
PersistenceManagerFactory pmf = JDOHelper. getPersistenceManagerFactory (JDOConfig );
PersistenceManager pm = pmf. getPersistenceManager ();
Person person = null;
System. out. println ("Insert iterm into DB .");
// Insert
Person = new Person ("wenhao", 123, "wenhao@gmail.com ");
Pm. makePersistent (person );
// Select
GetPersonsFromDB (pm );
// Update
Person. setMail ("wenhao@sina.com.cn ");
Pm. close ();
Person. setAge (1000 );
System. out. println ("instance level:" + person. getAge ());
Pmf = JDOHelper. getPersistenceManagerFactory (JDOConfig );
Pm = pmf. getPersistenceManager ();
List <Person> updatePersons = getPersonsFromDB (pm );
If (updatePersons! = Null & updatePersons. size ()> 0 ){
For (Person updatePerson: updatePersons)
// Delete
Pm. deletePersistent (updatePerson );
System. out. println ("Delete iterms from DB .");
}
Pm. close ();
// Select
Query q = pm. newQuery ("select from" + Person. class. getName () + "WHERE name = wenhao ");
List <Person> updatePersons = (listmediaq.exe cute ();
6. Run the JDO operation class and the following error will be reported during direct running:
This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced v