openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hvieren <herman.vierende...@gmail.com>
Subject Re: openjpa entity remove does unnecessary load of ManyToOne field ?
Date Tue, 23 Oct 2012 12:40:54 GMT
I have been able to solve my problem by using FieldStrategy extender

 @ManyToOne(fetch=FetchType.LAZY,optional=true,cascade=CascadeType.MERGE)
 @JoinColumn(name="CCD",nullable=false)
 @Strategy("h4.projects.website1.myRelationFieldStrategy")
 public COUNTRIES cOUNTRIES_CCD_i=null;

myRelationFieldStrategy:

package h4.projects.website1;
//package org.apache.openjpa.jdbc.meta.strats;

import java.sql.SQLException;

import java.util.logging.*;

import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy;
import org.apache.openjpa.jdbc.schema.ForeignKey;
import org.apache.openjpa.jdbc.sql.Row;
import org.apache.openjpa.jdbc.sql.RowManager;
import org.apache.openjpa.jdbc.sql.Select;
import org.apache.openjpa.kernel.OpenJPAStateManager;

public class myRelationFieldStrategy extends RelationFieldStrategy
{
 private static final Logger
logger=Logger.getLogger(myRelationFieldStrategy.class.getName());

 public void delete(OpenJPAStateManager sm,JDBCStore store,RowManager rm)
 throws SQLException
 {
  if(field.getMappedBy()!=null) return;

  if(field.getJoinDirection()==field.JOIN_INVERSE)
  {
   super.delete(sm,store,rm);
   return;
  }

  if(sm.getLoaded().get(field.getIndex()))
  {
   super.delete(sm,store,rm);
   return;
  }

  logger.info("sm="+sm);
  OpenJPAStateManager rel=null;

  field.deleteRow(sm, store, rm);
  //if our foreign key has a delete action, we need to set the related
object so constraints can be evaluated
  //tshvr4 get ForeignKey from FieldMapping 
  ClassMapping clssmppng=field.getTypeMapping();
  ForeignKey fk=field.getForeignKey(clssmppng);
    
if(fk.getDeleteAction()==ForeignKey.ACTION_RESTRICT||fk.getDeleteAction()==ForeignKey.ACTION_CASCADE)
  {
   Row row = field.getRow(sm, store, rm, Row.ACTION_DELETE);
   row.setForeignKey(fk, null, rel);
   // this is for bi-directional maps, the key and value of the map are
stored in the table of the mapped-by entity  
   //no need to call setMapKey if rel==null
    //setmapkey: if (rel == null)return;
   //super.setMapKey(sm, rel, store, row);
  }
 }//delete
}




--
View this message in context: http://openjpa.208410.n2.nabble.com/openjpa-entity-remove-does-unnecessary-load-of-ManyToOne-field-tp7581482p7581493.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Mime
View raw message