我正在进行查询转换sql - > JPQL,我使用的是eclipselink JPA框架。
Sql查询返回结果正确,但JPQL查询没有返回任何东西,如果任何人可以提供线索将是非常好的。
JPA实体:
/**
* Contiene el mapeo de la siguiente entidad: <br/>
* PRD_OWNER.BET_LABEL_COLLECTIONS <br/>
* Nombre Nulo Tipo <br/>
*--------------------------- -------- --------------<br/>
* <b>LABEL_COLECCTIONS_ID NOT NULL NUMBER </b> <br/>
* CREATION_DATE NOT NULL TIMESTAMP(6) <br/>
* CREATED_BY NOT NULL NUMBER <br/>
* LAST_UPDATE_DATE NOT NULL TIMESTAMP(6) <br/>
* LAST_UPDATED_BY NOT NULL NUMBER <br/>
* LABEL_ID NOT NULL NUMBER <br/>
* COLLECTION_ID NOT NULL NUMBER <br/>
* SAMPLE NUMBER(1) <br/>
* COMMENTS VARCHAR2(4000) <br/>
* RELATED_LABEL_COLLECTION_ID NUMBER <br/>
* RELATED_SEASON_ID NUMBER <br/>
* ACTIVE NUMBER(1) <br/>
* FILE_SUPPLIER BLOB <br/>
* FILE_SUPPLIER_CONTENT_TYPE VARCHAR2(25) <br/>
*
* <b>permite vincular un etiqueta {@link Label} - coleccion {@link Collection} - temporada {@link ActivatableSeason}</b>
* contiene objetos heredados de {@link BaseEntity} --> información de auditoria
*/
//@formatter:on.
@Entity
@Table(name = "BET_LABEL_COLLECTIONS")
@NamedQueries({ @NamedQuery(name = LabelCollection.RETRIEVE_BY_SEASON_COLLECTION, query = "SELECT labelCollection from LabelCollection labelCollection INNER JOIN labelCollection.label.seasonList season WHERE labelCollection.active=1 AND season.seasonId = :seasonId AND labelCollection.collection.collectionId = :collectionId ORDER BY labelCollection.sample DESC, labelCollection.label.referencia ASC"),
@NamedQuery(name = LabelCollection.RETRIEVE_BY_CODE, query = "SELECT labelColecction FROM LabelCollection labelColecction WHERE labelColecction.active=1 AND labelColecction.label.referencia LIKE UPPER(:labelCode)"),
@NamedQuery(name = LabelCollection.RETRIEVE_SAMPLE_LABELS_BY_SEASON_COLLECTION, query = "SELECT labelColecction from LabelCollection labelColecction INNER JOIN labelColecction.label.seasonList season WHERE labelColecction.active=1 AND labelColecction.sample = true AND season.seasonId = :seasonId AND labelColecction.collection.collectionId = :collectionId"),
@NamedQuery(name = LabelCollection.RETRIEVE_BY_SEASON_COLLECTION_LABEL_CODE, query = "SELECT labelCollection from LabelCollection labelCollection INNER JOIN labelCollection.label.seasonList season WHERE labelCollection.active=1 AND season.seasonId = :seasonId AND labelCollection.collection.collectionId = :collectionId AND labelCollection.label.labelId = :labelId"),
@NamedQuery(name = LabelCollection.RETRIEVE_LABEL_COLLECTION_COPY_PRICES_POLLAS, query = "select lb from LabelCollection lb join lb.label.seasonList ls where lb.collection.collectionId = :colId and ls.seasonId = :seasonDestiny and exists ("
+ " select 1 from CollectionAssignement ca where ca.collection.collectionId = lb.collection.collectionId "
+ " and ca.supplier.labelSupplierId in :idSuppliersToCopy and ca.season.seasonId = :seasonOrigin )")
})
public class LabelCollection extends BaseEntity implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 2948530882980344938L;
/** The Constant RETRIEVE_BY_SEASON_COLLECTION. */
public static final String RETRIEVE_BY_SEASON_COLLECTION = "retrieveBySeasonCollection";
/** The Constant RETRIEVE_BY_SEASON_COLLECTION_LABEL_CODE. */
public static final String RETRIEVE_BY_SEASON_COLLECTION_LABEL_CODE = "retrieveBySeasonCollectionLabelCode";
/** The Constant RETRIEVE_BY_CODE. */
public static final String RETRIEVE_BY_CODE = "retrieveByCode";
/** The Constant RETRIEVE_SAMPLE_LABELS_BY_SEASON_COLLECTION. */
public static final String RETRIEVE_SAMPLE_LABELS_BY_SEASON_COLLECTION = "retrieveSampleLabelsBySeasonCollection";
/** The Constant RETRIEVE_SAMPLE_LABELS_BY_SEASON_COLLECTION. */
public static final String RETRIEVE_LABEL_COLLECTION_COPY_PRICES_POLLAS = "retrieveLabelCollectionPrices";
/** The label collection id. */
@Id
@SequenceGenerator(name = "LABEL_COLLECTION_ID_S", sequenceName = "BET_LABEL_COLLECTIONS_SEQ", allocationSize = 1)
@GeneratedValue(generator = "LABEL_COLLECTION_ID_S", strategy = GenerationType.SEQUENCE)
@Column(name = "LABEL_COLECCTIONS_ID", nullable = false)
private Long labelCollectionId;
/** The sample. */
@Column(name = "SAMPLE")
@EditableField
private Boolean sample;
/** The active. */
@Column(name = "ACTIVE")
private Long active;
/** The collection. */
@ManyToOne
@JoinColumn(name = "COLLECTION_ID")
private Collection collection;
/** The comments. */
@Column(length = 4000)
@EditableField
private String comments;
/** The file supplier. */
@Column(name = "FILE_SUPPLIER")
private byte[] fileSupplier;
/** The file supplier content type. */
@Column(name = "FILE_SUPPLIER_CONTENT_TYPE", length = 25)
private String fileSupplierContentType;
/** The label. */
@ManyToOne
@JoinColumn(name = "LABEL_ID")
private Label label;
/** The related label collection. */
@ManyToOne
@JoinColumn(name = "RELATED_LABEL_COLLECTION_ID")
private LabelCollection relatedLabelCollection;
/** The related season. */
@ManyToOne
@JoinColumn(name = "RELATED_SEASON_ID")
private ActivatableSeason relatedSeason;
//@formatter:off.
/**
* <ol>Este objeto permite vinvular un precio {@link Price} a: <br/>
* <li> coleccion {@link Collection}</li>
* <li> proveedor{@link LabelSupplier}</li>
* <li> temporada {@link ActivatableSeason}</li>
* </ol>
* Contiene el mapeo de la siguiente entidad: <br/>
*
* gpe_collection_assignements
* Nombre Nulo Tipo <br/>
* ------------------------- -------- ------------<br/>
* <b>COLLECTION_ASSIGNEMENT_ID NOT NULL NUMBER </b> <br/>
* COLLECTION_ID NUMBER <br/>
* SUPPLIER_ID NUMBER <br/>
* SEASON_ID NUMBER <br/>
* ASSIGNEMENT_DATE DATE <br/>
* CREATION_MODE VARCHAR2(30) <br/>
* CREATED_BY NOT NULL NUMBER <br/>
* CREATION_DATE NOT NULL TIMESTAMP(6) <br/>
* LAST_UPDATED_BY NOT NULL NUMBER <br/>
* LAST_UPDATE_DATE NOT NULL TIMESTAMP(6) <br/>
* SAMPLE_DEADLINE DATE <br/>
* PROPOSAL_DEADLINE DATE <br/>
* STATUS VARCHAR2(60) <br/>
* NOTIFIED NUMBER(1) <br/>
*
* Los atributos que no se encuentran en esta entidad = > {@link BaseEntity} -->
* atributos de auditoria.
*/
//@formatter:on.
@NamedQueries({
@NamedQuery(name = CollectionAssignement.RETRIEVE_BY_SUPPLIER, query = "SELECT ca from CollectionAssignement ca WHERE ca.supplier.labelSupplierId =:labelSupplierId") })
@Entity
@Table(name = "GPE_COLLECTION_ASSIGNEMENTS")
@SequenceGenerator(name = "COLLECTION_ASSIGNEMENT_ID_S", sequenceName = "GPE_COLLECTION_ASSIGNEMENT_S", allocationSize = 1)
public class CollectionAssignement extends BaseEntity implements Serializable {
/** Generated serial version id. */
private static final long serialVersionUID = 7140950871330380100L;
/** The Constant RETRIEVE_BY_SUPPLIER. */
public static final String RETRIEVE_BY_SUPPLIER = "retrieveBySupplier";
/** The collection assignement id. */
@Id
@GeneratedValue(generator = "COLLECTION_ASSIGNEMENT_ID_S", strategy = GenerationType.SEQUENCE)
@Column(name = "COLLECTION_ASSIGNEMENT_ID")
private Long collectionAssignementId;
/** The collection. */
@EditableField
@ManyToOne
@JoinColumn(name = "COLLECTION_ID")
private Collection collection;
/** The supplier. */
@EditableField
@ManyToOne
@JoinColumn(name = "SUPPLIER_ID")
private LabelSupplier supplier;
/** The season. */
@EditableField
@ManyToOne
@JoinColumn(name = "SEASON_ID")
private ActivatableSeason season;
/** The price list. */
@OneToMany(mappedBy = "assignement", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Price> priceList;
/** The sample deadline. */
@EditableField
@Column(name = "SAMPLE_DEADLINE")
@Temporal(TemporalType.DATE)
private Date sampleDeadline;
/** The proposal deadline. */
@EditableField
@Column(name = "PROPOSAL_DEADLINE")
@Temporal(TemporalType.DATE)
private Date proposalDeadline;
/** The assignement date. */
@EditableField
@Column(name = "ASSIGNEMENT_DATE")
@Temporal(TemporalType.DATE)
private Date assignementDate;
/** The creation mode. */
@EditableField
@Column(name = "CREATION_MODE")
private String creationMode;
/** The status. */
@EditableField
@Column(name = "STATUS")
private String status;
/** The notified. */
@EditableField
@Column(name = "NOTIFIED")
private Boolean notified;
/** The development list. */
@OneToMany(mappedBy = "assignement")
private List<Development> developmentList;
//@formatter:off
/**
*
* Contiene el mapeo de la siguiente entidad: <br/>
* PRD_OWNER.BET_LABELS <br/>
* Nombre Nulo Tipo <br/>
*------------------- -------- -------------- <br/>
* <b>LABEL_ID NOT NULL NUMBER </b> <br/>
* VERSION NUMBER <br/>
* REFERENCIA NOT NULL VARCHAR2(20) <br/>
* ACTIVA NOT NULL NUMBER <br/>
* ETI_PVP NUMBER <br/>
* ETI_CAL_CCO NUMBER <br/>
* LEYENDA_ESP VARCHAR2(4000) <br/>
* LEYENDA_ENG VARCHAR2(4000) <br/>
* TIPO_LABEL_ID NOT NULL NUMBER <br/>
* RELATED_LABEL_ID NUMBER <br/>
* FORMATO_ID NOT NULL NUMBER <br/>
* AMBITO_ID NOT NULL NUMBER <br/>
* MANGO_MNG_LK_ID NUMBER <br/>
* CREATED_BY NOT NULL NUMBER <br/>
* CREATION_DATE NOT NULL TIMESTAMP(6) <br/>
* LAST_UPDATED_BY NOT NULL NUMBER <br/>
* LAST_UPDATE_DATE NOT NULL TIMESTAMP(6) <br/>
* IMAGE BLOB <br/>
* INTERIOR_EXTERIOR VARCHAR2(30) <br/>
* EXPORTED NUMBER(6) <br/>
* TOBE_EXPORTED NUMBER(6) <br/>
* SAP_EXPORT_STATUS NUMBER(6) <br/>
* LAST_SAP_EXPORT_TRY TIMESTAMP(6) <br/>
*
* Los atibutos de la entidad relacionados con auditoria se encuentran en la entidad heredada --> {@link BaseEntity}
*
*/
//@formatter:on.
@Entity
@Table(name = "BET_LABELS")
@SequenceGenerator(name = "LABELS_ID_S", sequenceName = "BET_LABELS_SEQ", allocationSize = 1)
public class Label extends BaseEntity implements Serializable {
/** Generated serial version id. */
private static final long serialVersionUID = -5428182745695196613L;
/** The label id. */
@Id
@GeneratedValue(generator = "LABELS_ID_S", strategy = GenerationType.SEQUENCE)
@Column(name = "LABEL_ID", nullable = false)
private Long labelId;
/** The activa. */
@Column(nullable = false)
private Long activa;
/** The exported. */
@Column(nullable = false)
private Long exported;
/** The tobe exported. */
@Column(name = "TOBE_EXPORTED", nullable = false)
private Long tobeExported;
/** The eti cal cco. */
@Column(name = "ETI_CAL_CCO")
private Long etiCalCco;
/** The eti pvp. */
@Column(name = "ETI_PVP")
private Long etiPvp;
/** The leyenda eng. */
@Column(name = "LEYENDA_ENG", length = 4000)
private String leyendaEng;
/** The leyenda esp. */
@Column(name = "LEYENDA_ESP", length = 4000)
private String leyendaEsp;
/** The referencia. */
@Column(nullable = false, length = 20)
private String referencia;
/** The version. */
@Version
private Long version;
/** The int ext. */
@Column(name = "INTERIOR_EXTERIOR")
private String int_ext;
// XXX Lazy fetching does not work in this context according to
/** The image. */
// http://stackoverflow.com/questions/2112508/basicfetch-fetchtype-lazy-does-not-work
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(name = "IMAGE")
private byte[] image;
// Linkado a las tablas de MNG_OWNER
/** The mango mng lk id. */
@Column(name = "MANGO_MNG_LK_ID", nullable = true)
private Long mangoMngLkId;
// Relaciones
/** The season list. */
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "BET_LABEL_SEASONS", joinColumns = { @JoinColumn(name = "LABEL_ID") }, inverseJoinColumns = { @JoinColumn(name = "SEASON_ID") })
private List<ActivatableSeason> seasonList;
/** The format. */
@ManyToOne
@JoinColumn(name = "FORMATO_ID")
private LabelFormat format;
/** The kind of label. */
@ManyToOne
@JoinColumn(name = "TIPO_LABEL_ID")
private KindOfLabel kindOfLabel;
//@formatter:off
/**
* Contiene el mapeo de la siguiente entidad: <br/>
* PRD_OWNER.GPE_LABEL_SUPPLIERS <br/>
*Nombre Nulo Tipo <br/>
*----------------- -------- -------------------<br/>
*<b>LABEL_SUPPLIER_ID NOT NULL NUMBER </b> <br/>
*CREDITOR_ID NUMBER <br/>
*NAME NOT NULL VARCHAR2(256 CHAR) <br/>
*COMMENTS VARCHAR2(2000 CHAR) <br/>
*CODE VARCHAR2(30) <br/>
*TERRITORY_CODE VARCHAR2(2) <br/>
*CREATED_BY NOT NULL NUMBER <br/>
*CREATION_DATE NOT NULL TIMESTAMP(6) <br/>
*LAST_UPDATED_BY NOT NULL NUMBER <br/>
*LAST_UPDATE_DATE NOT NULL TIMESTAMP(6) <br/>
*STATUS VARCHAR2(30) <br/>
*TECHNICAL_DETAILS VARCHAR2(30) <br/>
*ETHIC_CODE VARCHAR2(30) <br/>
*CONTRACT VARCHAR2(30) <br/>
*TYPE VARCHAR2(30) <br/>
*LABEL_TYPE VARCHAR2(30) <br/>
*SUPPLIER_TYPE VARCHAR2(30) <br/>
*
* Los atributos de la entidad relacionados con auditoria se encuentran en la entidad heredada --> {@link BaseEntity}
*/
//@formatter:on.
@Entity
@NamedQueries({ @NamedQuery(name = LabelSupplier.RETRIEVE_BY_NAME_QUERY, query = "SELECT supplier FROM LabelSupplier supplier WHERE supplier.name = :name"),
@NamedQuery(name = LabelSupplier.RETRIEVE_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON, query = "SELECT supplier FROM LabelSupplier supplier INNER JOIN supplier.seasonList season WHERE season.seasonId = :seasonId AND supplier.territory.territoryCode = :territoryCode ORDER BY supplier.name ASC"),
@NamedQuery(name = LabelSupplier.RETRIEVE_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON_MULTIPLE_TERRITORI, query = "SELECT supplier FROM LabelSupplier supplier INNER JOIN supplier.seasonList season WHERE season.seasonId = :seasonId AND supplier.territory.territoryCode IN :territoryCode ORDER BY supplier.name ASC"),
@NamedQuery(name = LabelSupplier.RETRIEVE_MISSING_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON, query = "SELECT supplier FROM LabelSupplier supplier INNER JOIN supplier.seasonList season WHERE season.seasonId = :seasonId AND supplier.territory.territoryCode = :territoryCode and supplier.labelSupplierId not in :supplierIds ORDER BY supplier.name ASC") ,
@NamedQuery(name = LabelSupplier.RETRIEVE_RELALTED_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON, query = "SELECT supplier FROM LabelSupplier supplier INNER JOIN supplier.seasonList season WHERE season.seasonId = :seasonId AND supplier.territory.territoryCode = :territoryCode and supplier.labelSupplierId in :supplierIds ORDER BY supplier.name ASC") ,
@NamedQuery(name = LabelSupplier.RETRIEVE_BY_SUPPLIER_CODE, query = "SELECT supplier FROM LabelSupplier supplier WHERE supplier.creditor.user.userId = :code"),
@NamedQuery(name = LabelSupplier.RETRIEVE_ACTIVE_SUPPLIERS, query = "SELECT supplier FROM LabelSupplier supplier ORDER BY supplier.name ASC"),
@NamedQuery(name = LabelSupplier.RETRIEVE_LIKE_NAME_QUERY, query = "SELECT supplier FROM LabelSupplier supplier WHERE UPPER(supplier.name) LIKE UPPER(:name)")})
@Table(name = "GPE_LABEL_SUPPLIERS")
@SequenceGenerator(name = "GPE_LABEL_SUPPLIER_ID_S", sequenceName = "GPE_LABEL_SUPPLIERS_S", allocationSize = 1)
public class LabelSupplier extends BaseEntity implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 6967594085491181944L;
/** The Constant RETRIEVE_BY_NAME_QUERY. */
public static final String RETRIEVE_BY_NAME_QUERY = "retrieveByNameQuery";
/** The Constant RETRIEVE_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON. */
public static final String RETRIEVE_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON = "retrieveActiveSuppliersByTerritoryCode";
/** The Constant RETRIEVE_MISSING_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON. */
public static final String RETRIEVE_MISSING_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON = "retrieveMissingActiveSuppliersByTerritoryCode";
/** The Constant RETRIEVE_RELALTED_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON. */
public static final String RETRIEVE_RELALTED_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON = "retrieveRelatedActiveSuppliersByTerritoryCode";
/** The Constant RETRIEVE_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON_MULTIPLE_TERRITORI. */
public static final String RETRIEVE_ACTIVE_SUPPLIERS_BY_TERRITORY_CODE_SEASON_MULTIPLE_TERRITORI = "retrieveMissingActiveSuppliersByMultipleTerritoryCode";
/** The Constant RETRIEVE_BY_SUPPLIER_CODE. */
public static final String RETRIEVE_BY_SUPPLIER_CODE = "retrieveBySupplierCode";
/** The Constant RETRIEVE_ACTIVE_SUPPLIERS. */
public static final String RETRIEVE_ACTIVE_SUPPLIERS = "retrieveActiveSuppliers";
/** The Constant RETRIEVE_LIKE_NAME_QUERY. */
public static final String RETRIEVE_LIKE_NAME_QUERY = "retrieveLikeNameQuery";
/** The label supplier id. */
@Id
@Column(name = "LABEL_SUPPLIER_ID", nullable = false)
@GeneratedValue(generator = "GPE_LABEL_SUPPLIER_ID_S", strategy = GenerationType.SEQUENCE)
private Long labelSupplierId;
/** The code. */
@Column(unique = true, length = 30)
private String code;
/** The comments. */
@Column(length = 2000)
private String comments;
/** The contract. */
@Column(length = 30)
private String contract;
/** The ethic code. */
@Column(name = "ETHIC_CODE", length = 30)
private String ethicCode;
/** The label type. */
@Column(name = "LABEL_TYPE", length = 30)
private String labelType;
/** The name. */
@Column(nullable = false, length = 256)
private String name;
/** The status. */
@Column(length = 30)
private String status;
/** The supplier type. */
@Column(name = "SUPPLIER_TYPE", length = 30)
private String supplierType;
/** The technical details. */
@Column(name = "TECHNICAL_DETAILS", length = 30)
private String technicalDetails;
/** The type. */
@Column(length = 30)
private String type;
/** The creditor. */
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "CREDITOR_ID")
private CreditorBet creditor;
/** The territory. */
@ManyToOne
@JoinColumn(name = "TERRITORY_CODE")
private ActivatableTerritory territory;
/** The label supplier contact. */
@OneToOne(mappedBy = "labelSupplier" , cascade=CascadeType.ALL)
private LabelSupplierContact labelSupplierContact;
/** The season list. */
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "GPE_SEASONS_SUPPLIERS", joinColumns = { @JoinColumn(name = "LABEL_SUPPLIER_ID") }, inverseJoinColumns = { @JoinColumn(name = "SEASON_ID") })
private List<ActivatableSeason> seasonList;
Sql:
StringBuilder hastaLosCojones= new StringBuilder(
" SELECT BLC1.LABEL_COLECCTIONS_ID, BLC1.ACTIVE, BLC1.COLLECTION_ID, "
+ "BLC1.COMMENTS, BLC1.FILE_SUPPLIER_CONTENT_TYPE, BLC1.LABEL_ID, BLC1.RELATED_LABEL_COLLECTION_ID, "
+ "BLC1.RELATED_SEASON_ID, BLC1.SAMPLE "
+ "FROM BET_LABEL_SEASONS BLS, BET_LABEL_COLLECTIONS BLC1 "
+ "WHERE BLS.LABEL_ID = BLC1.LABEL_ID " + "AND BLC1.COLLECTION_ID = " + idCol + " "
+ "AND BLS.SEASON_ID = " + seasonDestiny + " " + "AND EXISTS (SELECT 1 "
+ " FROM GPE_COLLECTION_ASSIGNEMENTS GPE, BET_LABEL_COLLECTIONS BLC "
+ " WHERE GPE.COLLECTION_ID = BLC.COLLECTION_ID "
+ " AND GPE.COLLECTION_ID = BLC1.COLLECTION_ID " + " AND BLC.LABEL_ID = BLC1.LABEL_ID ");
hastaLosCojones.append(generadorDeOrs(idSuppliersToCopy, " GPE.SUPPLIER_ID"));
hastaLosCojones.append(" AND GPE.SEASON_ID = ");
hastaLosCojones.append(seasonOrigin);
JPQL查询:
select lb from LabelCollection lb join lb.label.seasonList ls
where lb.collection.collectionId = :colId and ls.seasonId = :seasonDestiny and exists( select 1 from CollectionAssignement ca
where ca.collection.collectionId = lb.collection.collectionId
and ca.supplier.labelSupplierId in :idSuppliersToCopy and ca.season.seasonId = :seasonOrigin)
TY。