Recursively related entities not loaded
---------------------------------------
Key: OPENJPA-707
URL: https://issues.apache.org/jira/browse/OPENJPA-707
Project: OpenJPA
Issue Type: Bug
Components: jpa
Affects Versions: 1.1.0
Environment: * [OpenJPA 1.1.0]
* [derby 10.4.1.3]
* [java hotspot 1.6.0_06-b02]
* [ubuntu 8.04.1 2.6.24-19-generic]
Reporter: Antonio Sánchez
OpenJPA is failing to load data from the database in recursive
many-to-one relationships (and possibly other types of relationships).
CASE (Steps 1 to 4 follow) ---------->
STEP 1.- I'm using a recursive table (most probably the same case
applies for non-recursive relationships):
create table "SA"."RECURSIVA" (
PK int primary key not null,
DATO varchar(10),
PADRE int references RECURSIVA
);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (0,'Raiz',null);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (1,'n1',0);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (2,'n2',1);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (3,'n3',2);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (4,'n4',3);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (5,'n5',4);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (6,'n6',5);
INSERT INTO "SA"."RECURSIVA" (PK,DATO,PADRE) VALUES (7,'n7',6);
STEP 2.- This is the entity (the recursive many-to-one relationship is
supposed to be eagerly fetched, according to the spec.):
@Entity
@Table(name = "RECURSIVA")
public class Recursiva implements Serializable {
@Id
@Column(name = "PK", nullable = false)
private Integer pk;
@Column(name = "DATO")
private String dato;
@OneToMany(mappedBy = "padre")
private Collection<Recursiva> recursivaCollection;
@JoinColumn(name = "PADRE", referencedColumnName = "PK")
@ManyToOne
private Recursiva padre;
....
STEP 3.- This is the data retrieval code.
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("mijpa");;
EntityManager em = emf.createEntityManager();
Recursiva rc = null;
rc = em.find(Recursiva.class, 7);
while (rc != null) {
System.out.println(rc.getDato());
rc = rc.getPadre();
}
em.close();
emf.close();
STEP 4.- Results:
n7
n6
I would have expected to be printed the whole hierarchy up to the root,
i.e.: n7 n6 n5 n4 n3 n2 n1 Raiz
NOTE: TopLink Essentials does it as expected.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.