bonjour,
j'ai quelque petites question sur les ejb3 j'ai crée deux bean ayant une relation
oneToMany
et je n'arrive pas a crée une requete en ejb-ql : me donner tous les lots par un id de fichier.
voici mon premier code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Entity
public class EnteFiPersistance implements Serializable {
@OneToMany(mappedBy = "entetefichier")
private List<EnteLotPersistance> enteLotPersistances;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
/** Creates a new instance of EnteFiPersistance */
private String brandId;
private String nomFichier;
private String horodatageDate;
private String horodatageHeure;
private String numeroSequentielFichier; |
1) que signifie
(mappedBy = "entetefichier")
second 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
| @Entity
public class EnteLotPersistance implements Serializable {
@OneToMany(mappedBy = "entetelot")
private List<detailTraPersistance> detailTraPersistances;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String typedeTransaction;
private String typeLot;
private String presenceDonneesCartes;
private String presenceNumeroAutorisation;
private String codeNumeriqueMonnaie;
private String identifiantAccepteurCarte;
private String identifiantTerminalAccepteurCarte;
@JoinColumn(name="refentetefichier")
@ManyToOne
private EnteFiPersistance entetefichier; |
2) que signifie
JoinColumn(name="refentetefichier")
3) comment les ejb represente les tables ?
voici ma requete :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public static Collection<EnteteLot> getSelectedEnteteLot(int id) throws Exception {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
EnteteLot v = null;
Collection c = null;
try {
Query query = em.createQuery("Select entelotpersistance from EnteFiPersistance As entelotpersistance where entelotpersistance.entefipersistance.id="+id);
c = query.getResultList();
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
throw new Exception("Impossible d'obtenir les informations.");
} finally {
em.close();
}
return c;
} |
Query query = em.createQuery("Select entelotpersistance from EnteFiPersistance As entelotpersistance where entelotpersistance.entefipersistance.id="+id);
l'erreur lors du deploiment :
1 2 3 4 5 6
| java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:180)
Caused by: Exception [TOPLINK-8030] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Unknown state or association field [entefipersistance] of class [com.experian.fichier.persistance.EnteFiPersistance].
at oracle.toplink.essentials.exceptions.EJBQLException.unknownAttribute(EJBQLException.java:409)
at oracle.toplink.essentials.internal.parsing.DotNode.validate(DotNode.java:80) |
merci !
Partager