Problem in cascade-delete
I've using cascade delete for delete rows from two entity beans.......
but my problem is that if I'm doing it from ejb side...i.e. setting "fk_constraint" to false, and setting cascade-delete in ejb-jar.xml (& not in database), then its working fine....
but if I remove these tags from the ejb-jar and in the database, specify foreign key and ON DELETE CASCADE, then its not working....it is giving the error...
"can't add or update a child row...foreign key constraint fails".....
I've read somewhere that this cascade delete option should be specified either on the ejb side or on the db side..and not on both the sides......but in run-time only ejb side is working...
Plz. help me out coz I want the deletion from db side...as thr are some other tables not used in ejb but dependant on the one used in the ejb side.
I think that you must specify <cascade-delete/> tag in ejb-jar.xml ONLY. But not in database.
Similar Messages
-
Problems with cascading delete with entities
I have a problem with cascading delete. I have two entities, Notebook and Note. One instance of Notebook can have several instances of Note in a Collection< Note >. The two entities are joined with a join table notebook_note that have two columns, the PK from the table of Notebook and Note. Note is not aware of the relation.
From the user interface some elements of the collection<Note> can be added or deleted. I want to delete an element of that collection and make it persisted on the DB.
If I add some Note elements to the collection and then I EntityManager.merge(notebook) (see public void persistNotebook() code below), I have all them persisted on the DB.
However, if I delete some preexisting Note elements, after the merge I found deleted only the corresponding rows from the join table notebook_note BUT the rows in table Note, that was belonging to the deleted instance of Notebook, are NOT removed.
Till now I found a way to do that (see code UserBean below), but I think that there is a simpler and so better way to do that! I hope to receive some suggestions!!
@Entity
public class Notebook implements Serializable {
private static final long serialVersionUID = 1L;
private String userName;
private Collection<Note> notes;
public Notebook() {
public Notebook(String userName) {
this.userName = userName;
notes = new ArrayList<Note>();
@Id
public String getUserName() {
return userName;
public void setUserName(String userName) {
this.userName = userName;
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
public Collection<Note> getNotes() {
return notes;
public void setNotes(Collection<Note> notes) {
this.notes = notes;
@Entity
public class Note implements Serializable {
String note;
public void setNote(String note) {
this.note = note;
public String getNote() {
return note;
@Stateful
public class UserBean implements UserRemote {
private static Logger log = Logger.getLogger(UserRemote.class);
@PersistenceContext(unitName = "etourism-ejbPU")
private EntityManager em;
……
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void persistNotebook() {
NotebookDao notebookDao = new notebookDao(em);
notebookDao.merge(notebook);
em.flush();
public void deleteNotebookNote (….) {
…..
//noteFound is the note I want to delete from the Collection<Note>
notebook.getEvents().remove(noteFound);
persistNotebook(); //see method above
*//I have also to explicitally delete the associated note!!!*
*NoteDao noteDao = new NoteDao(em);*
*noteDao.remove(noteDao.read(noteFound.getId()));*
public void addNotebookNote(…..) {
//add new note to the collection<Note> of the Notebook
Note newNote = new Note(…);
notebook.getNotes().add(newNote);
persistNotebook();
Where:
public class NotebookDao extends JpaDao<Notebook, String> {
……
public abstract class JpaDao<T, PK extends Serializable> implements IDao<T, PK> {
…..
public void remove(T entity) {
getEntityManager().remove(entity);
public void merge(T transientObject) {
getEntityManager().merge(transientObject);
}Thank you gimbal2 for your answer.
You are right saying that a single Note could be bound to multiple notebooks, when using a join table, so the cascade cannot be done automatically by JPA.
However, in my case, a single Note is bound only to one Notebook, so I would like to drop the join table (as you rightly suggest): however when I declare in the Notebook, a relation 1:N in this way ...
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
private Collection<Note> notes;
... the join table is automatically created during the deploy.
Sorry, I am a beginner in EJB3. What kind of relational mapping annotation should I use to have a straight 1:N relationship that doesn't generate a join table?
I think that it should be better to avoid to modify the relationship (es. cascade option) directly in the created db tables and let the logic be declared in the entity code definition: am I right?
Waiting for your suggestion ...
thank you very much
Enzo
Edited by: contini on May 22, 2009 5:37 AM -
Problem with cascade delete and remove bean
I am working with two entity beans that map to two tables that have a foreign key relationship. Table B has a foreign key to A and in the database that foreign key is set for cascaded updates and cascaded deletes.
The problem occurs when the the sytem first tries to remove bean 1 (mapped to table A) and then remove bean 2 (mapped to B) where bean 2 is associated with bean 1 with a foreign key relationship. The first remove works but then when it tries to remove bean 2 it throws a very ugly "CORBA TRANSACTION_ROLLEDBACK 9998" Maybe exception. My guess is that the reason is because bean 2's reocrd in the database was deleted when bean 1 was removed but the 'bean object' was not removed from the container.
When I go into our Application Server and look at how it see's the tables, it show the wrong relationship. It shows a restrict delete and a restrict update realationship.
My question is, am I wrong to think that this is a application server problem or a configuration problem? It seems to me that attempting to remove a non-existant record should not cause an error. It won't cause any SQL exceptions. Is this a flawed viewpoint? As a work around I made sure that the dependent records are deleted first but it kind of defeats the point of cascaded deletes.
We have a limited number of support calls, should I use one or am I at fault here?If the database removes the record from the second
table, why is the system trying to remove it once
again? You should try to remove an entity from a
single place, should it be the database or the
application. Don't try to remove it twice.
Regards,
DimitarI could do this but it is a huge pain in my ass. The problem is that you might want to remove the dependent bean without removing it's parent. The object structure is a little questionable, I'll admit that. It is, as they say, the eleventh hour and I can't really change that now.
The way this work is that the server gets a list of objects marked either as new, modified, or deleted. It then relates those changes back to the database.
In this case we have two lists(which makes me realize where the class structure sucks.) In order to do what you suggest I would have to get all the deleted parent objects and then search all the deleted child objects for ones that have the parent's key in them.
It would be prefferable to fix the class structure but again this is not an option.
Anyone want to answer the question I asked? -
Problem with cascade delete in CMP one-to-one relationship
I am not able to cascade delete for one-to-one relationship. Even though relationship seems to be setup correctly, record from the second table is not deleted.
Following is the structure of tables i am using:
First Table(vcc_lrmc) -- LRMCBean
lrmc_id pk (Bean field is id)
lrmc_dtl_id (Bean field islrmcDtlId)
Second Table (vcc_lrmc_dtl) -- LRMCDetailBean
lrmc_dtl_id (pk) (Bean field islrmcDtlId)
lrmc_id (Bean field id)
One to one bidirectional relationship has been setup with CMR fields moreLRMC and mainLRMC.
section of ejb-jar is as follows:
<ejb-relation>
<ejb-relation-name>LRMCMainToDetail</ejb-relation-name>
<ejb-relationship-role>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>LRMC</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>moreLRMC</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<multiplicity>One</multiplicity>
<cascade-delete/>
<relationship-role-source>
<ejb-name>LRMCDetail</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>mainLRMC</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
section of orion-ejb-jar is as follows:(Bidirectional mapping)
<entity-deployment name="LRMC" data-source="jdbc/VCCDS" table="VCC_LRMC">
<cmp-field-mapping name="moreLRMC">
<entity-ref home="LRMCDetail">
<cmp-field-mapping name="lrmcDtlId" persistence-name="LRMC_DTL_ID"/>
</entity-ref>
</cmp-field-mapping>
</entity-deployment>
<entity-deployment name="LRMCDetail" data-source="jdbc/VCCDS" table="VCC_LRMC_DTL">
<cmp-field-mapping name="mainLRMC">
<entity-ref home="LRMC">
<cmp-field-mapping name="id" persistence-name="LRMC_ID"/>
</entity-ref>
</cmp-field-mapping>
</entity-deployment>
Is there anything else need to be setup for Cascade delete or is there anything wrong the way one-to-one relationship has been setup.
Pls. advice.
Thanks
DhirajIs it happening because of this bug.
Cannot create a 1:1 bi-directional CMR for entity beans when database tables are reverse engineered. (2447364)
Anyone, any idea on this ?
Cheers,
Dhiraj -
Cascade delete problem(1+n call)
Hi Kodo Team.
I have two objects(one-many).
When I delete object, cascade delete works good.
But Kodo generates n+1 call.
Is this right?
As I know, Kodo generates just 1 call when I call one-many load.
Is there any way to only one call for delete?
my setting is below.
<jdo>
<package name="ep.prm.schedule.entity">
<class name="Schedule" objectid-class="SchedulePK">
<extension vendor-name="kodo" key="jdbc-class-map" value="base">
<extension vendor-name="kodo" key="pk-column" value="SCHCODE"/>
<extension vendor-name="kodo" key="table"
value="EPSCHEDULE.SC_TSCHEDULE"/>
</extension>
<extension vendor-name="kodo" key="jdbc-version-ind"
value="version-number">
<extension vendor-name="kodo" key="column" value="JDOVERSION"/>
</extension>
<!-- many sides-->
<field name="receivers" persistence-modifier="persistent">
<collection element-type="Receiver"/>
<extension vendor-name="kodo" key="fetch-group" value="receiver"/>
<extension vendor-name="kodo" key="inverse-logical" value="schedule"/>
<extension vendor-name="kodo" key="element-dependent" value="true"/>
<extension vendor-name="kodo" key="jdbc-field-map" value="one-many">
<extension vendor-name="kodo" key="table"
value="EPSCHEDULE.SC_TRECEIVER"/>
<extension vendor-name="kodo" key="ref-column.SCHCODE"
value="SCHCODE"/>
</extension>
</field>
</class>
</package>
</jdo>Thanks for your help.
I said a separate delete statement.
"Marc Prud'hommeaux" <[email protected]> wrote in message
news:[email protected]...
Leejungryong-
Are you saying that Kodo will issue a separate delete statement for each
object that is deleted? If so, then that is expected behavior. Note that
batch support in Kodo should make those statements all be executed in a
single batch, so it isn't as much of a performance penalty as it might
first appear (provided you have a Performance Pack or Enterprise Edition
license).
If you mean something else by "Kodo generates n+1 call", can you
clarify? Is it issuing multiple separate selects or something? Some
logging output might help provide some more insight.
In article <[email protected]>, Leejungryong wrote:
Hi Kodo Team.
I have two objects(one-many).
When I delete object, cascade delete works good.
But Kodo generates n+1 call.
Is this right?
As I know, Kodo generates just 1 call when I call one-many load.
Is there any way to only one call for delete?
my setting is below.
<jdo>
<package name="ep.prm.schedule.entity">
<class name="Schedule" objectid-class="SchedulePK">
<extension vendor-name="kodo" key="jdbc-class-map" value="base">
<extension vendor-name="kodo" key="pk-column" value="SCHCODE"/>
<extension vendor-name="kodo" key="table"
value="EPSCHEDULE.SC_TSCHEDULE"/>
</extension>
<extension vendor-name="kodo" key="jdbc-version-ind"
value="version-number">
<extension vendor-name="kodo" key="column" value="JDOVERSION"/>
</extension>
<!-- many sides-->
<field name="receivers" persistence-modifier="persistent">
<collection element-type="Receiver"/>
<extension vendor-name="kodo" key="fetch-group" value="receiver"/>
<extension vendor-name="kodo" key="inverse-logical"
value="schedule"/>
<extension vendor-name="kodo" key="element-dependent" value="true"/>
<extension vendor-name="kodo" key="jdbc-field-map" value="one-many">
<extension vendor-name="kodo" key="table"
value="EPSCHEDULE.SC_TRECEIVER"/>
<extension vendor-name="kodo" key="ref-column.SCHCODE"
value="SCHCODE"/>
</extension>
</field>
</class>
</package>
</jdo>
Marc Prud'hommeaux
SolarMetric Inc. -
Cascade deletes in kodo 3.0.1
I'm trying to use the cascade delete option and am having problems.
Here is my jdo file:
<class name="RoomScene" objectid-class="RoomSceneId">
<extension vendor-name="kodo" key="jdbc-class-map"
value="base">
<extension vendor-name="kodo" key="table"
value="t_roomscene"/>
<extension vendor-name="kodo" key="pk-column" value="id_i"/>
</extension>
<extension vendor-name="kodo" key="jdbc-version-ind"
value="version-number">
<extension vendor-name="kodo" key="column"
value="rowversion_i"/>
</extension>
<field name="id" primary-key="true">
<extension vendor-name="kodo" key="jdbc-field-map"
value="value">
<extension vendor-name="kodo" key="column"
value="id_i"/>
</extension>
</field>
<field name="itemLinks">
<collection element-type="ItemLink"/>
<extension vendor-name="kodo" key="element-delete-action"
value="cascade"/>
<extension vendor-name="kodo" key="jdbc-field-map"
value="one-many">
<extension vendor-name="kodo" key="table"
value="t_mapitemroomscene"/>
<extension vendor-name="kodo" key="ref-column.id_i"
value="roomscene_id_i"/>
</extension>
</field>
</class>
<class name="ItemLink" objectid-class="ItemLinkId">
<extension vendor-name="kodo" key="jdbc-class-map" value="base">
<extension vendor-name="kodo" key="table" value="t_mapitemroomscene"/>
<extension vendor-name="kodo" key="pk-column" value="id_i"/>
</extension>
<extension vendor-name="kodo" key="jdbc-version-ind"
value="version-number">
<extension vendor-name="kodo" key="column" value="rowversion_i"/>
</extension>
<field name="id" primary-key="true">
<extension vendor-name="kodo" key="jdbc-field-map" value="value">
<extension vendor-name="kodo" key="column" value="id_i"/>
</extension>
</field>
<field name="item">
<extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
<extension vendor-name="kodo" key="column.id_vc" value="item_id_vc"/>
</extension>
</field>
<field name="roomScene">
<extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
<extension vendor-name="kodo" key="column.id_i"
value="roomscene_id_i"/>
</extension>
</field>
<field name="linkText">
<extension vendor-name="kodo" key="jdbc-field-map" value="value">
<extension vendor-name="kodo" key="column" value="linktext_vc"/>
</extension>
</field>
</class>
(each RoomScene has many ItemLinks)
but when I delete my RoomScene object, I get the following exception:
"kodo.util.FatalDataStoreException: ERROR: ExecUpdate: Fail to add
null value in not null attribute roomscene_id_i {prepstmnt 2515391
UPDATE t_mapitemroomscene SET roomscene_id_i = ? WHERE roomscene_id_i =
?} [code=0, state=null]
NestedThrowables:
com.solarmetric.jdbc.ReportingSQLException: ERROR: ExecUpdate: Fail to
add null value in not null attribute roomscene_id_i {prepstmnt 2515391
UPDATE t_mapitemroomscene SET roomscene_id_i = ? WHERE roomscene_id_i =
?} [code=0, state=null]
java.sql.SQLException: ERROR: ExecUpdate: Fail to add null value in
not null attribute roomscene_id_i
at
kodo.jdbc.sql.SQLExceptions.getFatalDataStore(SQLExceptions.java:42)
at
kodo.jdbc.sql.SQLExceptions.getFatalDataStore(SQLExceptions.java:24)
at
kodo.jdbc.runtime.JDBCStoreManager.flush(JDBCStoreManager.java:510)
at
kodo.runtime.PersistenceManagerImpl.flushInternal(PersistenceManagerImpl
..java:788)
at
kodo.runtime.PersistenceManagerImpl.beforeCompletion(PersistenceManagerI
mpl.java:644)
at
kodo.runtime.LocalManagedRuntime.commit(LocalManagedRuntime.java:69)
at
kodo.runtime.PersistenceManagerImpl.commit(PersistenceManagerImpl.java:
416)
at
net.mastertile.www.room.action.RoomSceneDeleteAction.executeLogic(RoomSc
eneDeleteAction.java:27)
my kodo.properties file is like this:
javax.jdo.PersistenceManagerFactoryClass:
kodo.jdbc.runtime.JDBCPersistenceManagerFactory
javax.jdo.option.RetainValues: true
javax.jdo.option.RestoreValues: true
javax.jdo.option.Optimistic: true
javax.jdo.option.NontransactionalWrite: false
javax.jdo.option.NontransactionalRead: true
javax.jdo.option.Multithreaded: false
javax.jdo.option.MsWait: 5000
javax.jdo.option.MinPool: 1
javax.jdo.option.MaxPool: 200
javax.jdo.option.IgnoreCache: true
javax.jdo.option.ConnectionFactoryName=java:comp/env/jdbc/default
javax.jdo.option.ConnectionFactory2Name=java:comp/env/jdbc/default
kodo.LicenseKey=XXXXXXXXXXX
kodo.jdbc.MappingFactory=metadata
kodo.DataCache=false
kodo.RemoteCommitProvider=sjvm
kodo.FlushBeforeQueries=false
kodo.jdbc.ForeignKeyConstraints=true
kodo.jdbc.SequenceFactory: native
kodo.jdbc.SchemaFactory: dynamic
We are using postgresql.
Thanks,
NathanWere the foreign keys generated in the database? You also may want to
try using the *-dependent extensions.
Nathan Voxland wrote:
I'm trying to use the cascade delete option and am having problems.
Here is my jdo file:
<class name="RoomScene" objectid-class="RoomSceneId">
<extension vendor-name="kodo" key="jdbc-class-map"
value="base">
<extension vendor-name="kodo" key="table"
value="t_roomscene"/>
<extension vendor-name="kodo" key="pk-column" value="id_i"/>
</extension>
<extension vendor-name="kodo" key="jdbc-version-ind"
value="version-number">
<extension vendor-name="kodo" key="column"
value="rowversion_i"/>
</extension>
<field name="id" primary-key="true">
<extension vendor-name="kodo" key="jdbc-field-map"
value="value">
<extension vendor-name="kodo" key="column"
value="id_i"/>
</extension>
</field>
<field name="itemLinks">
<collection element-type="ItemLink"/>
<extension vendor-name="kodo" key="element-delete-action"
value="cascade"/>
<extension vendor-name="kodo" key="jdbc-field-map"
value="one-many">
<extension vendor-name="kodo" key="table"
value="t_mapitemroomscene"/>
<extension vendor-name="kodo" key="ref-column.id_i"
value="roomscene_id_i"/>
</extension>
</field>
</class>
<class name="ItemLink" objectid-class="ItemLinkId">
<extension vendor-name="kodo" key="jdbc-class-map" value="base">
<extension vendor-name="kodo" key="table" value="t_mapitemroomscene"/>
<extension vendor-name="kodo" key="pk-column" value="id_i"/>
</extension>
<extension vendor-name="kodo" key="jdbc-version-ind"
value="version-number">
<extension vendor-name="kodo" key="column" value="rowversion_i"/>
</extension>
<field name="id" primary-key="true">
<extension vendor-name="kodo" key="jdbc-field-map" value="value">
<extension vendor-name="kodo" key="column" value="id_i"/>
</extension>
</field>
<field name="item">
<extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
<extension vendor-name="kodo" key="column.id_vc" value="item_id_vc"/>
</extension>
</field>
<field name="roomScene">
<extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
<extension vendor-name="kodo" key="column.id_i"
value="roomscene_id_i"/>
</extension>
</field>
<field name="linkText">
<extension vendor-name="kodo" key="jdbc-field-map" value="value">
<extension vendor-name="kodo" key="column" value="linktext_vc"/>
</extension>
</field>
</class>
(each RoomScene has many ItemLinks)
but when I delete my RoomScene object, I get the following exception:
"kodo.util.FatalDataStoreException: ERROR: ExecUpdate: Fail to add
null value in not null attribute roomscene_id_i {prepstmnt 2515391
UPDATE t_mapitemroomscene SET roomscene_id_i = ? WHERE roomscene_id_i =
?} [code=0, state=null]
NestedThrowables:
com.solarmetric.jdbc.ReportingSQLException: ERROR: ExecUpdate: Fail to
add null value in not null attribute roomscene_id_i {prepstmnt 2515391
UPDATE t_mapitemroomscene SET roomscene_id_i = ? WHERE roomscene_id_i =
?} [code=0, state=null]
java.sql.SQLException: ERROR: ExecUpdate: Fail to add null value in
not null attribute roomscene_id_i
at
kodo.jdbc.sql.SQLExceptions.getFatalDataStore(SQLExceptions.java:42)
at
kodo.jdbc.sql.SQLExceptions.getFatalDataStore(SQLExceptions.java:24)
at
kodo.jdbc.runtime.JDBCStoreManager.flush(JDBCStoreManager.java:510)
at
kodo.runtime.PersistenceManagerImpl.flushInternal(PersistenceManagerImpl
.java:788)
at
kodo.runtime.PersistenceManagerImpl.beforeCompletion(PersistenceManagerI
mpl.java:644)
at
kodo.runtime.LocalManagedRuntime.commit(LocalManagedRuntime.java:69)
at
kodo.runtime.PersistenceManagerImpl.commit(PersistenceManagerImpl.java:
416)
at
net.mastertile.www.room.action.RoomSceneDeleteAction.executeLogic(RoomSc
eneDeleteAction.java:27)
my kodo.properties file is like this:
javax.jdo.PersistenceManagerFactoryClass:
kodo.jdbc.runtime.JDBCPersistenceManagerFactory
javax.jdo.option.RetainValues: true
javax.jdo.option.RestoreValues: true
javax.jdo.option.Optimistic: true
javax.jdo.option.NontransactionalWrite: false
javax.jdo.option.NontransactionalRead: true
javax.jdo.option.Multithreaded: false
javax.jdo.option.MsWait: 5000
javax.jdo.option.MinPool: 1
javax.jdo.option.MaxPool: 200
javax.jdo.option.IgnoreCache: true
javax.jdo.option.ConnectionFactoryName=java:comp/env/jdbc/default
javax.jdo.option.ConnectionFactory2Name=java:comp/env/jdbc/default
kodo.LicenseKey=XXXXXXXXXXX
kodo.jdbc.MappingFactory=metadata
kodo.DataCache=false
kodo.RemoteCommitProvider=sjvm
kodo.FlushBeforeQueries=false
kodo.jdbc.ForeignKeyConstraints=true
kodo.jdbc.SequenceFactory: native
kodo.jdbc.SchemaFactory: dynamic
We are using postgresql.
Thanks,
Nathan
Steve Kim
[email protected]
SolarMetric Inc.
http://www.solarmetric.com -
i am having a problem deleting child object
here is my code
my hibernate files are generated with xdoclet
I want to remove an object AFVALSTOF with all it's childs. the relationship is bi-directional. parent object is AFVALSTOF and as example child is OVERBRENGER. the relationship is obligated (not-null="true")
By viewing the hibernate logging i can see that the key field of the child is update to null first but this is an obligated field.
Can anyone help me on how to define my relationship so i can execute the cascade delete?
This is a part of my parent object (AFVALSTOF) which causes
problems
/ private Set overbrenger = new HashSet( );
* @hibernate.set tablename="overbrenger" lazy="true" inverse="false"
* cascade="all-delete-orphan"
* @hibernate.collection-key column="ovbr_afvs_id"
* @hibernate.collection-one-to-many class="be.milieuinfo.imjv.database.model.afval.Overbrenger"
* @return Set
public Set getOverbrenger() {
return overbrenger;
* @param overbrenger
* Overbrenger
public void setOverbrenger(Set overbrenger) {
this.overbrenger = overbrenger;
THIS IS THE CHILD (OVERBRENGER) which has a relationship to the PARENT called AFVALSTOF
private Afvalstof afvalstof ;
* @hibernate.many-to-one column="ovbr_afvs_id" class=
* "be.milieuinfo.imjv.database.model.afval.Afvalstof"
* not-null="true" inverse="true" cascade="all"
* @return Afvalstof
public Afvalstof getAfvalstof() {
return afvalstof ;
* @param afvalstof
public void setAfvalstof(Afvalstof afvalstof) {
this.afvalstof = afvalstof ;
thnx
Stefaan<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.orly_otero.patterns.VO.ArticleVO" table="tblArticles">
<id name="idArticle" type="long">
<column name="id_Article" not-null="true"/>
<generator class="native"/>
</id>
<property name="title" type="string">
<column name="Title" length="200" not-null="true"/>
</property>
<property name="abstracT" type="string">
<column name="Abstract" length="2000" not-null="true"/>
</property>
<property name="keywords" type="string">
<column name="Keywords" length="200" not-null="true"/>
</property>
<property name="type" type="string">
<column name="type" length="1" not-null="true"/>
</property>
<property name="position" type="integer">
<column name="position" not-null="false"/>
</property>
<property name="isBriefContribution" type="boolean">
<column name="isBriefContribution" not-null="false"/>
</property>
<many-to-one name="issueVO" column="id_Issue" class="com.orly_otero.patterns.VO.IssueVO" not-null="true"/>
<set name="authorsVO" table="tlbArticlesAuthors" lazy="true" cascade="save-update">
<key column="id_Article"/>
<many-to-many class="com.orly_otero.patterns.VO.AuthorVO" column="id_Author"/>
</set>
<set name="sectionsVO" inverse="true" lazy="true" cascade="all" order-by="position ASC">
<key column="id_Article" not-null="true"/>
<one-to-many class="com.orly_otero.patterns.VO.SectionVO"/>
</set>
</class>
</hibernate-mapping> -
Cascade delete in CMP 1:M relationship
All,
I have 2 CMP entity beans with 1:M relationship and cascade delete option setup. All functions of Add/Mod are working fine.
Even cascade delete is getting trigged but not executing properly every time. Out of more than 100 records in the child table, only 99 are getting cascade deleted. I am deploying the beans using embedded OC4J which comes with JDeveloper.
Is anyone aware of any such limitations or faced similar problem before ? Database tables don't have any integrity constraint setup.
Thanks,
DhirajThe problem is that by making the AddrXRef privately owned it cannot be reparented. Once it is removed from it's parent's list (either one) it will be deleted. To achieve what you're trying to do you'll need to delete the old incorrect AddrXRef and replace it with a new correct one.
From the TopLink Developer's Guide[1]:
When you tell TopLink that a relationship is privately owned, you are specifying that:
* If the source of a privately owned relationship is deleted, then delete the target.
* If you remove the reference to a target from a source, then delete the target.
--Shaun
[1] http://www.oracle.com/technology/products/ias/toplink/doc/10131/main/_html/uowbas007.htm#i1134011 -
Let the database doing cascade deletion for privateOwned relationship
Hi,
I have two tables: parent, child. I mapped the parent to child as a one-many private owned relationship. The child table have a foreign key reference back to parent table. The constraint is like this
alter table child add constraint FK_CONSTRAINT foreign key (parentid) reference parent (parentid) on delete cascade;
I would the cascade deletion is done by database (as it is "on delete cascade" in the constraint) rather by the toplink. (This is exactly what you will do when use JDBC. another reason is that if I let the TopLink do the cascade deletion, I got a deadlock! If I remove the cascade deletion from topLink, I do not have the deadlock).
Is there anyway I can turn off the cascade deletion from topLink, but at the same side keep the private owned relationship(because it is indeed privately owned)?
Any help is really appreciated.
jasonSetting a no-op sql solves the cascade deletion problem. However, if I really want to remove a child from the parently, I ends up using the same no-op sql. I can not delete child independently.
-
We are developing with Visual Studio 2013, Entity Framework 5, Oracle DB 11 via ODP.NET managed driver.
The edmx is generated/updated from database (database first). We generate POCO object using standard T4.
We have 2 tables with a master-detail foreign key relation, one to many. The foreign key in database does _not_ allow cascade deletes, so when you delete master row via SQL, you get error " ... child record found ... ".
The problem now is:
In Entity Framework, when i delete a record from the master table, then EF also deletes all corresponding detail records from the detail table! The restriction of the foreign key in database is ignored.
In edmx diagram, the properies End1 OnDelete / End2 OnDelete are set to "None", so i expect that on delete of a master row, EF should throw an error if detail rows exists.
How can i disable the cascading of the delete?
Here is the FK definition in edmx:
<Association Name="USR_USER_ROLES_ROLES_FK">
<End Role="USR_ROLES" Type="Self.USR_ROLES" Multiplicity="1" />
<End Role="USR_USER_ROLES" Type="Self.USR_USER_ROLES" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="USR_ROLES">
<PropertyRef Name="GES" />
<PropertyRef Name="PROJ" />
<PropertyRef Name="ROLE_NAME" />
</Principal>
<Dependent Role="USR_USER_ROLES">
<PropertyRef Name="GES" />
<PropertyRef Name="PROJ" />
<PropertyRef Name="ROLE_NAME" />
</Dependent>
</ReferentialConstraint>
</Association>
The delete of master row is done by calling:
ivDbCtx.USR_Roles.Local.Remove(role); // ivDbCtx is the DbContext, USR_Roles is the collection, role is the POCO object to be deleted.
Thank you very much for your help!
UdoHello,
For issues regarding ODP.NET managed driver, I would suggest you posting to oracle entity framework forum:
https://community.oracle.com/communications
There are oracle entity framework expects who will help you better.
Thanks for your understanding.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Cascade delete in container or database schema?
I am creating a database schema which I want to map EJB CMP Entity Beans onto. There are a number of relationships in the schema where I want to cascade deletion if a parent record is deleted and a number of relationships where I want to prevent deletion of parent records if child records exist for the relationship.
I am wondering whether it is better to implement this in the database schema (Oracle) or in the container (JBoss 3.2.2)? I believe it is possible to implement cascading delete in the container but I am not sure about preventing delete in the container? Is there a way I could do it programmatically? I want to use CMP though so I'm not sure there would be much scope for that.
Are there any rules as to which approach is better? Will the container have a problem if I implement it in the database schema? Obviously the ejbRemove may throw an exception if I prevent deletion in a relationship but that is fine. I believe it is not a good idea to implement it in both the container and schema as there will be a conflict when they both try to delete records.
Thanks.Container's cascade-deleting in jboss(tm)3.2.x working properly with any scope:
This example with 1 scope:
<relationships>
<ejb-relation>
<ejb-relation-name>Region-Town</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>region-has-towns</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>RegionBean</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>regionTowns</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>town-belongs-to-region</ejb-relationship-role-name>
<multiplicity>Many</multiplicity> <cascade-delete/>
<relationship-role-source>
<ejb-name>TownBean</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>region</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships> -
Cascading Delete in BC4J-UIXml application
Morning all,
I have a problem with a UIXml application that I was wondering somebody could help me with. Since I am new to this technology, please excuse the simplistic nature of the question.
I have a BC4J application working through UIX pages. In this application I have a form that deletes a record from the table. However, I am unable to determine how to perform an automatic cascading delete on the record since it has child records in another table.
Please advise. I shall update this thread after a successful workaround in order to provide a reference for others who may encounter this problem.
Thanks in advance for reading this post.
AdeelThis was resolved in the entity's association properties.
-
Hibernate child cascade delete child???
i am facing a problem on the cascade delete of a parent object, i try to explain the problem by example.
Parent object C
Child object D,E,F
i want to delete the parent object "delete(c) ".
before the parent can be deleted the child D,E and F has to be deleted.
My relations are defined with cascade="all-delete-orphan" in the parent
object. In my child no cascade is defined.
When i check the logging on deletion of the object i see that hibernate
tries to update reference in the child to the parent by setting the value to
null. But since the the reference is obligated (NOT NULL in database)
i get a not null constraint violation.
My first question is why does hibernate not delete the child record instead of updating the reference (since my child object is remove
from my collection in the parent object)?
Could some one tell me what i am doing wrong? or does there not exist a solution.
thnxFirst, is that a typo? The docs for 3.1 that I'm looking at say "all,delete-orphan", but you have "all-delete-orphan".
Second, I thought (and it's been a long time since I've needed to do this) that you defined the cascading in the child. I could be wrong though.
What kind of relationship is this? The docs say that delete-orphan only applies to one-to-many.
You might want to go through the pertinent sections of these if you haven't already:
http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html
http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html
[url http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-transitive]http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-transitive -
Can Designer handle Cascade Delete w/ Recursion?
Hello,
Does anyone know if Designer client Forms have a problem doing recursive relationships set to Cascade Delete in the FK? No problem on the server side code but when we try to generate the form since changing the recursive FK to Cascade Delete we get the error:
CDG-01131 ERROR: Module <form name>: Recursion found in referential integrity rules (foreign key <FK> on table <table>)
We are using Designer 6i Patch 4.1.1 and Developer 6i_R2 Patch 7
We are planning to upgrade soon to 4.5 and patch 10.
Thank you for your input!You may override getQueryHitCount on the ViewObject
and use a custom query to return the
estimatedRowCount using the right query for your
target db.But I've checked SQL92 in my connection and it seem this isn't legal syntax.
Alternatively you may provide a custom SQLBuilderImpl
extending 'SQL92SQLBuilderImpl' and provide a custom
query by overriding the method
public String getQueryHitCountSQL(RowSet rs)We've solved this case by doing the cacade delete in the database so no middle-tier logic is required.
However, this is not the end of our SQL92 problems. We're trying to get outer-joins to work using SQL92 syntax and a similar "SELECT * FROM (SELECT..." problem pops up.
See
Outer joins in non-Oracle RDBMS
Tony. -
All,
Facts :
1) I have 2 tables 150mil rows (table A) and second 125 mils rows (table B).
2) Table A <-> B is having FK 1:1 relationship and delete on table A is cascade delete on B
Issue : We are missing 25 mil rows in table B, and trying to delete Table A records with a PK in the where clause, I discovered that the cascade delete tries to Delete records in table B there are no records related to table A and it does a full table scan.
Question : How to delete the 25 mil rows effectively.
1) create index on table B same as PK of A and delete records from table.
2) Drop the FK constraint on table B and delete the records from table A and re-create the constraint.
Which one would be faster ?
Thanks,
SSPransuj,
You too! do not read the posts.
Have you heard about the concept of Partition
Tables.
Heard about Partition, Used it Extensively. Partitioning is not available at my clients place.
If I were you and have tables with that many millions
of rows, I would go for partition tables. If you have
partitioned tables you would not have run into these
kinds of problems
Not good enough Statement or reason to do Partitioning.
SS
Maybe you are looking for
-
Boa tarde, Estou com um erro na transação MIRO, quando estou efetuando o lançamento da fatura ocorre o erro: V1297 "A conversão de quantidades de em UN não pôde ser efetuada". Fiz um teste em QUP, onde lancei a MIGO e a MIRO com sucesso, após lança
-
Icloud add-in stopped working with Outlook 2010.
All of a sudden the add-in stopped working with Oulook 2010 on my Windows 7 PC. Instead of the refresh button on the toolbar is says "incorrect password." I have not changed my icloud username or password. I tried to setup from icloud control pane
-
Can't get the DOM to output XML document tags in correct order.
I'm trying to output an XML document from the DOM using the DOMWriter class: new DOMWriter(document, filename, outputEncoding, encodingTag, getDocTypeString()); It refuses to output the tags in the correct order so my document always fails validation
-
Idoc inbound error - encoding question
Hello, I receive idoc file from a parnter. I create a File Ports(WE21) : Non-unicode format and Checked 'Continue Despite Conversion Error'. The partner send to us a file with ASCII-encoding including German NÄHER . In WE02, I found the
-
Lightroom CC will not launch after install
Hi, installed Lightroom CC today twice but it will not launch. I uninstalled it, restarted then reinstalled it. In task manager you can see it show up for a second then it disappears. I have LR 5, PS CS6, PS CC, PS CC2014. Anyone having issues?