Composite IN clause in JPA
Hi ,
Does JPQL supports multi Column "in" clause , for example :
select o
from O o
where (o.a,o.b) in (select e.a , e.b from E e) ??
Best Regards,
No it does not. Not all databases support this syntax either (Oracle does).
<p>
You can use a native query in JPA with SQL for this type of query.
<p>
You might be able to define this using TopLink Expressions as well, but this may require some tweaking, as it is not directly supported.
<p>---
<br>James Sutherland
<br>Oracle TopLink, EclipseLink
<br>Wiki: Java Persistence, EclipseLink
Similar Messages
-
Deployment of SCA composite with Spring and JPA fails on WLS 10.3.3
Hi,
We want to use JPA as Persistence Layer (EclipseLink as Persistence Provider) in a Spring managed Bean in a SOA Composite (SCA).
We configured our persistence.xml and spring configuration as described below.
We are using JDeveloper 11.1.1.3 and WLS 10.3.3 with SOA Suite 11.1.1.3.
The Deployment fails with the following Exception
+Could not instantiate bean class [org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebLogic ClassLoader because WebLogic 10 API classes are not available+
We are not sure how to deal with the "WebLogic 10 API classes are not available" message. Is there a lib we have to add to the SCA composite or do we have to change the WLS configuration somehow?
We already tried a lot of configurations of persistence.xml and spring but nothing worked so far.
Exception
Caused By: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver' defined in URL [oramds:/deployed-composites/default/ProjectBServiceSCA_rev1.0/ProjectBServiceSCA.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebLogic ClassLoader because WebLogic 10 API classes are not available
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize WebLogic ClassLoader because WebLogic 10 API classes are not available
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalStateException: Could not initialize WebLogic ClassLoader because WebLogic 10 API classes are not available
at org.springframework.instrument.classloading.weblogic.WebLogicClassLoader.<init>(WebLogicClassLoader.java:70)
at org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver.<init>(WebLogicLoadTimeWeaver.java:57)
at org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver.<init>(WebLogicLoadTimeWeaver.java:46)
at sun.reflect.GeneratedConstructorAccessor768.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodException: oracle.classloader.PolicyClassLoader.addInstanceClassPreProcessor(weblogic.utils.classloaders.ClassPreProcessor)
at java.lang.Class.getMethod(Class.java:1605)
at org.springframework.instrument.classloading.weblogic.WebLogicClassLoader.<init>(WebLogicClassLoader.java:62)
at org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver.<init>(WebLogicLoadTimeWeaver.java:57)
at org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver.<init>(WebLogicLoadTimeWeaver.java:46)
at sun.reflect.GeneratedConstructorAccessor768.newInstance(Unknown Source)
Truncated. see log file for complete stacktracepersistence.xml
<?xml version="1.0" encoding="Cp1252" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="SCASpringJPATest">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>performanceTestDS</jta-data-source>
<class>de.prototype.entities.Mainproject</class>
<class>de.prototype.entities.Project</class>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10"/>
<property name="javax.persistence.jtaDataSource"
value="performanceTestDS"/>
</properties>
</persistence-unit>
</persistence>spring.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:sca="http://xmlns.oracle.com/weblogic/weblogic-sca"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-2.5.xsd http://xmlns.oracle.com/weblogic/weblogic-sca META-INF/weblogic-sca.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!--Spring Bean definitions go here-->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="ProjectBServiceSCA"/>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver"/>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="database" value="ORACLE"/>
</bean>
</property>
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager"
class="org.springframework.transaction.jta.WebLogicJtaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="de.prototype.service.ProjectBServiceSCAImpl"
id="projectBService">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<sca:service target="projectBService" name="projectBServiceSCA"
type="de.prototype.service.IProjectBServiceSCA"/>
</beans>We solved the problem by using the org.springframework.instrument.classloading.oc4j.OC4JLoadTimeWeaver. But we are not sure if this is correct. It at least works so far without any problems...
-
Hi,
select t from table t where t.aDate= to_date('26/12/2009','dd/MM/YYYY')throws illegal argument exception.says:"unexpected token "to_date"
How can i query a table by using a Date column in "where" clause?JPA does not have a to_date function as far as I know. But you can easily plug in a parameter and pass a Date object you construct on the java side.
If you absolutely must go down the query path, you'll need to use a native query in stead of a JPQL query. -
Expression in JPA QL select clause
in JPA QL, how do I let put expression in select clause. for example, in SQL, I can do
select cust.first_name,cust.last_name, cust.first_name+cust.last_name as full_name
from ....
or even simpler, just return a constant:
select 1 from tableA
or do some calculation
select 1+2 from tableA
but non of them working using JPA QL
is it posible in JPA QL?Dear
Try the following query
select
lgr_ml,
nvl(lgr_pl,' ') ,
lgr_cr_dr ,
lgr_dpt ,
lgr_tpc,
lgr_sr_no,
decode(lgr_tr_ty,
'P', (select apt_pj_ser from apt where lgr_sr_no = apt_sr_no) ,
'') lgr_pj_se
from ledger
or
Use can also use case statment
( case
when lgr_tr_ty = 'P' then (select apt_pj_ser from apt where lgr_sr_no = apt_sr_no)
else ' ' end)
Regards
Singh -
HAVING clause error in JPA 2 examples
In Chapter 8: Query Language of the Pro JPA 2 Mastering the Java Persistence API book, the jpqlExamples WAR has this query:
SELECT e, COUNT(p)
FROM Employee e JOIN e.projects p
GROUP BY e
HAVING COUNT(p) >= 2
When executed, the following error occurs:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Error compiling the query [SELECT e, COUNT(p) FROM Employee e JOIN e.projects p GROUP BY e HAVING COUNT(p) >= 2], line 1, column 80: invalid HAVING expression [COUNT(p) >= 2] for query with grouping [GROUP BY e]. The HAVING clause must specify search conditions over the grouping items or aggregate functions that apply to grouping items.
I bring this us because I have an application which is getting the same error and need a fix. If the query is indeed legal in JPA 2, then why the error? If if it is my setup however, then I would like suggestions on fixing it. I am using GlassFish v3 (build 74.2), updated regularly with the Update Tool.The bug has been reopened. Now it says:
Reopening because there is some debate about whether this should be supported
by the spec. Some people read the spec to say the above query is allowed - I
am not convinced, but discussion can be appended to this bug if necessary.
This is Bug 308482, and I assume at least a few might want to take a look.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=308482 -
Performance - composite index with 'OR' in 'WHERE' clause
I have a problem with the performance of the following query:
select /*+ index_asc(omschact oma_index1) */ knr, projnr, actnr from omschact where ((knr = 100 and actnr > 30) or knr > 100)
and rownum = 1;
(rownum used only for test purpose)
index:
create index on omschact (knr, projnr);
Execution plan:
Id Operation
0 SELECT STATEMENT
1 COUNT STOPKEY
2 TABLE ACCESS BY INDEX ROWID
3 INDEX FULL SCAN
If I'm correct, the 'OR' in the 'WHERE' clause is responsible for the INDEX FULL SCAN, what makes the query slow.
A solution would be then to separate the 'WHERE' clause in 2 separate select's (1 with 'knr = 100 and actnr > 30' and 1 with 'knr > 100' and combine the results with a UNION ALL.
Since it's necessary to have all rows in ascending order (oma_index1) I still have to use an ORDER BY to make sure the order of the rows is correct. This results again in a (too) low performance.
Another solution that does the trick is to create an index with the 2 fields (knr, projnr) concatenated and to use the same in the 'WHERE' clause:
create index oma_index2 on omschact (knr || projnr);
select /*+ index_asc(omschact oma_index2) */ knr, projnr, actnr from omschact where (knr || projnr) > 10030;
I just can't believe this work-around is the only solution, so I was hoping that someone here knows of a better way to solve this.padders,
I'll give the real data instead of the example. The index I really use consists of 4 fields. In this table the fields are just numbers, but in other tables I need to use char-fields in indexes, so that's why I concatenate instead of using formula's (allthough I would prefer the latter).
SQL> desc omschact
Name Null? Type
KNR NOT NULL NUMBER(8)
PROJNR NOT NULL NUMBER(8)
ACTNR NOT NULL NUMBER(8)
REGELNR NOT NULL NUMBER(3)
REGEL CHAR(60)
first methode:
SQL> create index oma_key_001(knr,projnr,actnr,regelnr);
Index created.
SQL> select /*+ index_asc(omschact oma_key_001) */ * from omschact where
2 (knr > 100 or
3 (knr = 100 and projnr > 30) or
4 (knr = 100 and projnr = 30 and actnr > 100000) or
5 (knr = 100 and projnr = 30 and actnr = 100000 and regelnr >= 0));
Execution Plan
Plan hash value: 1117430516
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 11M| 822M| 192K (1)| 00:38:26 |
| 1 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 11M| 822M| 192K (1)| 00:38:26 |
|* 2 | INDEX FULL SCAN | OMA_KEY_001 | 11M| | 34030 (1)| 00:06:49 |
Predicate Information (identified by operation id):
2 - filter("KNR">100 OR "KNR"=100 AND "PROJNR">30 OR "KNR"=100 AND "PROJNR"=30
AND "ACTNR">100000 OR "ACTNR"=100000 AND "KNR"=100 AND "PROJNR"=30 AND
"REGELNR">=0)
second method (same index):
SQL> select * from (
2 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr > 100
3 union all
4 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr > 30
5 union all
6 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr = 30 and actnr > 100000
7 union all
8 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr = 30 and actnr = 100000 and regelnr > 0)
9 order by knr, projnr, actnr, regelnr;
Execution Plan
Plan hash value: 292918786
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 11M| 1203M| | 477K (1)| 01:35:31 |
| 1 | SORT ORDER BY | | 11M| 1203M| 2745M| 477K (1)| 01:35:31 |
| 2 | VIEW | | 11M| 1203M| | 192K (1)| 00:38:29 |
| 3 | UNION-ALL | | | | | | |
| 4 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 11M| 822M| | 192K (1)| 00:38:26 |
|* 5 | INDEX RANGE SCAN | OMA_KEY_001 | 11M| | | 33966 (1)| 00:06:48 |
| 6 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 16705 | 1272K| | 294 (1)| 00:00:04 |
|* 7 | INDEX RANGE SCAN | OMA_KEY_001 | 16705 | | | 54 (0)| 00:00:01 |
| 8 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 47 | 3666 | | 4 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | OMA_KEY_001 | 47 | | | 3 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 1 | 78 | | 4 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | OMA_KEY_001 | 1 | | | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
5 - access("KNR">100)
7 - access("KNR"=100 AND "PROJNR">30)
9 - access("KNR"=100 AND "PROJNR"=30 AND "ACTNR">100000)
11 - access("KNR"=100 AND "PROJNR"=30 AND "ACTNR"=100000 AND "REGELNR">0)
third method:
SQL> create index oma_test(to_char(knr,'00000000')||to_char(projnr,'00000000')||to_char(actnr,'00000000')||to_char(regelnr,'000'));
Index created.
SQL> select /*+ index_asc(omschact oma_test) */ * from omschact where
2 (to_char(knr,'00000000')||to_char(projnr,'00000000')||
3 to_char(actnr,'00000000')||to_char(regelnr,'000')) >=
4 (to_char(100,'00000000')||to_char(30,'00000000')||
5* to_char(100000,'00000000')||to_char(0,'000'))
Execution Plan
Plan hash value: 424961364
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 553K| 55M| 1712 (1)| 00:00:21 |
| 1 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 553K| 55M| 1712 (1)| 00:00:21 |
|* 2 | INDEX RANGE SCAN | OMA_TEST | 99543 | | 605 (1)| 00:00:08 |
Predicate Information (identified by operation id):
2 - access(TO_CHAR("KNR",'00000000')||TO_CHAR("PROJNR",'00000000')||TO_CHAR("
ACTNR",'00000000')||TO_CHAR("REGELNR",'000')>=TO_CHAR(100,'00000000')||TO_CHAR(3
0,'00000000')||TO_CHAR(100000,'00000000')||TO_CHAR(0,'000')) -
[JPA/TOPLINK] is the function "lower" supported in "order by" clause?
In EJB-QL
I can use lower() or upper() in where clause.
But there is always a parse exception thrown when i tried to use it in main clause or order by clause.
works:
select s from Student s where lower(s.name) like 'm%'
exception thrown:
select s from Student s where s.name like 'm%' order by lower(s.name)
OR --------------
Why i am asking this is that the resultset returned from database is not alphabetical sorted but ascii sorted, which means any characters with upper case is always prior to the ones with lower case.
If EJB-QL doesn't support using lower() in order by clause, do I have any other options to avoid this problem?
BTW, it is the Oracle 10g we are using as DB
many thanks,
Xuphey
Edited by: Xuphey on Nov 29, 2007 1:33 AMIf you want to do this, you'd have to use dynamic SQL (execute immediate or DBMS_SQL). For the easier 'execute immediate' approach, you'd do something like
create or replace someProc( someArg varchar2 )
as
strSQL varchar2(4000)
begin
strSQL := <<string containing your SQL statement up to the order by clause>>
strSQL := strSQL || 'ORDER BY ' || someArg
execute immediate strSQL;
endJustin -
I need to dynamically build the order by clause of my query.
I tried this:
<named-query name="list">
<query>
<![CDATA[
SELECT p FROM Person p
ORDER BY :orderby
]]>
</query>
</named-query>
@SuppressWarnings("unchecked")
public List<Person> list(String sort) {
Query query = getEntityManager().createNamedQuery("list");
query.setParameter("orderby", sort);
return query.getResultList();
}But at runtime it throws an exception:
com.microsoft.sqlserver.jdbc.SQLServerException:
L'elemento SELECT identificato da ORDER BY 1 include una variabile nell'espressione che identifica la posizione di una colonna.
Le variabili sono consentite solo nell'ordinamento in base a un'espressione che fa riferimento a un nome di colonna.The translation of the italian message is something like:
The SELECT element identified by ORDER BY 1 includes a variable that identifies the position of a column.
The valid variables in the order by clause must refer to the name of a columnThe value of the parameter sort is_ the name of a column!
Any hint?My solution was to append the order clause to an "namedQuery" like this:
- declare the named query as usual, with annotation
- create a simple helper function like findNamedQuery to find the query string for a given class and queryName (using reflection)
- if you need to execute the query without sort order - use EntityManager.createNamedQuery (as usual)
- BUT: if you want to sort data: use EntityManager.createQuery with the string obtained from findNamedQuery and the sort clause
I guess the is a performance penalty, but.. .it works. -
JPA - Select with where clause
Hi
I have 2 classes:
-Class A
-Class B with a member which holds a reference to an object of Class A --> unidirectional one-to-one relation. The mapping is the following:
<one-to-one name="a">
target-entity="domain.A" fetch="LAZY"
optional="false">
<join-column name="ID" table="A" />
</one-to-one>
Now i want to find all objects of B which have a certain instance of A. I tried this, but it doesn't work:
<named-query name="findBsByA">
<query>select b from B b where b.a = ?1</query>
</named-query>
Any suggestions?
Thanks for help
Michaelname or ID might be reserved words in access. Either change the name of the column or put [] around them. Also, you ar looking for a record where fields name and name1 are equal. You probably don't have a name1 field.
String name1=nameTextfield.getText().trim();
String query="SELECT [ID] from Suppliers WHERE [name]='"+name1+"';"
Pay attention to the single and double quotes I have. -
Single column index vs composite index?
I am just wondering that what are the differences between the following?
create table test(
person_id number
name varchar2(50),
surname varchar2(50)
create index my_indx on test(name);
create index my_indx2 on test(surname);
OR
create index my_indx3 on test(name, surname);
OR
create index my_indx4 on test(surname, name);
What are the differences among these three indexes?
When I create name and surname columns in same index (composite index) in order to index scan should I use both of them in the where clause?
My last question is, Is the order important for composite indexes?
Thanks in advance.What are the differences among these three indexes?
You should be able to answer that yourself by just trying some examples or by answering these questions:
1. Will an index on NAME help you if you want to search on SURNAME?
2. Will an index on SURNAME help you if you want to search on NAME?
When I create name and surname columns in same index (composite index) in order to index scan should I use both of them in the where clause?
You have it backwards. You create indexes based on the predicates in the WHERE clause of your queries. How can you use 'both of them' in the where clause if the query you want to execute doesn't have both of them available.
My last question is, Is the order important for composite indexes?
Not if you specify both columns. What is the difference between 'AB' and 'BA'? Or between 'ABCDE' and 'EDCBA'? If you only have one value available (e.g. SURNAME) then refer to my question #1 abov: will an index on NAME help you?
See 'Choosing Composite Indexes' in the Performance Tuning Guide
http://docs.oracle.com/cd/B28359_01/server.111/b28274/data_acc.htm#i2773 -
How to Get the required List Item values by using Where Clause
I have two tables named "TAX_RULES","BILL"
1. " Tax_Rules" (Sub_Head_Code,Tax_ID,Tax_Percentage)
{ While "Sub_Head_Code" field is unique,
Tax_ID describes that there are two kinds of Tax_IDs based on Tax_percentage which is 6% for some Sub_Head_Codes and 3.5% for the remainng Sub_Head_Codes. I have given Tax_ID 1 for 6% and Tax_ID 2 for Sub_Head_codes having 3.5%. }
2. "BILL" (Bill_ID,Sub_Head_Code,Tax_ID,Bill_Amount)
{While "Bill_ID" describes unique Bill Identification Number,
Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table}
I have design form for both tables.
In BILL form i am trying to get values of Tax_ID from Tax_Rules table at run-time by using WHEN-NEW-FORM-INSTANCE.
For this whenever i select a Sub_Head_Code in Bill Form, all the Tax_IDs that i have recorded against each Sub_Head_Code which is either 1 or 2 against 6% and 3.5% respectively.
But I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code ahould come in the LIST ITEM.
I have used WHERE clause but that is useless.
Following is the Code that i have applied in the WHE-NEW-ITEM-INSTANCE Trigger at FORM LEVEL
<CODE>
DECLARE
rg_n1 VARCHAR2(40) :='TAX_ID';
rg_idn1 RecordGroup;
gc_idn1 GroupColumn;
errcode NUMBER;
BEGIN
CLEAR_LIST('BILL.TAX_ID');
rg_idn1 := Find_Group(rg_n1);
IF Id_Null(rg_idn1) then
rg_idn1 := Create_Group(rg_n1);
gc_idn1 := Add_Group_Column(rg_idn1,'EXPLAIN',CHAR_COLUMN,60);
gc_idn1 := Add_Group_Column(rg_idn1,'TAX_ID',CHAR_COLUMN,3);
END IF;
errcode := Populate_Group_With_Query(rg_idn1,'select TAX_ID,TAX_ID from TAX_RULES');
POPULATE_LIST('BILL.TAX_ID',RG_IDn1);
END;
</CODE>In the Tax Rules table, you state:
"Sub_Head_Code" field is unique
In the Bill table, you state:
Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table
If the Sub_Head_Code is unique, then it's acting as a primary key, so Sub_Head_Code and Tax_ID in the Bill table are not behaving like a composite foreign key. The Sub_Head_Code is a foreign key, and the Tax_ID is irrelevant as far as keys are concerned.
It is not clear what it is you want to do.
If you want to display the Tax_IDs from the Bill table when you select a Sub_Head_Code from the Tax_Rules table, then change your query to:
select TAX_ID, TAX_ID from BILL where Sub_Head_Code = :Tax_Rules.Sub_Head_Code
If you want to display the Tax_IDs from the Tax_Rules table when you select a Sub_Head_Code from the Bill table, then change your query to:
select TAX_ID, TAX_ID from TAX_RULES where Sub_Head_Code = :Bill.Sub_Head_Code
If this is not what you want, then clarify what it is you want to do. Don't say:
"I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code"
because it is not clear what tables you are referring to. -
Problem with performance of a query having order by, distinct clause
Hi,
I have a problem with queries having order by, distinct clause.
While its executing its taking lot of time. With DBMS_PROFILER identified the queries taking long time.
The table is having approximately 70 million rows.
Problem -1
select * from table_name order by col1;
select distinct col1,col2 from table_name;
Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.
Solution1:
Max parallel servers is 8.
select /* + parallel(table_name,8) */ * from table_name order by col1;
select /* + parallel(table_name,8) */ distinct col1, col2 from table_name ;
Solution-2:
select /* + first_rows */ * from table_name order by col1;
select /* + first_rows */ distinct col1, col2 from table_name ;
Problem-2
I am having a query with where condition on columns.
Select * from table_name where col1='value1' and col2!='value2';
Index created on col1 and col2.
As we no that not equal won't use index as it is a composite index it should use the lead column. but its not using the index.
Should i forcibly use index with hint or suggest me better solution.
Any help really appreciated.
Thanks in advanceunique wrote:
The table is having approximately 70 million rows.
select * from table_name order by col1;Do you really want 70,000,000 rows from your table without any restrictions ? And furthermore ordered output ? I honestly understand the slowness of that query.
Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.Who knows if you choosed the right solution. I would suggest to reconsider your query and the need of 70,000,000 returned rows.
Problem-2
I am having a query with where condition on columns.
Select * from table_name where col1='value1' and col2!='value2';Please, provide the explain plan, eventually the tkprof output could also help. And tables descirption AND indexes description.
And OS and Oracle version.
Nicolas. -
Null in Composite Primary Key and "Primary keys must not contain null"
Hello all.
I'm a newbie concerning to JPA/EJB3, but I was wondering if toplinks doesn't support composite primary keys with null in some field (something perfectly right in any RDBMS).
I used JDeveloper (I'm using Oracle 10g database and JDeveloper 10.1.3.2.) wizards to generate JPA classes and I checked out generated files (with annotations), so they should be right (by the way, other O-R mappings for my model are working right, but this one).
I'm getting the next error:
Exception Description: The primary key read from the row [DatabaseRecord(
TSUBGRUPOSLDI.CD_GRUP => 01
TSUBGRUPOSLDI.CD_SUBGRUP => null
TSUBGRUPOSLDI.CG_POBL => 058
TSUBGRUPOSLDI.CG_PROV => 28
TSUBGRUPOSLDI.DSCR => Sanidad)] during the execution of the query was detected to be null. Primary keys must not contain null.
Compound primary key is (CD_GRUP, CD_SUBGRUP). No foreign keys, no joins (only a NamedQuery: "select o from ..."). It's the simplest case!
I checked out that everything runs ok if there's no "null" value in CD_SUBGRUP.
After some research (this and other forums) I'm beginning to believe that it's not supported, but not sure.
Am I doing sth wrong? If not, what is the reason to not support this? Will it be supported in the future?
Thanks in advance.Null is a special value and in many databases is not comparable to another null value (hence the isNull operator) and may pose problems when used to uniquely identify an Entity. TopLink does not support null values within a composite PK. As the nullable column is most likely not designated as a PK within your database table (many databases do not allow this) I recommend updating the Entity PKs to match that of the database.
--Gordon -
Netweaver's ORM library and JPA implementation. How to use EclipseLink?
Hi,
I'm migrating from Glassfish to Netweaver and when I deploy my EAR on Netweaver I'm receiving the following exception. I have two questions. 1) TABLE_PER_CLASS is supported in EclipseLink but for some reason Netweaver isn't using it as the JPA implementation. Why? 2) What is the com.sap.engine.services.orpersistence.model.ormappingmodel package and how do I avoid using it because it seems to be reading my annotations when I just want it to ignore it and let EclipseLink handle things?
I'm using Netweaver Composition Environment 7.1 and found this little FAQ on the topic:
https://wiki.sdn.sap.com/wiki/display/Java/JavaEE5+FAQ#JavaEE5FAQ-1.190
It says:
Can I use another JPA implementation on top of Java EE 5 Edition?
By design this feature is supported, however it has not been tested in this release. For future releases it is planned to test the SAP NetWeaver AS Java with other available JPA providers.
Not even sure if it's applicable here since the FAQ entry isn't related to CE.
Description:
1. [ERROR CODE DPL.DS.5402] JLinEE reported following erros for JavaEE/calendar-ear application.
ERRORS:
Model Creator: Error during model creation occured: com.sap.engine.services.orpersistence.model.ormappingmodel.ORMException: Unsupported inheritance strategy TABLE_PER_CLASS
at com.sap.engine.services.orpersistence.model.ormappingmodel.impl.ORMUtils.getInheritanceStrategy(ORMUtils.java:1252)
at com.sap.engine.services.orpersistence.model.ormappingmodel.impl.ORMappingModelCreatorImpl.parsePersistentClass(ORMappingModelCreatorImpl.java:831)
Thanks, any help is appreciated.
Edited by: Zarar Siddiqi on Jul 24, 2009 5:32 PMI should add that I've gone through the steps outlined in this article:
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60642a88-95fe-2b10-d387-a245d48fc257
I've properly configured a Heavy Resource and tested it through telnet so I know its installed properly. However, I still get the same exception. In my persistence.xml I've specified EclipseLink as the persistence provider:
<persistence-unit name="mainDatabase">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/Main</jta-data-source>
I'm wondering what I'm missing because Netweaver is still using SAP JPA and not EclipseLink.
Thanks. -
Master Detail Forms with 2 composite primary keys - Is there a workaround?
Hello All,
I have been searching for a workaround to the maximum 2 part primary key restriction on the multi-row updates, and master-detail forms, and am hoping that someone can help me. I am using HTMLDB v2.0.0.00.49 with IE 6 against a 9.2 DB.
I successfully implemented the workaround of Fred Stoopendaal's (see Updata PK on HTML DB ) and it works fine for single page multi-record updateable forms, but alas I haven't been able to extend it to master detail forms (I think it is something to do with Oracle not allowing the "returning" clause on views).
Here is what I tried:
two tables, one with a 2 part composite primary key, which is the master table, and a detail table with 3 part composite primary key -
--------- BEGIN SQL ---------
create table master_table
( master_col1 number
, master_col2 number
, master_col3 varchar2(30)
, constraint master_pk primary key (master_col1,master_col2));
create table detail_table
(detail_col1 number
,detail_col2 number
,detail_col3 number
,detail_col4 varchar2(30)
, constraint detail_pk primary key(detail_col1,detail_col2,detail_col3)
, constraint master_detail_fk foreign key (detail_col1,detail_col2) references master_table(master_col1,master_col2));
create or replace view v_master_table as
select rowid mata_rowid,mata.*
from master_table mata;
create or replace view v_detail_table as
select rowid deta_rowid,
(select rowid from master_table mata where mata.master_col1 = deta.detail_col1 and mata.master_col2 = deta.detail_col2) deta_mata_rowid
, deta.*
from detail_table deta;
create or replace trigger mata_ins_upd_trg
instead of insert or update on v_master_table
referencing new as new old as old
for each row
begin
if inserting then
insert into master_table (master_col1, master_col2, master_col3)
values (:new.master_col1, :new.master_col2, :new.master_col3);
end if;
if updating then
update master_table
set master_col1 = :new.master_col1,
master_col2 = :new.master_col2,
master_col3 = :new.master_col3
where rowid = :old.mata_rowid;
end if;
end;
create or replace trigger deta_ins_upd_trg
instead of insert or update on v_detail_table
referencing new as new old as old
for each row
begin
if inserting then
insert into detail_table ( detail_col1, detail_col2, detail_col3, detail_col4)
values (:new.detail_col1, :new.detail_col2, :new.detail_col3, :new.detail_col4);
end if;
if updating then
update detail_table
set detail_col1 = :new.detail_col1,
detail_col2 = :new.detail_col2,
detail_col3 = :new.detail_col3,
detail_col4 = :new.detail_col4
where rowid = :old.deta_rowid;
end if;
end;
--------- END SQL ---------
Then I created a master-detail form in Apex on the two views, using the mata_rowid and deta_rowid as primary keys, and mata_rowid=deta_mata_rowid as the link. I realise that using a function to fetch the master rowid within the detail view query is costly, but it was my intention to modify the record fetch queries to use the real FK columns once things were up and running.
It seems to generate the pages ok, and I can insert/update master table records, but as soon as I modify records in the detail table things go a bit haywire. I can't find any documentation on how the inbuilt MRU/MRD logic works, so can't figure out the issue.
Can anyone out there tell me what the problem is with the logic above, or if they have come up with a neat solution to this annoying limitation. I know that many will say that I should modify the data model to use surrogate primary keys, but many of the uses for HTMLDB are new interfaces for old schemas, so a workaround that doesn't involve wholesale data model changes would be preferable.
Thanks in advance,
Mike CretanHi, this is likely not the most elegant way...but perhaps the simplest -- and I didn't have much time to play.
I used Wizard to create two separate Master Detail forms, each with a separate detail table. Thus I ended up with four pages:
Page "A" - "Selector" page for Master (Report), with Edit link driving to Detail-1
Page "B" - Editable Master/Detail-1 page (HTML / Report)
Page "C" - "Selector" page for Master (Report), with Edit link driving to Detail-2
Page "D" - Editable Master/Detail-2 page (HTML / Report)
Then I selected the primary key column TWICE on the Report on Page A. Modified the second instance of this column to navigate to Page D (passing primary key) exactly the way the original instance of this column navigates to Page B. Then I deleted Page C.
Since you can have only one Tabular Entry form per page, this seemed the best way to drive two separate detail tables from a common interface.
Maybe you are looking for
-
i have hp pavilion dv4 series.my dvd drive not worked properly.for that purpose only i went 7 times in your service centre but they won't take action till now .why u people do like this .i want explation and just change my dvd drive that's all.
-
Issue : Read a text file and print the same
Hi, My requirement is to read a text file and print it the same way. import java.io.BufferedReader; import java.io.FileReader; public class CatFile { public static void main(String[] args) throws Exception FileReader file = new FileReader("D:/Te
-
Alert About battery dumped using showfaults is not present in syslog
Hello, My problem is the following: when I am connected on sc and with showfaults command I can see the warning concerning the battery threshold, but this warning do not appear in syslog under /var/log/. And also when using prtdiag -v command nothing
-
Error while creating Multiple Items Shopping Cart with Asset Assignment
Hi All, I am creating Shopping Cart with multiple items for different Assets. Example: I have Two Assets (Asset A with the budget of $1000 and Asset B with the Budget of $1500) in the back end system. Asset A assigned to Order 102649996 (value - $100
-
Reverse Compatibility with WPA2 in iBooks?
Hello. I own a 1.07 GHz iBook that is about 27 months old, and I bought an AirPort Extreme card with it. I've read that the AirPort Utility version 4.2 adds WPA2 support to AirPort Extreme base stations, but does it do anything for the firmware of Ai