Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

one-to-many relation with array types

Don T

2008-08-07


Author LoginPost Reply

Hi, I'm trying to populate a field of array type using apache-openjpa-1.0.2.
The entity classes are autogenerated by Axis wsdl2java so I cannot modify
them or add annotations. I can only register custom field mappings through
orm.xml or persistence.xml. Here is an example with the Java classes and
orm.xml:


Java:

public class Battery {
 private int batteryId;
 private int siteId;
 // .. other fields
}

public class SiteInfo {
 private int siteInfoId;
 private Battery[] batteries;  
 // .. other fields

 public Battery[] getBatteries() {
   return batteries;
 }

 public void setBatteries(Battery[] batteries) {
   this.batteries = batteries;
 }
}


ORM.XML:

<entity name="Battery" class="Battery">    
 <table name="battery" />        
 <attributes>
   <id name="batteryId">
     <column name="battery_id"/>
   </id>      
   <basic name="siteId">
     <column name="site_id" />
   </basic>                
 </attributes>    
</entity>

<entity class="SiteInfo" name="SiteInfo">
 <table name="site_info" />        
   
 <attributes>
   <id name="siteInfoId">
     <column name="site_info_id" />
   </id>
     
   <one-to-many name="batteries">      
     <join-column name="site_id" referenced-column-name="site_info_id" />
   </one-to-many>
 </attributes>
</entity>
</pre>

I verified that 2 JPQL queries are executed, one for parent entity and one
for child entity with a join to parent entity:

SELECT t0.site_info_id, t0.county, t0.state FROM site_info t0 WHERE
(t0.county = ? AND t0.state = ?)

SELECT t0.site_info_id, t1.site_id FROM site_info t0, battery t1 WHERE
(t0.county = ? AND t0.state = ?) AND t0.site_info_id = t1.site_id

I get the result as a list of SiteInfo objects. When calling getBatteries()
on any SiteInfo object its always returning null. I'm guessing Apache
OpenJPA expects Collection types for one-to-many relationships. What is the
simplest way to populate a field of array types using OpenJPA?
--
Sent from the OpenJPA Users mailing list archive at Nabble.com.

©2008 gg3721.com - Jax Systems, LLC, U.S.A.