geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fredrik Jonson <fred...@myrealbox.com>
Subject Unexpected behaviour from @OneToMany with FetchType.LAZY
Date Tue, 17 Mar 2009 15:18:19 GMT
Hello everyone,

I can't get my @OneToMany references with FetchType.LAZY to become
populated by openjpa in geronimo. Using FetchType.EAGER works as
expected. Using OpenJPA standalone (in unit tests) and
transaction-type=LOCAL works too. But when I deploy the code in
geronimo my LAZY-fetched OneToMany relations are not populated.

For example, using the code below when I call customer.getAccounts()
the Set is always null, but customer.getProducts() works as expected
and that Set is populated by openjpa.

@Entity
@Table(name="customer")
public class Customer implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    private String name;
    @OneToMany(mappedBy="customer", fetch=FetchType.LAZY,
        cascade=CascadeType.ALL)
    private Set<Account> accounts;
    @OneToMany(mappedBy="customer", fetch=FetchType.EAGER,
        cascade=CascadeType.ALL)
    private Set<Product> products;

    public Set<Account> getAccounts() {
        return this.accounts;
    }

    public Set<Product> getProducts() {
        return this.products;
    }

    // More regular getter/setters omitted...
}

The product and account entity have the same implementation apart
from their name:

@Entity
@Table(name="account")
public class Account implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    @ManyToOne
    @JoinColumn(name="customer_id", nullable = false)
    private Customer customer;

    // Getters/setters omitted...
}

I'm using geronimo 2.1.3. Though I get the same result with the
last daily build of 2.1.4-SNAPSHOT (20090310).

Is this expected behaviour from FetchType.LAZY or is it a matter
of configuration (and PEBCAK ;)? I can provide the application
descriptors, but for brewity I've left them out here.

-- 
Fredrik Jonson


Mime
View raw message