[Java lista] JPA ManyToMany
Szomor Attila
aszomor at computertechnika.hu
2009. Okt. 19., H, 15:57:01 CEST
Sziasztok,
Van 3 entitás és köztük egy kapcsoló entitás, a kapcsoló PlaceIntrc
entitásban PlaceUseru mindig van, de hol a PlaceGroP, hol a PlaceClass
null.
Tulajdonképen két kapcsoló tábla kellene egy a PlaceUseru és a PlaceGroP,
valamint egy másik a PlaceUseru és a PlaceClass közé, de hát ez az örökség.
A környezet GlassFish, Toplink-Essential, PostgreSQL, látszólag minden jól
működik amíg a GlassFish-t le nem kell állítani, akár napokig is jók a
kapcsolatok.
Azonban űjra indítás után a PlaceUseru-n történő első update-kor törli a
PlaceIntrc rekordokat és így elvész a kapcsolat a táblák (entitások)
között.
(semmit nem teszünk az entitással, csak meghívjuk az upadte-ot).
Van valami tippetek, mit kellene beállítani a JPA-ban, vagy láttok hibát
az entitások definicióiban?
Köszi, Attila.
public class PlaceUseru implements Serializable {
...
// PlaceIntrc: Felhasználó - Ambulanciái kapcsolat
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name ="place_intrc",
joinColumns = {@JoinColumn(name = "useru_use_int_id",
referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "gro_p_gro_use_id",
referencedColumnName = "id")}
)
private Collection<PlaceGroP> placeGroPCollection;
// PlaceIntrc: Felhasználó - Osztályai kapcsolat
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name ="place_intrc",
joinColumns = {@JoinColumn(name = "useru_use_int_id",
referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "class_cla_use_id",
referencedColumnName = "id")}
)
private Collection<PlaceClass> placeClassCollection;
...
}
public class PlaceGroP implements Serializable {
...
// PlaceIntrc: Felhasználó - Ambulanciái kapcsolat
@ManyToMany(mappedBy="placeGroPCollection")
private Collection<PlaceUseru> placeUseruCollection;
...
}
public class PlaceClass implements Serializable {
...
// PlaceIntrc: Felhasználó - Osztályai kapcsolat
@ManyToMany(mappedBy="placeClassCollection")
private Collection<PlaceUseru> placeUseruCollection;
...
}
public class PlaceIntrc implements Serializable {
...
@JoinColumn(name = "gro_p_gro_use_id", referencedColumnName = "id")
@ManyToOne
private PlaceGroP groPGroUseId;
@JoinColumn(name = "useru_use_int_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private PlaceUseru useruUseIntId;
@JoinColumn(name = "class_cla_use_id", referencedColumnName = "id")
@ManyToOne
private PlaceClass classClaUseId;
...
}
--
LOG részlet :
-------------
Az Execute query DataModifyQuery() -> DELETE
=============================================
------------------------
[ctMedikaPersistenceUnit] Mon Oct 19 15:26:23 CEST 2009 [DEBUG]
in com.ct.medika.persistence.units.PlaceUseruBean.updateEntity():
started.
------------------------
client acquired
TX binding to tx mgr, status=STATUS_ACTIVE
Merge clone with references
com.ct.medika.persistence.entities.PlaceUseru[id=1]
Register the existing object
com.ct.medika.persistence.entities.ChltableChltable[id=53751]
Register the existing object
com.ct.medika.persistence.entities.ChltableChltable[id=53801]
Execute query ReadAllQuery(com.ct.medika.persistence.entities.PlaceGroP)
reconnecting to external connection pool
SELECT t1.id, t1.grphn, t1.grpho, t1.created, t1.grcfl, t1.grcop,
t1.grcfv, t1.grcom, t1.grmeg, t1.grmuh, t1.grbeh, t1.grflg, t1.grmoj,
t1.grsma, t1.grtav, t1.grmin, t1.grjel, t1.grktg, t1.modified, t1.grnap,
t1.grbed, t1.grpro, t1.grkts, t1.grmh2, t1.uid, t1.gramb, t1.grnks,
t1.gregy, t1.grepo, t1.grnel, t1.grtps, t1.grint, t1.taprep_tap_doc_id,
t1.place_intez_id, t1.class_clagro_id, t1.chltable_chltable_boos_grjel_id,
t1.chltable_chltable_boss_grtip_id, t1.chltable_chltable_boss_grmin_id
FROM place_intrc t0, place_gro_p t1 WHERE ((t0.useru_use_int_id = ?) AND
(t1.id = t0.gro_p_gro_use_id))
bind => [1]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.AmbulatKilat)
reconnecting to external connection pool
SELECT id, modified, kiambukod, created, uid, place_gro_p_id FROM
ambulat_kilat WHERE (place_gro_p_id = ?)
bind => [452]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.PlaceIntez)
reconnecting to external connection pool
SELECT id, inusr, inflg, uid, intsz, modified, inbed, innam, inbln, inado,
infin, inadr, inpfr, inbis, incod, inmen, incit, inmal, created, inurl,
inpho, intbk FROM place_intez WHERE (id = ?)
bind => [53]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.ChltableChltable)
reconnecting to external connection pool
SELECT id, szoveg, inflg, uid, szekcio, bejegyz, modul, modified, created
FROM chltable_chltable WHERE (id = ?)
bind => [56401]
Register the existing object
com.ct.medika.persistence.entities.PlaceGroP[id=452]
Register the existing object
com.ct.medika.persistence.entities.PlaceIntez[id=53]
Register the existing object
com.ct.medika.persistence.entities.ChltableChltable[id=56401]
Execute query ReadAllQuery(com.ct.medika.persistence.entities.TaprepTapDoc)
reconnecting to external connection pool
SELECT id, modified, mhcod, uid, tbdoc, created, place_useru_id FROM
taprep_tap_doc WHERE (place_useru_id = ?)
bind => [1]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.PlaceUseru)
Register the existing object
com.ct.medika.persistence.entities.TaprepTapDoc[id=1]
Register the existing object
com.ct.medika.persistence.entities.PlaceUseru[id=1]
Execute query ReadAllQuery(com.ct.medika.persistence.entities.PlaceClass)
reconnecting to external connection pool
SELECT id, clsta, cldin, uid, clusr, modified, clint, clnam, crepo, clflg,
cnovo, clflag, clcod, clsma, created, cladr, ctype,
chltable_chltable_boss_ctype_id, place_useru_id, place_intez_id FROM
place_class WHERE (place_useru_id = ?)
bind => [1]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.ChltableChltable)
reconnecting to external connection pool
SELECT id, szoveg, inflg, uid, szekcio, bejegyz, modul, modified, created
FROM chltable_chltable WHERE (id = ?)
bind => [55351]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.PlaceUseru)
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.PlaceIntez)
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.ChltableChltable)
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.PlaceUseru)
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.PlaceIntez)
Register the existing object
com.ct.medika.persistence.entities.PlaceClass[id=102]
Register the existing object
com.ct.medika.persistence.entities.ChltableChltable[id=55351]
Register the existing object
com.ct.medika.persistence.entities.PlaceUseru[id=1]
Register the existing object
com.ct.medika.persistence.entities.PlaceIntez[id=53]
Register the existing object
com.ct.medika.persistence.entities.PlaceClass[id=52]
Register the existing object
com.ct.medika.persistence.entities.ChltableChltable[id=55351]
Register the existing object
com.ct.medika.persistence.entities.PlaceUseru[id=1]
Register the existing object
com.ct.medika.persistence.entities.PlaceIntez[id=53]
Execute query ReadAllQuery(com.ct.medika.persistence.entities.PlaceSzakm)
reconnecting to external connection pool
SELECT id, modified, uszak, created, uid, codes_szakma_id,
useru_use_szk_id FROM place_szakm WHERE (useru_use_szk_id = ?)
bind => [1]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.CodesSzakma)
reconnecting to external connection pool
SELECT id, modified, szak_code, uid, szak_name, szak_flg, created FROM
codes_szakma WHERE (id = ?)
bind => [51]
Execute query
ReadObjectQuery(com.ct.medika.persistence.entities.PlaceUseru)
Register the existing object
com.ct.medika.persistence.entities.PlaceSzakm[id=2]
Register the existing object
com.ct.medika.persistence.entities.CodesSzakma[id=51]
Register the existing object
com.ct.medika.persistence.entities.PlaceUseru[id=1]
Execute query ReadAllQuery(com.ct.medika.persistence.entities.PlaceClass)
reconnecting to external connection pool
SELECT t1.id, t1.clsta, t1.cldin, t1.uid, t1.clusr, t1.modified, t1.clint,
t1.clnam, t1.crepo, t1.clflg, t1.cnovo, t1.clflag, t1.clcod, t1.clsma,
t1.created, t1.cladr, t1.ctype, t1.chltable_chltable_boss_ctype_id,
t1.place_useru_id, t1.place_intez_id FROM place_intrc t0, place_class t1
WHERE ((t0.useru_use_int_id = ?) AND (t1.id = t0.class_cla_use_id))
bind => [1]
Register the existing object
com.ct.medika.persistence.entities.PlaceClass[id=102]
TX beginTransaction, status=STATUS_ACTIVE
Execute query
UpdateObjectQuery(com.ct.medika.persistence.entities.PlaceUseru[id=1])
Execute query DataModifyQuery()
reconnecting to external connection pool
DELETE FROM place_intrc WHERE ((gro_p_gro_use_id = ?) AND
(useru_use_int_id = ?))
bind => [452, 1]
Execute query DataModifyQuery()
DELETE FROM place_intrc WHERE ((class_cla_use_id = ?) AND
(useru_use_int_id = ?))
bind => [102, 1]
------------------------
[ctMedikaPersistenceUnit] Mon Oct 19 15:26:23 CEST 2009 [DEBUG]
in com.ct.medika.persistence.units.PlaceUseruBean.updateEntity():
com.ct.medika.persistence.entities.PlaceUseru[id=1] updated.
------------------------
További információk a(z) Javalist levelezőlistáról