You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by QkI <ku...@gmail.com> on 2011/04/19 10:56:06 UTC
Problem with fetching relation
Hi,
I've got a problem during fetching @ManyToOne relations.
Consider following persistent classes:
@Entity
@Table(name = "x")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "jdoclass", length = 255)
@DiscriminatorStrategy("org.apache.openjpa.jdbc.meta.strats.ClassNameDiscriminatorStrategy")
public class X {
@Id
@Column(name = "id")
private int id;
}
@Entity
@Table(name = "b")
public class B extends X {
@Column(name = "name")
private String name;
}
@Entity
@Table(name = "a")
public class A extends X {
@ManyToOne
@JoinColumn(name = "b_id")
private B b;
}
The following test fails always.
@Test
public void test2() {
EntityManager em = context.getEm();
List<X> results = em.createQuery("SELECT e FROM X e").getResultList();
assertTrue(results.size() == 2);
for(X x : results) {
if(x instanceof A) {
A a = (A) x;
assertNotNull(a.getB());
}
}
em.close();
}
@Before
public void init() {
context.init();
EntityManager em = context.getEm();
EntityTransaction et = em.getTransaction();
try {
et.begin();
B b = new B();
b.setId(101);
b.setName("test");
A a2 = new A();
a2.setB(b);
a2.setId(102);
a2.setNo(2);
//em.persist(a);
em.persist(b);
em.persist(a2);
et.commit();
} catch (Throwable t) {
et.rollback();
}
}
Does anybody know what might be a reason of this ?
PS.
When I replaced @ManyToOne relation by primitive field:
@Column(name="b_id")
private int bId;
everything works, but I'm not a big fun of such workaround.
Regards,
Paweł
--
View this message in context: http://openjpa.208410.n2.nabble.com/Problem-with-fetching-relation-tp6286468p6286468.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Problem with fetching relation(OpenJPA 1.2.2)
Posted by QkI <ku...@gmail.com>.
Hi,
I have checked this problem once again, using different versions of OpenJPA.
It seems that it exists also in 2.1.0 but has been fixed in 1.2.3.
Should I rise a defect for problem which I described ?
Regards,
Paweł
--
View this message in context: http://openjpa.208410.n2.nabble.com/Problem-with-fetching-relation-OpenJPA-1-2-2-tp6286468p6308328.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.