Difference between revisions of "JPA Tools Smoke Test"

From Eclipsepedia

Jump to: navigation, search
Line 20: Line 20:
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
 
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
<!--schema></schema-->
+
<!--schema></schema-->
 
<!--catalog></catalog-->
 
<!--catalog></catalog-->
 
<access>FIELD</access>
 
<access>FIELD</access>
<entity name="EmployeeEntity" class="Employee">
+
<entity name="model.EmployeeEntity" class="model.Employee">
 
    <table name="Employee"/>
 
    <table name="Employee"/>
 
<table-generator name="EMPLOYEE_GENERATOR_TABLE" table="EMP_SEQ" pk-column-name="SEQ_NAME" value-column-name="SEQ_COUNT" pk-column-value="EMP_SEQ"/>
 
<table-generator name="EMPLOYEE_GENERATOR_TABLE" table="EMP_SEQ" pk-column-name="SEQ_NAME" value-column-name="SEQ_COUNT" pk-column-value="EMP_SEQ"/>
Line 29: Line 29:
 
<exclude-superclass-listeners/>
 
<exclude-superclass-listeners/>
 
    <attributes>
 
    <attributes>
<id name="employeeId">
+
<id name="empId">
 
<column name="EMP_ID"/>
 
<column name="EMP_ID"/>
 
<generated-value strategy="TABLE" generator="EMPLOYEE_GENERATOR_TABLE"/>
 
<generated-value strategy="TABLE" generator="EMPLOYEE_GENERATOR_TABLE"/>
 
</id>
 
</id>
<basic name="firstName">
+
<basic name="fName">
 
<column name="F_NAME"/>
 
<column name="F_NAME"/>
 
</basic>
 
</basic>
<basic name="lastName">
+
<basic name="lName">
 
<column name="L_NAME"/>
 
<column name="L_NAME"/>
 
</basic>
 
</basic>
<one-to-many name="phones" target-entity="Phone" mapped-by="empId">
+
<one-to-many name="phones" target-entity="model.Phone" mapped-by="employee">
 
<cascade>
 
<cascade>
 
<cascade-all/>
 
<cascade-all/>

Revision as of 13:25, 21 August 2013

Project creation

  • Create a "New JPA Project"
  • Select the "Generic" Platform and "Java 1.7" facet configuration
  • Set up a DB and library that contains a JPA implementation (this can be Oracle, DB2, MySQL, Sybase, etc...)

Java Source test

  • Create a JPA Entity in the project and add at least 3 attributes
  • Make one of the attributes the Id for the Entity using the JPA Details
  • Verify that the appropriate annotations have been inserted into the Java source

Generate annotated source

  • Right-click on the project and select JPA Tools->Generate Entities from Tables...
  • Examine the generated Entities
  • Edit an @Column name to be wrong and ensure that validation picks up the error

orm.xml test

  • Create a new orm.xml file in the src or meta-inf directory of your Utility project
  • Paste in the following content
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
		<!--schema></schema-->
	<!--catalog></catalog-->
	<access>FIELD</access>
	<entity name="model.EmployeeEntity" class="model.Employee">
	    <table name="Employee"/>
		<table-generator name="EMPLOYEE_GENERATOR_TABLE" table="EMP_SEQ" pk-column-name="SEQ_NAME" value-column-name="SEQ_COUNT" pk-column-value="EMP_SEQ"/>
		<exclude-default-listeners/>
		<exclude-superclass-listeners/>
	    <attributes>
			<id name="empId">
				<column name="EMP_ID"/>
				<generated-value strategy="TABLE" generator="EMPLOYEE_GENERATOR_TABLE"/>
			</id>
			<basic name="fName">
				<column name="F_NAME"/>
			</basic>
			<basic name="lName">
				<column name="L_NAME"/>
			</basic>
			<one-to-many name="phones" target-entity="model.Phone" mapped-by="employee">
				<cascade>
					<cascade-all/>
				</cascade>
			</one-to-many>
	    </attributes>
	</entity>
</entity-mappings>
  • Verify that the JPA structure displays the correct values
  • Edit the firstName mapping and confirm that the file and or UI is updated

Project Explorer

  • Open the Project Explorer view and verify that the content is correct

EclipseLink

  • Perform all of the above steps to test the EclipseLink extension