SAP JPA simple query
Hello, experts!
I have a simple entity
@Entity
@Table( schema = "dbo", name = "class")
public class ClassEntity {
private Long id;
@Id
@Column(name="id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
public Long getId() {
return id;
public void setId(Long id) {
this.id = id;
I have about 10.000 records in this table. The simplest query "SELECT c FROM ClassEntity c WHERE c.id=:id" tooks 3-4 seconds! I have found (using mssql profiler) that SAP JPA implementation selects ALL records and only then returns the one I need!
Moreover, query "SELECT count(c) FROM ClassEntity c" tooks 3-4 seconds too, and its behaviour is the same! Have anyone an idea, whats going on? How can I select just 1 record (ClassEntity) from the table?
Thanks for any advice.
Hi Andrey,
the behavior you are describing would be absolutely unexpected.
Could you please double check using the SQL Trace (http://<host>:<port>/OpenSQLMonitors) that the generated SQL is a you are describing it.
-Adrian
Similar Messages
-
Hi All,
In Hibernate we can see the query by setting in persistence xml file
<property name="show_sql">true</property>
Do we have anything like this in SAP JPA so that i can see the actual query ?
If not is there any place in Server where can I check the fired query?
Many ThanksHi Arvind,
You can monitor JPA Cache, for more details please have look of the below help
Using JPA Monitors - Monitoring - SAP Library
Thanks,
Hamendra -
Dear experts,
I have a WD application with EJB model. I have faced strange JPA exception (I am using SAP JPA implementation).
This is 2 Entities with relationship
@Entity
@Table( schema = "dbo", name = "class")
public class ClassEntity {
private Long id;
@Id
@Column(name="id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
public Long getId() {
return id;
public void setId(Long id) {
this.id = id;
private Collection<ClassAttributeEntity> classAttributesById;
@OneToMany(mappedBy = "classByClassId", fetch=FetchType.LAZY)
public Collection<ClassAttributeEntity> getClassAttributesById() {
return classAttributesById;
public void setClassAttributesById(Collection<ClassAttributeEntity> classAttributesById) {
this.classAttributesById = classAttributesById;
@Entity
@Table( schema = "dbo", name = "class_attribute")
public class ClassAttributeEntity{
private Long id;
@Id
@Column(name="id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
public Long getId() {
return id;
public void setId(Long id) {
this.id = id;
private ClassEntity classByClassId;
@ManyToOne
@JoinColumn(name = "class_id", referencedColumnName = "id")
public ClassEntity getClassByClassId() {
return classByClassId;
public void setClassByClassId(ClassEntity classByClassId) {
this.classByClassId = classByClassId;
I want to execute JPQL query
"SELECT c FROM ClassEntity c"
; But I get this exception:
javax.persistence.PersistenceException: The relationship >>classAttributesById<< of entity {test.ClassEntity(id=1686)}cannot be loaded because the entity is detached
I can overcome it using EAGER loading -
@OneToMany(mappedBy = "classByClassId", fetch=FetchType.EAGER)
, but I really dont need ClassAttributes in this situation! I have many thousands of classes and eager loading provides extremly poor perfomance. What can I do with this problem?
Thanks in advance for any advice.Hi Andrey,
I assume you are getting the exception if you atempt to access "classAttributesById" ouside the transaction, in which you executed the query, i.e. after the persistence context, in which the query has been executed is closed.
You have got to make sure that all entities you need to access are read as long as the persistence context executing the query is still open.
How to address this depends a bit on whether you need to access all related entites or only some.
If you need to access the relationship "classAttributesById" for only some instances of "ClassEntity", you could for example call size() on "classAttributesById" for these selected instances of "ClassEntity" (within the same transaction/persistence context".
If you need to access all related entities, theoretically, fetchType = EAGER would be the right choice. However, as you have observed, SAP JPA can't handle this efficiently at the time beeing. Therefore,
I'd rather suggest that you firstly load all related attributes with a query
"SELECT ca FROM ClassAttributeEntity ca"
and secondly load the "ClassEntity"s
"SELECT c FROM ClassEntity c"
this should execute efficiently.
Sorry for the inconvenience.
-Adrian -
Hello,
I'm operating on a large table with a few million of records using SAP JPA running on AS Java 7.3.1 and Oracle 11g. While analyzing a performance issue, I came across a DB trace that led me to think that the setMaxResults() method on Query objects may not be working the way I think they were.
I execute a SELECT and apply setMaxResults(100) to the DB along with a WHERE clause, but Oracle SQL trace shows only the SELECT and WHERE clauses. I expect setMaxResult to be applied as a ROWNUM parameter at the end of the WHERE clause, so if I execute a statement like:
Query q = "SELECT ent FROM ENTLargeTable ent WHERE ent.type = 1";
List list = em.createQuery(queryString).setMaxResults(100).getResultList();
DB trace shows:
SELECT id, name, type FROM LargeTable WHERE type = 1 ORDER BY id
where I expect it to be something like:
SELECT id, name, type FROM LargeTable WHERE type = 1 and ROWNUM < 100 ORDER BY id
My list is 100 records long indeed, but I run into Oracle TMP and performance related issues probably because this is trying to scan the whole table first.
Appreciate any ideas on this.
Kind Regards,
GökhanHi Gökhan,
As you say the "list is 100 records long indeed", it behaves correctly as defined in the JPA spec - though I agree there is most likely potential for optimization. The best approach would be to open an SAP support ticket.
Cheers,
--Vlado -
SAP JPA - case-insensitive search
Hi there, is it possible to have a case-insensitive search with SAP JPA? The keywords UPPER, LOWER aren't available in the query (OpenSQL limitation I guess).
The only way I see is to create a duplicates columns for the search relative atributes and make the data upper or lower case before save. May be there is another options? More suitable and elegant?Hi,
you may bypass openSQL by native queries.
Make sure that you use the hint described in
http://help.sap.com/saphelp_nwce72/helpdata/en/4a/0cf02870c540caab611d56220ec0cb/frameset.htm
together with createNativeQuery.
But anyway, the approach with duplicates columns enables you to create indexes on these UPPER columns. It is not too bad.
Regards,
Rolf -
Simple Query returns no result
We have a problem with a simple query on a "old" Table in our Database. The Table has following Structure:
CREATE TABLE <table_name>
ROLE_ID INTEGER NOT NULL,
ROLE_NAME VARCHAR (99) ascii NOT NULL,
OBJECTDATA LONG BYTE,
UNIQUE (ROLE_NAME)
The table containts two rows and following querys get these results:
select role_id, role_name from <schema>.<table_name>
--> 2 rows
select role_id, role_name from <schema>.<table_name>
order by role_id
--> 2 rows
select role_id, role_name from <schema>.<table_name>
order by role_name
--> 0 rows ?? confusion
When we create a "new" table with the same structure, and insert the same content to this new table, the queries are working correctly.
What happened with our "old" table, so that these simple queries don't function anymore?
(Database Kernel 7.6.05 Build 009-123-191-997)
thx
gerri
Edited by: Gerfried on Jul 17, 2009 11:42 AMOk, Gerfried send me the dump file and this is what was in it:
INV ROOT/LEAF 15857 perm entries : 0 [block 0]
bottom : 81 filevers: dummy convvers: 9
writecnt: 1
00001 nodepage.pno: 15857 nodepage.pt : data
00006 nodepage.pt2: inv nodepage.chk: checksumData
00008 nodepage.mde: empty
08181 nd_checksum : 61937 nodepge2.pno: 15857
08189 nodepge2.pt : data nodepge2.pt2: inv
08191 nodepge2.chk: checksumData
08192 nodepge2.mde: empty
00009 nd_bottom : 81 nd_rec_cnt : 0
00017 nd_level : 0
00019 nd_filestate: empty
00020 nd_sorted : false nd_root : 15857/F13D0000
00025 nd_right : nil_pno nd_left : nil_pno
00033 nd_last : nil_pno nd_conv_vers: 9
00045 nd_str_vers : nil_pno nd_file_vers: dummy
00052 ndPageVersio: 0 nd_inv_usage: 0
00057 nd_leaf_cnt : 1 nd_treeleavs: nil
00065 nd_trans_id : nil ndInvRoot : nil_pno
00077 nd_write_cnt: 1
END OF FILE
Obviously the reason for not delivering any data for the query is: this index is empty.
See "nd_filestate: empty" !
For some reasons (that I really don't know - sorry about that) this index had not been maintained anymore, since a very long time.
"nd_conv_vers: 9" tells us that it was the 9th savepoint that wrote down this page to the disks and that it had not been touched since then.
To view the current converter version you may just use the db_restartinfo command in dbmcli.
If you were a SAP customer the next thing I'd check would be with which database version these indexes had been created, what the internal file state is etc. - just to figure out the root cause.
As such an analysis is basically not possible via this forum all I can propose is to look for those indexes (containing 0 entries although the table has more rows) and rebuild them.
This statement should do the trick:
select i.owner, i.indexname, i.tablename, if.*
from files if join files tf on if.primaryfileid=tf.fileid
join indexes i on if.fileid=i.fileid
where if.entrycount =0
and if.type ='INDEX'
and tf.entrycount >0
best regards,
Lars -
SAP-JPA changes version of unchanged entities
Hi all:
We are having a problem with an application that we developed using Sap NetWeaver 7.1 . We are having optimisticlock exception in some of the transactions that we have in the application, checking this situation we found that SAP-JPA is updating the version field for entities that we haven't change. Why is this happening?Hi Adrian:
I'm sending the following:
1. The ejb's method that we are using to execute the query.
2. The query.
3. The entities that are part of the query, if you need I can send you the related entities.
This is the method that we are calling from webDynpro.
@TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)
public List<Object> buscarOrdenesFabricacion(String codigoLote){
ArrayList<Object> listaParametros = new ArrayList<Object>();
listaParametros.add(codigoLote);
Parametro parametro = new Parametro();
parametro.setParametros(listaParametros);
//parametro = null;
List<Object> ordenFabricacion = (List<Object>)servicioCrud.findNamedQuery("OrdenFab.buscarPor_Lote_tipoSemi", parametro);
if(ordenFabricacion.size() == 0){
return null;
return ordenFabricacion;
This method is from an EJB that we use to handle all the DB interaction (DAO)
@TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)
public List findNamedQuery(String namedQuery, Parametro parametro) {
super.setEntityManager(this.entityManager);
return super.findNamedQuery(namedQuery, parametro);
In this EJB we are intantiating the entityManager in this way
@PersistenceContext(unitName="devCrystal~0~entidades~crystal.com.co")
protected EntityManager entityManager;
@Resource(name="ORDENES")
protected javax.sql.DataSource dataSource;
We are handling the transaction by BEAN.
This is the parent class for the above EJB.
@TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)
public List findNamedQuery(String namedQuery, Parametro parametro) {
List retorno = null;
Query query = this.entityManager.createNamedQuery(namedQuery).setFlushMode(FlushModeType.COMMIT);
setParametros(query, parametro);
retorno = query.getResultList();
return retorno;
protected Query setParametros(Query query, Parametro parametro) {
if (parametro != null) {
List<Object> listaParametros = parametro.getParametros();
if (parametro != null && listaParametros != null) {
for (int i = 1; i <= listaParametros.size(); i++) {
query.setParameter(i, listaParametros.get(i - 1));
return query;
QUERY
<named-native-query name="OrdenFab.buscarPor_Lote_tipoSemi" result-class="co.com.crystal.entidades.produccion.OrdenFabricacion">
<query><![CDATA[ SELECT of.*
FROM tb_ordenfabricacion of
WHERE of.co_ordenfabricacion IN
(SELECT DISTINCT tb_operacionlote.co_ordenfabricacion
FROM tb_operacionlote
WHERE tb_operacionlote.fh_terminacion IS NULL AND tb_operacionlote.co_lote = ?)]]>
</query>
</named-native-query >
Entities
package co.com.crystal.entidades.produccion;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;
@Entity
@Table(name="TB_ORDENFABRICACION")
public class OrdenFabricacion implements Serializable {
@Id
@Column(name="CO_ORDENFABRICACION")
private String coOrdenfabricacion;
@Column(name="FH_ACTUALIZACION")
@Temporal(TemporalType.TIMESTAMP)
private Timestamp fhActualizacion;
@Column(name="CA_PROGRAMADA")
private Double caProgramada;
@Version
private int version;
@Column(name="SW_SUMINISTROILIMITADO", nullable = true)
private String swSuministroilimitado;
@Column(name="CO_USUARIO")
private String coUsuario;
@Column(name="FH_CREACION")
@Temporal(TemporalType.TIMESTAMP)
private Timestamp fhCreacion;
@Column(name="VL_PORCENTAJEEXCESO", nullable = true)
private Double vlPorcentajeexceso;
@ManyToOne
@JoinColumn(name="CO_TIPOSEMIELABORADO", nullable = true)
private TipoSemiElaborado coTiposemielaborado;
@ManyToOne
@JoinColumn(name="CO_CENTRO")
private Centro coCentro;
@ManyToOne
@JoinColumn(name="CO_CATEGORIA", nullable = true)
private Categoria coCategoria;
@ManyToOne
@JoinColumn(name="CO_CLASEORDEN")
private ClaseOrden coClaseorden;
@ManyToOne
@JoinColumn(name="CO_MATERIAL")
private Material coMaterial;
@ManyToOne
@JoinColumn(name="CO_TALLA")
private Talla coTalla;
@ManyToOne
@JoinColumn(name="CO_COLOR")
private Color coColor;
/* //@OneToMany(mappedBy="coOrdenfabricacion", fetch=FetchType.LAZY)
@Transient
private List<OperacionLote> tbOperacionLoteCollection;
@OneToMany(mappedBy="coOrdenfabricacion", fetch=FetchType.LAZY)
private List<OperacionOrden> tbOperacionordenCollection;
@OneToMany(mappedBy="coOrdenfabricacion")
private Set<OrdenPrevFab> tbOrdenprevfabCollection;
@OneToMany(mappedBy="coOrdenfabricacion")
private Set<OrdenPrevFab> tbOrdenprevfabCollection;
private static final long serialVersionUID = 1L;
public OrdenFabricacion() {
super();
public String getCoOrdenfabricacion() {
return this.coOrdenfabricacion;
public void setCoOrdenfabricacion(String coOrdenfabricacion) {
this.coOrdenfabricacion = coOrdenfabricacion;
public Timestamp getFhActualizacion() {
return this.fhActualizacion;
public void setFhActualizacion(Timestamp fhActualizacion) {
this.fhActualizacion = fhActualizacion;
public Double getCaProgramada() {
return this.caProgramada;
public void setCaProgramada(Double caProgramada) {
this.caProgramada = caProgramada;
public Centro getCoCentro() {
return this.coCentro;
public void setCoCentro(Centro coCentro) {
this.coCentro = coCentro;
public int getVersion() {
return this.version;
public void setVersion(int version) {
this.version = version;
public String getSwSuministroilimitado() {
return this.swSuministroilimitado;
public void setSwSuministroilimitado(String swSuministroilimitado) {
this.swSuministroilimitado = swSuministroilimitado;
public String getCoUsuario() {
return this.coUsuario;
public void setCoUsuario(String coUsuario) {
this.coUsuario = coUsuario;
public TipoSemiElaborado getCoTiposemielaborado() {
return this.coTiposemielaborado;
public void setCoTiposemielaborado(TipoSemiElaborado coTiposemielaborado) {
this.coTiposemielaborado = coTiposemielaborado;
public Timestamp getFhCreacion() {
return this.fhCreacion;
public void setFhCreacion(Timestamp fhCreacion) {
this.fhCreacion = fhCreacion;
public Double getVlPorcentajeexceso() {
return this.vlPorcentajeexceso;
public void setVlPorcentajeexceso(Double vlPorcentajeexceso) {
this.vlPorcentajeexceso = vlPorcentajeexceso;
public Categoria getCoCategoria() {
return this.coCategoria;
public void setCoCategoria(Categoria coCategoria) {
this.coCategoria = coCategoria;
public ClaseOrden getCoClaseorden() {
return this.coClaseorden;
public void setCoClaseorden(ClaseOrden coClaseorden) {
this.coClaseorden = coClaseorden;
public Material getCoMaterial() {
return this.coMaterial;
public void setCoMaterial(Material coMaterial) {
this.coMaterial = coMaterial;
public Talla getCoTalla() {
return this.coTalla;
public void setCoTalla(Talla coTalla) {
this.coTalla = coTalla;
public Color getCoColor() {
return this.coColor;
public void setCoColor(Color coColor) {
this.coColor = coColor;
public List<OperacionOrden> getTbOperacionordenCollection() {
return this.tbOperacionordenCollection;
public void setTbOperacionordenCollection(List<OperacionOrden> tbOperacionordenCollection) {
this.tbOperacionordenCollection = tbOperacionordenCollection;
public Set<Lote> getTbLoteCollection() {
return tbLoteCollection;
public void setTbLoteCollection(Set<Lote> tbLoteCollection) {
this.tbLoteCollection = tbLoteCollection;
public Set<OrdenPrevFab> getTbOrdenprevfabCollection() {
return this.tbOrdenprevfabCollection;
public void setTbOrdenprevfabCollection(Set<OrdenPrevFab> tbOrdenprevfabCollection) {
this.tbOrdenprevfabCollection = tbOrdenprevfabCollection;
public Set<TbOrdenprevfab> getTbOrdenprevfabCollection() {
return this.tbOrdenprevfabCollection;
public void setTbOrdenprevfabCollection(Set<TbOrdenprevfab> tbOrdenprevfabCollection) {
this.tbOrdenprevfabCollection = tbOrdenprevfabCollection;
public List<OperacionLote> getTbLoteCollection() {
return tbOperacionLoteCollection;
public void setTbLoteCollection(List<OperacionLote> tbLoteCollection) {
this.tbOperacionLoteCollection = tbLoteCollection;
package co.com.crystal.entidades.produccion;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
@Entity
@Table(name="TB_OPERACIONLOTE")
public class OperacionLote implements Serializable {
@EmbeddedId
private OperacionLote.PK pk;
@Column(name="CA_PRIMERAS")
private Integer caPrimeras;
@Column(name="FH_TERMINACION")
@Temporal(TemporalType.TIMESTAMP)
private Timestamp fhTerminacion;
@Column(name="FH_INICIO")
@Temporal(TemporalType.TIMESTAMP)
private Timestamp fhInicio;
@Column(name="FH_ACTUALIZACION")
@Temporal(TemporalType.TIMESTAMP)
private Timestamp fhActualizacion;
@Column(name="FH_CREACION")
@Temporal(TemporalType.TIMESTAMP)
private Timestamp fhCreacion;
@Version
private int version;
@Column(name="CO_USUARIO")
private String coUsuario;
@Column(name="CA_TEORICA")
private Double caTeorica;
@Column(name="CA_TEORICAPLC")
private Double caTeoricaplc;
@ManyToOne
@JoinColumn(name="CS_MAQUINA")
private Maquina csMaquina;
@Column(name="CO_MAQUINA")
private String coMaquina;
@ManyToOne
@JoinColumns({
@JoinColumn(name="CO_ORDENFABRICACION", referencedColumnName="CO_ORDENFABRICACION", insertable=false, updatable=false),
@JoinColumn(name="CO_LOTE", referencedColumnName="CO_LOTE", insertable=false, updatable=false)
private Lote tbLote;
@ManyToOne
@JoinColumns({
@JoinColumn(name="CO_ORDENFABRICACION", referencedColumnName="CO_ORDENFABRICACION", insertable=false, updatable=false),
@JoinColumn(name="CS_OPERACION", referencedColumnName="CS_OPERACION", insertable=false, updatable=false)
private OperacionOrden tbOperacionOrden;
private static final long serialVersionUID = 1L;
public OperacionLote() {
super();
public OperacionLote.PK getPk() {
return this.pk;
public void setPk(OperacionLote.PK pk) {
this.pk = pk;
public Integer getCaPrimeras() {
return this.caPrimeras;
public void setCaPrimeras(Integer caPrimeras) {
this.caPrimeras = caPrimeras;
public Timestamp getFhTerminacion() {
return this.fhTerminacion;
public void setFhTerminacion(Timestamp fhTerminacion) {
this.fhTerminacion = fhTerminacion;
public Timestamp getFhInicio() {
return this.fhInicio;
public void setFhInicio(Timestamp fhInicio) {
this.fhInicio = fhInicio;
public Timestamp getFhActualizacion() {
return this.fhActualizacion;
public void setFhActualizacion(Timestamp fhActualizacion) {
this.fhActualizacion = fhActualizacion;
public Timestamp getFhCreacion() {
return this.fhCreacion;
public void setFhCreacion(Timestamp fhCreacion) {
this.fhCreacion = fhCreacion;
public int getVersion() {
return this.version;
public void setVersion(int version) {
this.version = version;
public String getCoUsuario() {
return this.coUsuario;
public void setCoUsuario(String coUsuario) {
this.coUsuario = coUsuario;
public Double getCaTeorica() {
return this.caTeorica;
public void setCaTeorica(Double caTeorica) {
this.caTeorica = caTeorica;
public Double getCaTeoricaplc() {
return this.caTeoricaplc;
public void setCaTeoricaplc(Double caTeoricaplc) {
this.caTeoricaplc = caTeoricaplc;
@Embeddable
public static class PK implements Serializable {
@Column(name="CO_ORDENFABRICACION")
private String coOrdenfabricacion;
@Column(name="CO_LOTE")
private String coLote;
@Column(name="CS_OPERACION")
private String csOperacion;
private static final long serialVersionUID = 1L;
public PK() {
super();
public String getCoLote() {
return this.coLote;
public void setCoLote(String coLote) {
this.coLote = coLote;
public String getCsOperacion() {
return this.csOperacion;
public void setCsOperacion(String csOperacion) {
this.csOperacion = csOperacion;
public String getCoOrdenfabricacion() {
return this.coOrdenfabricacion;
public void setCoOrdenfabricacion(String coOrdenfabricacion) {
this.coOrdenfabricacion = coOrdenfabricacion;
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
if ( ! (o instanceof PK)) {
return false;
PK other = (PK) o;
return this.coLote.equals(other.coLote)
&& this.csOperacion.equals(other.csOperacion)
&& this.coOrdenfabricacion.equals(other.coOrdenfabricacion);
@Override
public int hashCode() {
return this.coLote.hashCode()
^ this.csOperacion.hashCode()
^ this.coOrdenfabricacion.hashCode();
public Lote getTbLote() {
return tbLote;
public void setTbLote(Lote tbLote) {
this.tbLote = tbLote;
public OperacionOrden getTbOperacionOrden() {
return tbOperacionOrden;
public void setTbOperacionOrden(OperacionOrden tbOperacionOrden) {
this.tbOperacionOrden = tbOperacionOrden;
public Maquina getCsMaquina() {
return csMaquina;
public void setCsMaquina(Maquina csMaquina) {
this.csMaquina = csMaquina;
public String getCoMaquina() {
return coMaquina;
public void setCoMaquina(String coMaquina) {
this.coMaquina = coMaquina;
If you need i can send you also the database traces where you can see the selects and updates over the tables.
I hope that you can help us with this, we are in a huge problem because of this behavior.
Best regards,
Jose Arango. -
How can we remove the commas from the Formula value in SAP BW BEx query
Hi All,
How can we remove the commas from the Formula value in SAP BW BEx query
We are using the formula replacing with characteristic.The characteristic value needs to be display as number with out commas.
Regards
Venkat.Do you want to remove the commas when you run the query on Bex Web or in RSRT?
Regards -
How to write a simple query.
I have a table where I have data shown below. Now, I want to write a simple query which lists me the project and the count of the distinct effective dates for which data is existant there.
Sample data:
Project Task Effective Date (xx_proj_task_data)
101 T1 01-Jan-2008
101 T1 01-Feb-2008
101 T1 01-Mar-2008
101 T2 01-Jan-2008
101 T2 01-Apr-2008
101 T3 01-Apr-2008
102 T1 01-Jan-2008
102 T1 01-Feb-2008
102 T2 01-Apr-2008
103 T1 01-Jan-2008
103 T1 01-Feb-2008
103 T1 01-Mar-2008
103 T1 01-Apr-2008
103 T2 01-May-2008
103 T3 01-Jun-2008
103 T1 01-Jan-2008
103 T1 01-Aug-2008
103 T2 01-Apr-2008
Output Reqd:
Project Count(Distinct Effective Dates)
101 4
102 3
103 7
I can write a query that says:
select project_id, count(1)
from (select distinct project_id, effective_date
from xx_proj_task_data) x
group by project_id;
But, is there a way I can achieve the same by avoiding the inner Query (x) and just by a simple query ?
Thanks!Try below query:
select project_id
, count(distinct effective_date)
from xx_proj_task_data
group by project_id;
--venkata -
Designer support for Subquery against SAP BW Bex Query
BusinessObjects designer has an option in the paramaters window to turn on "Allow Sub-Queries" in a universe that has been created using a olap source. SAP BW BEX Query to be specific. Once turned on, you can build a query and the subquery button and functionality is actually enabled and allows you to build it. When running the query I get an error message "A filter contains a wrong value. You cannot run this query".
Now, I am pretty sure this functionality is not supported on a BW or OLAP source but, I can not find anything definitive from SAP stating that it is not supoorted. So I want to make sure that this is not one of those situations where everyone just says "It's not supported" but really just doesn't know. Does anyone have the official word or link to an SAP statement that this functionality is officially not supported.What I would say is, it won't support. The reason could be, as its not support any structure view in universe designer, that means we cannot create any derived tables where we could use sql query.
I believe the same applies here too. Even if you look at LOV defintions in universe, it won't show any query.
So the same applies to reports.
Hope this helps.
Regards
Gowtham -
Connecting Crystal Reports to SAP BW BEx query
Post Author: mfrank
CA Forum: Data Connectivity and SQL
We have used Crystal Enterprise 8.5 to connect to an SAP BW BEx query in the past, however we are having some difficulties. Rather than trying to upgrade our old CE system, I've been told that we should be able to connect Crystal Reports (2008?) directly to the BW BEx query. I've been trying to accomplish this, but can't seem to find any drivers that will allow the connectivity. When I try to set up a connection using OLAP, the only two options listed are Hyperion and Microsoft OLAP. I have an old version of Brio Query (now Hyperion, now Oracle) that does show up with a driver for BW, but this doesn't show up in my Crystal options.
Can someone give me some advice as to how to connect Crystal Reports to SAP BW? I realize there are licensing issues with running live data without using Crystal Enterprise (or later BO products), but I'm just looking to print a report to a PDF.
ThanksPost Author: A Kumar
CA Forum: Data Connectivity and SQL
Hi mfrank,
I am also facing a similar kind of a problem. Did you get any solution to your problem. If yes, kindly let me know.
Thanks
A kumar -
Simple Query in Oracle Linked Table in MS Access causes full table scan.
I am running a very simple query in MS ACCESS to a linked Oracle table as follows:
Select *
From EXPRESS_SERVICE_EVENTS --(the linked table name refers to EXPRESS.SERVICE_EVENTS)
Where performed > MyDate()
or
Select *
From EXPRESS_SERVICE_EVENTS --(the linked table name refers to EXPRESS.SERVICE_EVENTS)
Where performed > [Forms]![MyForm]![Date1]
We have over 50 machines and this query runs fine on over half of these, using an Oracle Index on the "performed" field. Running exactly the same thing on the other machines causes a full table scan, therefore ignoring the Index (all machines access the same Access DB).
Strangely, if we write the query as follows:
Select *
From EXPRESS_SERVICE_EVENTS
Where performed > #09/04/2009 08:00#
it works fast everywhere!
Any help on this 'phenominon' would be appreciated.
Things we've done:
Checked regional settings, ODBC driver settings, MS Access settings (as in Tools->Options), we have the latest XP and Office service packs, and re-linked all Access Tables on both the slow and fast machines independantly).Primarily, thanks gdarling for your reply. This solved our problem.
Just a small note to those who may be using this thread.
Although this might not be the reason, my PC had Oracle 9iR2 installed with Administratiev Tools, where user machines had the same thing installed but using Runtime Installation. For some reason, my PC did not have 'bind date' etc. as an option in the workarounds, but user machines did have this workaround option. Strangely, although I did not have the option, my (ODBC) query was running as expected, but user queries were not.
When we set the workaround checkbox accordingly, the queries then run as expected (fast).
Once again,
Thanks -
Dear Experts,
Not able to Execute this simple query :
Select T1.JobID , T1.BudgetValue,T1.ActualValue FROM [dbo].[Enprise_JobCost_ActualBudgetView] T1 WHERE T1.TransType = '[%0]'
RegardsHello,
View - A View in simple terms is a subset of a 'virtual table. It can be used to retrieve data from the tables, Insert, Update or Delete from the tables. The Results of using View are not permanently stored in the database.
Stored Procedure - A stored procedure is a group of SQL statements which can be stored into the database and can be shared over the netwrok with different users.
http://www.geekinterview.com/question_details/65914
Better make a UDT for your requirement.
Thanks
Manvendra Singh Niranjan -
Simple Query working on 10G and not working on 11gR2 after upgrade
Hi Folks,
This is the first time i am posting the query in this Blog.
I have a small issue which preventing the UAT Sigoff.
Simple query working fine on 10.2.0.1 and after upgrade to 11.2.0.1 its error out
10.2.0.4:
=====
SQL> SELECT COUNT(*) FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1=1;
COUNT(*)
1
SQL> SELECT COUNT(*) FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1=00001;
COUNT(*)
1
SQL> select ATTRIBUTE1 FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1=1;
ATTRIBUTE1
00001
11.2.0.1:
=====
SQL> SELECT COUNT(*) FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1=1
ERROR at line 1:
ORA-01722: invalid number
SQL> SELECT COUNT(*) FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1=00001
ERROR at line 1:
ORA-01722: invalid number
SQL> select ATTRIBUTE1 FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1='1';
no rows selected
SQL> SELECT COUNT(*) FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1='00001';
COUNT(*)
1
SQL> select ATTRIBUTE1 FROM APPS.HZ_PARTIES HP WHERE ATTRIBUTE_CATEGORY= 'PROPERTY' AND ATTRIBUTE1='00001';
ATTRIBUTE1
00001
++++++++++++++++++++++++++++++++++++++++++++++
SQL > desc APPS.HZ_PARTIES
Name Type
======== ======
ATTRIBUTE1 VARCHAR2(150)
++++++++++++++++++++++++++++++++++++++++++++++
Changes:
Recently i upgraded the DB from 10.2.0.4 to 11.2.0.1
Query:
1.If the type of that row is VARCHAR,why it is working in 10.2.0.4 and why not working in 11.2.0.1
2.after upgrade i analyzed the table with "analyze table " query for all AP,AR,GL,HR,BEN,APPS Schemas--Is it got impact if we run analyze table.
Please provide me the answer for above two questions or refer the document is also well enough to understand.Based on the Answer client will sigoff to-day.
Thanks,
P KumarWhiteHat wrote:
the issue has already been identified: in oracle versions prior to 11, there was an implicit conversion of numbers to characters. your database has a character field which you are attempting to compare to a number.
i.e. the string '000001' is not in any way equivalent to the number 1. but Oracle 10 converts '000001' to a number because you are asking it to compare to the number you have provided.
version 11 doesn't do this anymore (and rightly so).
the issue is with the bad code design. you can either: use characters in the predicate (where field = 'parameter') or you can do a conversion of the field prior to comparing (where to_num(field) = parameter).
I would suggest that you should fix your code and don't assume that '000001' = 1I don't think that the above is completely correct, and a simple demonstration will show why. First, a simple table on Oracle Database 10.2.0.4:
CREATE TABLE T1(C1 VARCHAR2(20));
INSERT INTO T1 VALUES ('1');
INSERT INTO T1 VALUES ('0001');
COMMIT;A select from the above table, relying on implicit data type conversion:
SELECT
FROM
T1
WHERE
C1=1;
C1
1
0001Technically, the second row should not have been returned as an exact match. Why was it returned, let's take a look at the actual execution plan:
SELECT
FROM
TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL));
SQL_ID g6gvbpsgj1dvf, child number 0
SELECT * FROM T1 WHERE C1=1
Plan hash value: 3617692013
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 2 (100)| |
|* 1 | TABLE ACCESS FULL| T1 | 2 | 24 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(TO_NUMBER("C1")=1)
Note
- dynamic sampling used for this statementNotice that the VARCHAR2 column was converted to a NUMBER, so if there was any data in that column that could not be converted to a number (or NULL), we should receive an error (unless the bad rows are already removed due to another predicate in the WHERE clause). For example:
INSERT INTO T1 VALUES ('.0001.');
SELECT
FROM
T1
WHERE
C1=1;
SQL> SELECT
2 *
3 FROM
4 T1
5 WHERE
6 C1=1;
ERROR:
ORA-01722: invalid numberNow the same test on Oracle Database 11.1.0.7:
CREATE TABLE T1(C1 VARCHAR2(20));
INSERT INTO T1 VALUES ('1');
INSERT INTO T1 VALUES ('0001');
COMMIT;
SELECT
FROM
T1
WHERE
C1=1;
C1
1
0001
SELECT
FROM
TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,NULL));
SQL_ID g6gvbpsgj1dvf, child number 0
SELECT * FROM T1 WHERE C1=1
Plan hash value: 3617692013
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 2 (100)| |
|* 1 | TABLE ACCESS FULL| T1 | 2 | 24 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(TO_NUMBER("C1")=1)
Note
- dynamic sampling used for this statement
INSERT INTO T1 VALUES ('.0001.');
SELECT
FROM
T1
WHERE
C1=1;
SQL> SELECT
2 *
3 FROM
4 T1
5 WHERE
6 C1=1;
ERROR:
ORA-01722: invalid numberAs you can see, exactly the same actual execution plan, and the same end result.
The OP needs to determine if non-numeric data now exists in the column. Was the database characterset possibly changed during/after the upgrade?
Charles Hooper
Co-author of "Expert Oracle Practices: Oracle Database Administration from the Oak Table"
http://hoopercharles.wordpress.com/
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc. -
Trying to optimize this simple query
Hi,
I am trying to optimize this simple query but the two methods I am trying actually make things worse.
The original query is:
SELECT customer_number, customer_name
FROM bsc_pdt_account_mv
where rownum <= 100
AND Upper(customer_name) like '%SP%'
AND customer_id IN
SELECT cust_id FROM bsc_pdt_assoc_sales_force_mv
WHERE area_identifier IN (
SELECT area_identifier FROM bsc_pdt_assoc_sales_force_mv
WHERE ad_identifier = '90004918' or rm_identifier = '90004918' or tm_identifier = '90004918'
The result set of this query returns me the first 100 rows in 88 seconds and they are all distinct by default (don't know why they are distinct).
My first attempt was to try to use table joins instead of the IN conditions:
SELECT
distinct -- A: I need to use distinct now
customer_number, customer_name
FROM bsc_pdt_account_mv pdt,
bsc_pdt_assoc_sales_force_mv asf,
SELECT distinct area_identifier FROM bsc_pdt_assoc_sales_force_mv
WHERE ad_identifier = '90004918' or rm_identifier = '90004918' or tm_identifier = '90004918'
) area
where
area.area_identifier = asf.area_identifier
AND asf.cust_id = pdt.customer_id
AND Upper(customer_name) like '%SP%'
AND rownum <= 100 -- B: strange when I comment this out
order by 1
I dont understand two things with this query. First issue, I now need to put in the distinct because the result set is not distinct by default. Second issue (very strange), when I put the rownum condition (<100) I get two rows in 1.5 seconds. If I remove the condition, I get 354 rows (whole result set) in 326 seconds.
My second attempt was to use EXISTS instead of IN:
SELECT
customer_number, customer_name
FROM bsc_pdt_account_mv pdt
where Upper(customer_name) like '%SP%'
AND rownum <= 100
AND EXISTS
select 1 from
bsc_pdt_assoc_sales_force_mv asf,
SELECT distinct area_identifier FROM bsc_pdt_assoc_sales_force_mv
WHERE ad_identifier = '90004918' or rm_identifier = '90004918' or tm_identifier = '90004918'
) area
where
area.area_identifier = asf.area_identifier
AND asf.cust_id = pdt.customer_id
This query returns a similar distinct result set as teh original one but takes pretty much the same time (87 seconds).The query below hangs when run in TOAD or PL/SQL Dev. I noticed there is no rows returned from the inner table for this condition.
SELECT customer_number, customer_name
FROM
bsc_pdt_account_mv pdt_account
where rownum <= 100
AND exists (
SELECT pdt_sales_force.cust_id
FROM bsc_pdt_assoc_sales_force_mv pdt_sales_force
WHERE pdt_account.customer_id = pdt_sales_force.cust_id
AND (pdt_sales_force.rm_identifier = '90007761' or pdt_sales_force.tm_identifier = '90007761') )
ORDER BY customer_name
-- No rows returned by this query
SELECT pdt_sales_force.cust_id
FROM bsc_pdt_assoc_sales_force_mv pdt_sales_force
WHERE pdt_sales_force.rm_identifier = '90007761' or pdt_sales_force.tm_identifier = '90007761'
Maybe you are looking for
-
Can i recycle my old iPhone for a discount on a new one like I can with iPods?
I'm going to by an iPhone 4, but I was wondering if I can recycle my old iPhone in for a discount. I know I can do that wit iPods. If you turn in your old iPod and get 10% off the purchase of a new one. Are iPhones the same?
-
Method Signature Not Enforced ?
Good day to the forum. This is an odball to me. Please tell me what's wrong with this picture..... public void foo(double d) public void bar() int i = 100; foo(i); }Why is JBuilder and my compiler allowing this?
-
Wrote the current Date and Time in the backend
HI everyone, I created a table view, where I display several records. Right now I will add an record to this table, which should be written back in the backend and automaticaly add the current date and time. But I don´t know to make this. I tried sev
-
Avi codec pack for mac??
Hi, We have recently switched over a few mac machines and are slowly getting the hang of them. After having issues playing back avi's on the machine i have downloaded the Perian codec pack for mac which allows me to play the files in quicktime etc an
-
Clicking on "Compose", "Reply" or "Forward" in Yahoo Mail does not do anything. I troubleshot the problem with Yahoo directly and they feel that the issue is with Mozilla Firefox. I do not have this issue when using Internet Explorer. Other buttons i