Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problem with indirect (lazy) mappings(trying to set to Lazy fetching type but getting validation errors)
Problem with indirect (lazy) mappings [message #510706] Thu, 28 January 2010 11:33 Go to next message
Carlos Conti is currently offline Carlos ContiFriend
Messages: 26
Registered: January 2010
Junior Member
Hi all, thanks in advance for your help.

I have checked the documentation from EclipseLink to configure the persistent unit in a static way so that I can load associated objects in a lazy way. However I am not being able to get through. This is the content of my persistence.xml file

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 <persistence-unit name="JPAIncidencias" transaction-type="JTA">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
   <jta-data-source>java:/comp/env/jdbc/SistemaIncidencias</jta-data-source>
   <exclude-unlisted-classes>false</exclude-unlisted-classes>
   <properties>
           
      <property name="eclipselink.session.customizer" value="utils.JPAEclipseLinkSessionCustomizer"/>        
      <property name="eclipselink.logging.level" value="FINEST"/> 
      
      <property name="eclipselink.weaving" value="static"/> 
      <property name="eclipselink.weaving.lazy" value="true"/>
      <property name="eclipselink.weaving.changetracking" value="true"/> 
      <property name="eclipselink.weaving.fetchgroups" value="true"/> 
      <property name="eclipselink.weaving.internal" value="true"/> 
      <property name="eclipselink.weaving.eager" value="false"/>  
      
    </properties>
 </persistence-unit>
 </persistence>



I am setting the entities in the following way:

Class A -> B (OneToMany)

public class A{
     private ArrayList toB;
     //getter and setter
}
public class B{
     private A toA;
     //getter and setter
}



and in the orm.xml got the following

<entity class="package.A">
		<table name="aa">
		</table>
                                           <one-to-many fetch="LAZY" name="toB" target-entity="package.B" mapped-by="toA">
		</one-to-many>
</entity>
<entity class="package.B">
		<table name="bb">
		</table>
                                           <many-to-one name="toA">
			<join-column name="A_ID" referenced-column-name="ID"/>
			</many-to-one>
</entity>


from B to A is eager by default, and from A to B lazy by default.

If possible would like to keep using ArrayList, but any [EclipseLink]List class arranged for maintaining indirection that works in not a very problematic way (regarding maintainance) will do fine. I used static weaving 'cause from the documentation I knew that it should only be defined once in the persistence.xml file.

Any hints on what I am doing wrong?

Thank you very much in advance.
Carlos
Re: Problem with indirect (lazy) mappings [message #510734 is a reply to message #510706] Thu, 28 January 2010 13:56 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

The JPA specification requires that collection attributes be either a Collection, Set, List or Map type, allowing providers to put in their own implementions transparently for lazy relations. EclipseLink does not strictly enforce this, which is why your collection type being ArrayList will work as long as it is not lazy. In order to be portable, you will need to change the toB type to be List, allowing EclipseLink to put its own IndirectList type when populating managed entities and still allowing your model to use ArrayList.

If you do not want to use the java.util.List and prefer a concrete type be specified, you would need to mark it as Transient and then use a customizer to create the mapping with native EclipseLink api.

Best Regards,
Chris
Previous Topic:Type conversion Oracle NVARCHAR2
Next Topic:User defined (custom) collections
Goto Forum:
  


Current Time: Tue Mar 19 03:15:14 GMT 2024

Powered by FUDForum. Page generated in 0.02121 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top