Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Change tracking of many-to-many relationship broken?
Change tracking of many-to-many relationship broken? [message #378580] Mon, 04 August 2008 12:11 Go to previous message
Frank Schwarz is currently offline Frank Schwarz
Messages: 25
Registered: July 2009
Location: Dresden
Junior Member
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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:left side of the IN operator missing?
Next Topic:many table, one entity, annotation driven?
Goto Forum:
  


Current Time: Sat May 25 03:29:32 EDT 2013

Powered by FUDForum. Page generated in 0.05133 seconds