Change tracking of many-to-many relationship broken? [message #378580] |
Mon, 04 August 2008 12:11  |
Eclipse User |
|
|
|
Consider this code snippet: (Person <-> Address is a many-to-many
relationship)
@SuppressWarnings("unchecked")
private static void update(EntityManagerFactory entityManagerFactory) {
EntityManager entityManager = entityManagerFactory
.createEntityManager();
try {
entityManager.getTransaction().begin();
Query query = entityManager.createQuery("SELECT p FROM Person p");
Collection<Person> collection = (Collection<Person>) query
.getResultList();
Address address = new Address();
address.setStreet("Oak Lane 12");
address.setCity("Dallas");
for (Person person : collection) {
person.getAddresses().add(address);
address.getPersons().add(person);
}
entityManager.getTransaction().commit();
} finally {
if (entityManager.getTransaction().isActive()) {
entityManager.getTransaction().rollback();
}
entityManager.close();
}
}
The database has already two person-entities beforehand. The execution of
this piece of code does not alter the database - it should, however,
insert an Address entity with corresponding entries in the join table
PERSON_ADDRESS. However, a subsequent query for person-entities reveals an
additional Address-object associated with each person, that only consists
of uninitialized properties.
Is this a known bug?
Kind regards,
Frank
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05904 seconds