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.