I have a problem when trying to update foreign keys. Using the merge function I always get a out of memory error, or I get a timeout
Fakultaet and Standort are foreign keys in the Raum table (many to one, and lazy fetching) Raum does eager fetching for the Fakultaet and Standort
@Stateless
@Local (IRaumHomeLocal.class)
@Remote (IRaumHomeRemote.class)
public class RaumHome implements IRaumHome {
@PersistenceContext private EntityManager em;
void merge(Raum r, Integer fid, Integer sid) {
Fakultaet f = em.find(Fakultaet.class, fid);
Standort s = em.find(Standort.class, sid);
r.setFakultaet(f);
r.setStandort(s);
f.getRaums().add(r);
s.getRaums().add(r);
em.merge(r);
}
....
}
I then tried using getReference() instead of find() since I only want to do an update, so I have the method:
void merge(Raum r, Integer fid, Integer sid) {
Standort s = em.getReference(Standort.class, sid);
Fakultaet f = em.getReference(Fakultaet.class, fid);
s.getRaums().add(r); // now it lags here
f.getRaums().add(r);
em.merge(r);
}
still not working
afterwards I removed the s.getRaums().add(r) and f.getRaums().add(r) lines
but this causes a LazyInitializationException in the next query I need to do.
all I want is something like this:
UPDATE Raum SET FakultaetId = ?, StandortId = ? WHERE RaumID = ?
what am I doing wrong ? is there a better method of doing this ?