Hi,
I'm using XML type columns in some of our DB Tables, therefore I decided to
use:
@Strategy ("org.apache.openjpa.jdbc.meta.strats.XMLValueHandler")
annotation.
According to the documentation this allow me to map the XML columns from and
to Java Classes by using simple JAXB annotations and letting the JPA to
perform the Marshalling/UnMarshalling himself.
I encounter a problem when we try to SELECT from a List inside our annotated
Class, there I got an exception.
Here Is a simple java DTO example (annotated with JAXB) of Employee with 3
fields (employeeId, employeeName and List<EmployeeDetails>):
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"employeeId",
"employeeName",
"employeeDetails",
})
@XmlRootElement(name = "EMPLOYEE ")
publicclassEmployeeDTOimplementsSerializable {
privatestaticfinallongserialVersionUID = 892691919044796049L;
@XmlElement(name = "EMPLOYEE_ID")
private Long employeeCountry;
@XmlElement(name = "EMPLOYEE_NAME ")
private String employeeName;
@XmlElement(name = "EMPLOYEE_DETAILS")
private List <EmployeeDetailsDTO>employeeDetails;
public Long getEmployeeId() {
returnemployeeId;
}
publicvoidsetEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeName() {
returnemployeeName;
}
publicvoidsetEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public List <EmployeeDetailsDTO>getEmployeeDetails() {
returnemployeeDetails;
}
publicvoidsetEmployeeDetails(List <EmployeeDetailsDTO>employeeDetails)
{
this.employeeDetails = employeeDetails;
}
Here is the Employee Details DTO:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"employeeCountry",
"employeeCity",
"employeePhone",
})
@XmlRootElement(name = "EMPLOYEE_DETAILS ")
publicclassEmployeeDetailsDTOimplementsSerializable {
privatestaticfinallongserialVersionUID = 892691919044796049L;
@XmlElement(name = "EMPLOYEE_COUNTRY")
private String employeeCountry;
@XmlElement(name = "EMPLOYEE_CITY ")
private String employeeCity;
@XmlElement(name = "EMPLOYEE_PHONE")
private String employeePhone;
public Long getEmployeeCountry() {
returnemployeeCountry;
}
publicvoidsetEmployeeCountry(String employeeCountry) {
this.employeeCountry = employeeCountry;
}
public String getEmployeeCity() {
returnemployeeCity;
}
publicvoidsetEmployeeCity(String employeeCity) {
this.employeeCity = employeeCity;
}
public String getEmployeePhone() {
returnemployeePhone;
}
publicvoidsetEmployeePhone(String employeePhone) {
this.employeePhone = employeePhone;
}
Entity Example:
@Entity
@Table(name="EMPLOYEEXML")
public class EmployeeEntity implements Serializable {
private staticfinallongserialVersionUID = 1L;
@Id
@SequenceGenerator(name="EMPLOYEEXML_EMPLOYEEID_GENERATOR",
sequenceName="EMPLOYEE_ID")
@GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="EMPLOYEEXML_EMPLOYEEID_GENERATOR")
private Long id;
@Persistent
@Strategy ("org.apache.openjpa.jdbc.meta.strats.XMLValueHandler")
private EmployeeDTO data;
publiccEmployeeEntity() {
}
public Long getId() {
returnthis.id;
}
public void setId(Long id) {
this.id = id;
}
public EmployeeDTO getData() {
returnthis.data;
}
public void setData(EmployeeDTO data) {
this.data = data;
}
Here an example of 2 records inside an xml column in the DB:
<EMPLOYEE>
<EMPLOYEE_ID>1</EMPLOYEE_ID>
<EMPLOYEE_NAME>JACOB JACOBY</EMPLOYEE_NAME>
<EMPLOYEE_DETAILS>
<EMPLOYEE_COUNTRY>FLORIDA</EMPLOYEE_COUNTRY>
<EMPLOYEE_CITY>MIAMI</snifName>
<EMPLOYEE_PHONE>97221234567</EMPLOYEE_PHONE>
</EMPLOYEE_DETAILS>
<EMPLOYEE_DETAILS>
<EMPLOYEE_COUNTRY>FLORIDA</EMPLOYEE_COUNTRY>
<EMPLOYEE_CITY>ORLANDO</snifName>
<EMPLOYEE_PHONE>97247654321</EMPLOYEE_PHONE>
</EMPLOYEE_DETAILS>
<EMPLOYEE_DETAILS>
<EMPLOYEE_COUNTRY>FLORIDA</EMPLOYEE_COUNTRY>
<EMPLOYEE_CITY>OTHER</snifName>
<EMPLOYEE_PHONE>97231234567</EMPLOYEE_PHONE>
</EMPLOYEE_DETAILS>
</EMPLOYEE>
<EMPLOYEE>
<EMPLOYEE_ID>2</EMPLOYEE_ID>
<EMPLOYEE_NAME>MOSES MOSESY</EMPLOYEE_NAME>
<EMPLOYEE_DETAILS>
<EMPLOYEE_COUNTRY>FLORIDA</EMPLOYEE_COUNTRY>
<EMPLOYEE_CITY>MIAMI</snifName>
<EMPLOYEE_PHONE>97221234567</EMPLOYEE_PHONE>
</EMPLOYEE_DETAILS>
<EMPLOYEE_DETAILS>
<EMPLOYEE_COUNTRY>FLORIDA</EMPLOYEE_COUNTRY>
<EMPLOYEE_CITY>OTHER</snifName>
<EMPLOYEE_PHONE>97231234567</EMPLOYEE_PHONE>
</EMPLOYEE_DETAILS>
</EMPLOYEE>
Here are examples of JPQL query we are trying to use:
SELECT e.data FROM EmployeeEntity e WHERE e.data.employeeName = "JACOB" –
[OK]
SELECT e.data FROM EmployeeEntity e WHERE
e.data.employeeDetails.employeeCity = "ORLANDO" – [ERROR]
*How can I perform a search\select inside the EmployeeDetilsDTOList (that is
inside the EmployeeDTO)?*
Thank you for your Help.
--
View this message in context: http://openjpa.208410.n2.nabble.com/JPA-XmlValueHandler-doesn-t-work-with-Multi-Valued-fileds-tp7582589.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
|