EJB - RIGHT_JOIN_NOT_SUPPORTED

1

I am new to the use of criteria and jpa.

I have two tables related by a field. I need to make a join that shows me all the related data as well as those not related by that field even if some of the fields in the main table are empty (This is the requirement, I guess they want to detect this information to identify the missing of this relationship ). The relationship of these tables is one to one.

My "main" table is cmb_configuration_changes which gets data from another table using a field to relate to it.

I have an SQL query that shows that table as I need it, however when I try to "translate" it to criteria I get an exception that the type of the join is not supported.

select *
from cmb_cambios_configuracion setup right outer join cmb_cambios pm
on setup.idcmb_cambios = pm.idcmb_cambios
where setup.idcmb_cambios is null 
OR setup.idcmb_cambios is NOT null;

my query I do it in the following way:

 public List<CmbCambiosConfiguracion> arranqueDatos(Marca marca) {

    List<Predicate> predicateList = new ArrayList();
    EntityManager em = getEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery();

    Root root = cq.from(getEntityClass());
    Join<CmbCambiosConfiguracion,CmbCambios> join = root.join(CmbCambiosConfiguracion_.cmbCambios, JoinType.RIGHT);

    cq.select(root);
    predicateList.add(cb.isMember(marca, root.get(CmbCambiosConfiguracion_.cmbCambios).get(CmbCambios_.serial).get(PrnPartnumber_.marca)));
    Predicate esNulo = cb.isNull(join.get(CmbCambios_.CmbCambiosConfiguracion));
    Predicate noNulo = cb.isNotNull(join.get(CmbCambios_.CmbCambiosConfiguracion));
    predicateList.add(cb.or(esNulo, noNulo));

    cq.where(cb.and(getPredicates(predicateList)));
    cq.orderBy(cb.asc(root.get(CmbCambiosConfiguracion_.fechaCreacion)));
    Query q = getEntityManager().createQuery(cq);
    return q.getResultList();
}

and the exception I get is the following

Advertencia:   A system exception occurred during an invocation on EJB CmbCambiosConfiguracionFacade, method: public java.util.List org.cardon.database.ejb.CmbCambiosConfiguracionFacade.arranqueDatos(org.cardon.database.entity.Marca)
Advertencia:   javax.ejb.EJBException
.
.
.
.
.
Caused by: java.lang.UnsupportedOperationException: RIGHT_JOIN_NOT_SUPPORTED (There is no English translation for this message.)

As I mention, I am still too inexperienced and I have already spent several hours investigating how to do it and I have only found that this is not supported by JPA. I thank you in advance for your answers and I apologize if I have not been very clear.

    
asked by COMINO628 28.11.2017 в 16:45
source

1 answer

0

He is telling you that he does not support a "right join":

 Join<CmbCambiosConfiguracion,CmbCambios> join = 
       root.join(CmbCambiosConfiguracion_.cmbCambios, JoinType.RIGHT);

Try changing this to another type, for example turn the order of the join and convert it into a LEFT:

select *
from cmb_cambios_configuracion setup right outer join cmb_cambios pm
on setup.idcmb_cambios = pm.idcmb_cambios

is the same as

select *
from cmb_cambios pm left outer join cmb_cambios_configuracion setup
on pm.idcmb_cambios = setup.idcmb_cambios
    
answered by 28.11.2017 в 17:39