Requête complexe avec un EntityQuery
Bonjour,
Je me suis inspiré de ce qui est généré par Seam Generate Entites pour faire une page affichant des données en tableau.
Ça fonctionne bien avec toutes les données de l'entité mais je souhaite restreindre les données affichées selon une requête complexe et là je ne sais plus faire ! :oops:
Le code qui marche :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Name("listeStages")
public class ListeStages extends EntityQuery<ThStageStg>
{
private static final String EJBQL = "select thStageStg from ThStageStg thStageStg";
private static final String[] RESTRICTIONS = {};
public ListeStages()
{
setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(25);
} |
Ce que j'ai essayé et qui ne fonctionne pas :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| @Name("listeStages")
public class ListeStages extends EntityQuery<ThStageStg>
{
private ThStageStg thStageStg = new ThStageStg();
@In
private EntityManager em;
@In Identity identity;
@In Credentials credentials;
@In (scope = ScopeType.SESSION)
private ThUtilisateurUti utilisateur;
public ListeStages()
{
/*setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(25);*/
Query query = em.createNativeQuery(
"SELECT ssn.ssn_id, ssn.ssn_libelle, ssn.ssn_date_debut, ssn.ssn_date_fin, " +
"cmn.cmn_nom, dpt.dpt_numero, rgn.rgn_nom " +
"FROM te_session_ssn ssn " +
"INNER JOIN th_stage_stg stg ON stg.stg_id_session = ssn.ssn_id " +
"INNER JOIN te_etablissement_etb etb ON etb.etb_id = stg.stg_id_etablissement " +
"INNER JOIN tr_commune_cmn cmn ON cmn.cmn_id = etb.etb_id_commune " +
"INNER JOIN tr_departement_dpt dpt ON dpt.dpt_id = cmn.cmn_id_departement " +
"INNER JOIN tr_region_rgn rgn ON rgn.rgn_id = dpt.dpt_id_region " +
"INNER JOIN tj_stg_concerner_dsc_scd scd ON scd.scd_id_stage = stg.stg_id_session " +
"INNER JOIN te_discipline_dsc dsc ON dsc.dsc_id = scd.scd_id_discipline " +
"INNER JOIN te_concours_ccr ccr ON ccr.ccr_id_discipline = dsc.dsc_id " +
"INNER JOIN th_etudiant_etu etu ON etu.etu_id_concours = ccr.ccr_id ");/* +
"WHERE etu.etu_id_candidat = :idEtudiant ");
query.setParameter("idEtudiant", this.utilisateur.getPrsId());*/
query.getResultList();
} |
Je précise que la requête fonctionne directement soumise à MySQL.
Erreur obtenue :
Citation:
org.jboss.seam.InstantiationException: Could not instantiate Seam component: listeStages
Caused by: java.lang.NullPointerException
Vaut-il mieux abandonner l'EntityQuery et faire comme dans l'exemple jpa :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| @Scope(SESSION)
@Name("bookingList")
// @TransactionAttribute(REQUIRES_NEW)
public class BookingListAction implements Serializable
{
@In
private EntityManager em;
@In
private User user;
@DataModel
private List<Booking> bookings;
@DataModelSelection
private Booking booking;
@Logger
private Log log;
@Factory
@Observer("bookingConfirmed")
@Transactional
public void getBookings()
{
bookings = em.createQuery("select b from Booking b where b.user.username = :username order by b.checkinDate")
.setParameter("username", user.getUsername())
.getResultList();
}
public void cancel()
{
log.info("Cancel booking: #{bookingList.booking.id} for #{user.username}");
Booking cancelled = em.find(Booking.class, booking.getId());
if (cancelled!=null) em.remove( cancelled );
getBookings();
FacesMessages.instance().add("Booking cancelled for confirmation number #0", booking.getId());
}
public Booking getBooking()
{
return booking;
}
} |