tags:

views:

39

answers:

1

I have a problem with OpenJPA

I try to read all rows from a table but the primary key has always a same value(value = 0)!?!?!?

for (Object o : em.createQuery("select x from AnnouncementsEntry x")
                .getResultList()) {
            //alway returns "0" in every row
                long id = ((AnnouncementsEntry) o).getEntryId();

my entry:

@Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long entryId;
A: 

The foreach loop executes same database query every time in each iteration. execute query before starting foreach loop and In for each loop iterate over the result.

Digambar Daund
This is not true. Check the section [14.14.2 The enhanced for statement](http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2) of the JLS, the query is executed only once and the for each loop iterates over the results.
Pascal Thivent
Thanks Pascal, I got the point.
Digambar Daund