Persistent Source Code Generation Issue

Hello,

Having the attached class diagram, I have the following issues when generating persistent code:

Question 1. I can’t have any kind of association relationship to PlanOS. I have the following error:

[Error] Plan OS: Class Composite element Plan OS cannot be referenced by classes other than ObraSocial.

Why? It’s not illegal.

Question 2. I have an Association Class ‘Afiliado’ between Paciente and PlanOS.
The navegability of this Association is from Paciente to PlanOS.

But in the generated code, PlanOS has navegability to Afiliado, and Afiliado has navegability to Paciente. Thus PlanOS has navegability to Paciente. It’s wrong.


//The following seems correct
import org.orm.*;
public class Paciente extends turnos.model.Persona {
	public Paciente() {...}	
	public boolean deleteAndDissociate() {...}	
        ...
	private String profesion;	
	private String estadoCivil;	
	private turnos.model.Afiliado afiliado;
	
	public void setProfesion(String value) {...}
        ...
	public turnos.model.Plan_OS getPlan os() {...}	
	public void removePlan os() {...}	
	public void addPlan os(turnos.model.Afiliado aAfiliado, turnos.model.Plan_OS aPlan os) {...}	
	public void setAfiliado(turnos.model.Afiliado value) {...}
	public turnos.model.Afiliado getAfiliado() {...}	
}

//The following generated code seems correct
import org.orm.*;
public class Afiliado {
	...	
	public boolean save() throws PersistentException {...}	
	public boolean delete() throws PersistentException {...}	
	public boolean refresh() throws PersistentException {...}
	public boolean evict() throws PersistentException {...}	
	public boolean deleteAndDissociate()throws PersistentException {...}	
	public boolean deleteAndDissociate(org.orm.PersistentSession session)throws PersistentException {...}
	private void this_setOwner(Object owner, int key) {...}	
	org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {...}		
	
	private int ID;	
	private int NroAfiliado;	
	private turnos.model.Paciente paciente;	
	private turnos.model.Plan_OS plan_os;	
	
        //setters y getters
	...	
	public void setPlan_os(turnos.model.Plan_OS value) {}		
	public turnos.model.Plan_OS getPlan_os() {}
		
	/**
	 * This method is for internal use only.
	 */
        ...
	public void setPaciente(turnos.model.Paciente value) {...}		
	public turnos.model.Paciente getPaciente() {...}	
	...	
}
//The following code seems not correct because of navegability
import org.orm.*;
public class Plan_OS {
	...
	public boolean save() throws PersistentException {...}
        ...
	public boolean deleteAndDissociate()throws PersistentException {...}
	private java.util.Set this_getSet (int key) {...}	
	org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {...};
	
	private int ID;	
	private Integer Nombre;	
	private Integer Categoria;	
	private Integer Estado;	
	private java.util.Set ORM_afiliados = new java.util.HashSet(); //I think it's not correct because of the navegability
	
        //setters and getters
	...
	private void setORM_Afiliados(java.util.Set value) {//I think it's not correct because of the navegability
		this.ORM_afiliados = value;
	}	
	private java.util.Set getORM_Afiliados() {//I think it's not correct because of the navegability
		return ORM_afiliados;
	}	
	public final turnos.model.AfiliadoSetCollection afiliados = new turnos.model.AfiliadoSetCollection(this, _ormAdapter, turnos.model.ORMConstants.KEY_PLAN_OS_AFILIADOS, turnos.model.ORMConstants.KEY_AFILIADO_PLAN_OS, turnos.model.ORMConstants.KEY_MUL_ONE_TO_MANY);//I think it's not correct because of the navegability
	...
}

Is the generated code wrong? Or am I wrong?

Thanks in advance.
Best regards.

clasesturnos.jpg

Hello Magoarcano,

Thanks for your message. For your questions:

  1. Since the class PlanOS is composite to ObraSocial, delete ObraSocial must delete the composite PlanOS. But delete PlanOS doesn’t enforce the deletion of its referenced object, which may lead to null pointer exception. Therefore we not allow composite element PlanOS having reference by other classes.

  2. I’ve tested with our latest build but cannot repeat the problem. Would you mind tell me the build number of VP you are using?

Best regards,
Rain

Hello Rain,

thanks for your response.

  1. Is it a necessary limitation? Even if PlanOS multiplicity of Paciente is 0…1?
    Also PlanOS has the following generated method: deleteAndDissociate
	public boolean deleteAndDissociate(org.orm.PersistentSession session)throws PersistentException {
		try {
			turnos.model.Afiliado[] lAfiliadoss = afiliados.toArray();
			for(int i = 0; i < lAfiliadoss.length; i++) {
				lAfiliadoss[i].setPlanos(null);
			}
			try {
				session.delete(this);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
  1. Version 7.1 Build sp1_20100106zi

Excuse me because of my english
Best regards.

Hello
Is there any answer for question 1?
How can I set the cascade in this example? I have the same problem as magoarcano.

best regards

Hello Buensche,

The deleteAndDissociate method is not for cascade, but for the smart collection handling (i.e. deleting object in by-directional association this method will help you to remove all the related reference before delete it). For the cascade, this is determined by the model itself. i.e. If the association is modeled with composition we will then do the cascade delete automatically.

Best regards,
Rain Wong