XPath - select value - xpath

Good Day
I would like to attain the VALUE of the national_id.
I am struggling as the value is in a separate element and not to sure how to select it ONLY.
I would like "1234567891011 (ZAF-ID)" to be returned.
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wd:Get_Workers_Response wd:version="v32.2" xmlns:wd="urn:com.workday/bsvc">
<wd:Response_Data>
<wd:Worker>
<wd:Worker_Data>
<wd:Integration_Field_Override_Data>
<wd:Field_Reference>
<wd:ID wd:type="WID">12345</wd:ID>
<wd:ID wd:type="Integration_Document_Field_Name" wd:parent_type="Integration_Document_Name" wd:parent_id="INT017 Field Override for Worker">passport_number</wd:ID>
</wd:Field_Reference>
</wd:Integration_Field_Override_Data>
<wd:Integration_Field_Override_Data>
<wd:Field_Reference>
<wd:ID wd:type="WID">67891</wd:ID>
<wd:ID wd:type="Integration_Document_Field_Name" wd:parent_type="Integration_Document_Name" wd:parent_id="INT017 Field Override for Worker">national_id</wd:ID>
</wd:Field_Reference>
<wd:Value>1234567891011 (ZAF-ID)</wd:Value>
</wd:Integration_Field_Override_Data>
<wd:Integration_Field_Override_Data>
<wd:Field_Reference>
<wd:ID wd:type="WID">111213</wd:ID>
<wd:ID wd:type="Integration_Document_Field_Name" wd:parent_type="Integration_Document_Name" wd:parent_id="INT017 Field Override for Worker">network_logon</wd:ID>
</wd:Field_Reference>
</wd:Integration_Field_Override_Data>
<wd:Integration_Field_Override_Data>
<wd:Field_Reference>
<wd:ID wd:type="WID">141516</wd:ID>
<wd:ID wd:type="Integration_Document_Field_Name" wd:parent_type="Integration_Document_Name" wd:parent_id="INT017 Field Override for Worker">role_size</wd:ID>
</wd:Field_Reference>
<wd:Value>M</wd:Value>
</wd:Integration_Field_Override_Data>
<wd:Integration_Field_Override_Data>
<wd:Field_Reference>
<wd:ID wd:type="WID">171819</wd:ID>
<wd:ID wd:type="Integration_Document_Field_Name" wd:parent_type="Integration_Document_Name" wd:parent_id="INT017 Field Override for Worker">ts_organization</wd:ID>
</wd:Field_Reference>
<wd:Value>Information Technology</wd:Value>
</wd:Integration_Field_Override_Data>
<wd:Integration_Field_Override_Data>
<wd:Field_Reference>
<wd:ID wd:type="WID">202122</wd:ID>
<wd:ID wd:type="Integration_Document_Field_Name" wd:parent_type="Integration_Document_Name" wd:parent_id="INT017 Field Override for Worker">mutual_branch_user</wd:ID>
</wd:Field_Reference>
<wd:Value>N</wd:Value>
</wd:Integration_Field_Override_Data>
</wd:Worker_Data>
</wd:Worker>
</wd:Response_Data>
</wd:Get_Workers_Response>
</env:Body>
</env:Envelope>
Any assistance would be highly appreciated.

this is working
//wd:ID[text()="national_id"]/ancestor::*/wd:Value/text()

To complete #Alexander Riedel's answer, two other options :
//wd:Value[preceding::wd:ID[1][.="national_id"]]/text()
//wd:ID[.="national_id"]/../following-sibling::wd:Value/text()

Related

Caching Hibernate Native Query - How can I set the max time to Live for a specifc query?

Hi I am using the EHCache to cache the SQL results from some Hibernate Native Queries in a JPA app. I am wondering how I can set for a specific query how long the results should should be cached? i.e. to 24h but for other queries not?
Hibernate Properties
hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=none
hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
EHCache Config XML
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
<persistence strategy="localTempSwap"/>
/>
</ehcache>
Java Method in a Spring Repository Class
#Repository
#Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AnalyticsRepositoryImpl implements AnalyticsRepository {
public Map<Long, Long> getAgeStatistic(boolean onlyPaid) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT (date_part('year',current_date) - date_part('year',a.date_value)) as age, COUNT(u.id) as count from answers a ");
sb.append("JOIN ...");
...
Query q = em.createNativeQuery(sb.toString());
// enable the cache for the native query
NativeQuery nativeQuery = q.unwrap(NativeQuery.class);
nativeQuery.addScalar("age", IntegerType.INSTANCE);
nativeQuery.addScalar("count", LongType.INSTANCE);
nativeQuery.setCacheable(true);
List<Object[]> result = q.getResultList();
// Place results in map
Map<Long, Long> map = convertResultSetToLongKeyMap(result);
return map;
}
I found the answer, the solution is for my problem to use "cache regions". so you can define a own region for your queries
e.g. set the "analytics" cache region
#Repository
#Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AnalyticsRepositoryImpl implements AnalyticsRepository {
public Map<Long, Long> getAgeStatistic(boolean onlyPaid) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT (date_part('year',current_date) - date_part('year',a.date_value)) as age, COUNT(u.id) as count from answers a ");
sb.append("JOIN ...");
...
Query q = em.createNativeQuery(sb.toString());
// enable the cache for the native query
NativeQuery nativeQuery = q.unwrap(NativeQuery.class);
nativeQuery.addScalar("age", IntegerType.INSTANCE);
nativeQuery.addScalar("count", LongType.INSTANCE);
nativeQuery.setCacheable(true);
nativeQuery.setCacheRegion("analytics");
List<Object[]> result = q.getResultList();
// Place results in map
Map<Long, Long> map = convertResultSetToLongKeyMap(result);
return map;
}
and in the ehcache configuration
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<cache name="analytics"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="6000"
timeToLiveSeconds="6000">
<persistence strategy="localTempSwap"/>
</cache>
</ehcache>

ClassNotFoundException: org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer when deploy war in WebLogic

When I deploy my Spring Boot project package as war WebLogic throws:
Caused By: java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:1025)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:986)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:83)
at weblogic.utils.classloaders.GenericClassLoader.doFindClass(GenericClassLoader.java:607)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:539)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:492)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:469)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:53)
at weblogic.servlet.internal.WebAppServletContext.initContainerInitializer(WebAppServletContext.java:1390)
at weblogic.servlet.internal.WebAppServletContext.initContainerInitializers(WebAppServletContext.java:1360)
at weblogic.servlet.internal.WebAppServletContext.initContainerInitializers(WebAppServletContext.java:1341)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1907)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3091)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1849)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:882)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:78)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:52)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:754)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:264)
at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:52)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:90)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:627)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:171)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:121)
at weblogic.deploy.internal.targetserver.operations.StartOperation.doCommit(StartOperation.java:151)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:347)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:901)
at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1456)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:456)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:181)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:217)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:14)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:69)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:666)
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)
WebLogic Server Version: 12.2.1.1.0
My Spring Boot source:
OneAppAPI.java
#SpringBootApplication
public class OneAppAPI extends SpringBootServletInitializer implements WebApplicationInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(OneAppAPI.class);
}
public static void main(String[] args) {
SpringApplication.run(OneAppAPI.class, args);
}
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:context-root>oneapp</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
dispatcherServlet-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
</beans>
My dependency scope for spring-boot-starter-tomcat is provided and xml files are placed in src/main/webapp/WEB-INF/
I've installed in other WebLogic but with different version (12.2.1.3.0) and it works.
Whats wrong?
I finally get the solution, as M. Deinum comments, the problem was the WebLogic packages, but in my case, I also have to add
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.*</wls:package-name>
<wls:package-name>com.google.common.*</wls:package-name>
</wls:prefer-application-packages>*

JPA No property findAll found for type Product

My repository:
#Repository
public interface ProductDao extends JpaRepository<Product,Long>,JpaSpecificationExecutor<Product> {
Page<Product> findAll(Specification<Product> specification,Pageable pageable);
}
My service:
...
#Autowired
public ProductServiceImpl(ProductRepository repository, ProductDao productDao, ProductImgService productImgService, ProductClassService productClassService, AuthUserService authUserService, DeviceService deviceService){
super(repository);
this.productDao = productDao;
this.productImgService = productImgService;
this.productClassService = productClassService;
this.authUserService = authUserService;
this.deviceService = deviceService;
}
final
ProductDao productDao;
...
I use it in the service like this:
midResult = productDao.findAll((root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>();
list.add(criteriaBuilder.equal(root.get("ouId").as(Long.class),product.getOuId()));
if(product.getPclassId()!=null)
list.add(criteriaBuilder.equal(root.get("pclassId").as(Long.class),product.getPclassId()));
if(product.getProductStatus()!=null)
list.add(criteriaBuilder.equal(root.get("productStatus").as(Integer.class),product.getProductStatus()));
if(product.getProductName()!=null)
list.add(criteriaBuilder.equal(root.get("productName").as(String.class),product.getProductName()));
if(product.getCreator()!=null)
list.add(criteriaBuilder.equal(root.get("creator").as(Integer.class),product.getCreator()));
list.add(criteriaBuilder.between(root.get("createTimeTmp").as(Long.class),Long.parseLong(finalStarttsp),Long.parseLong(finalEndtsp)));
Predicate[] p = new Predicate[list.size()];
criteriaQuery.where(criteriaBuilder.and(list.toArray(p)));
return criteriaQuery.getRestriction();
}, pageable);
The Product Class definition is good .
And when I run this code , error turned out to be :
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type Product!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:86) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.mybatis.repository.query.PartTreeMybatisQuery.<init>(PartTreeMybatisQuery.java:81) ~[spring-data-mybatis-1.0.17.RELEASE.jar:na]
at org.springframework.data.mybatis.repository.query.MybatisQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(MybatisQueryLookupStrategy.java:71) ~[spring-data-mybatis-1.0.17.RELEASE.jar:na]
at org.springframework.data.mybatis.repository.query.MybatisQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(MybatisQueryLookupStrategy.java:120) ~[spring-data-mybatis-1.0.17.RELEASE.jar:na]
at org.springframework.data.mybatis.repository.query.MybatisQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(MybatisQueryLookupStrategy.java:50) ~[spring-data-mybatis-1.0.17.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.mybatis.repository.support.MybatisRepositoryFactoryBean.afterPropertiesSet(MybatisRepositoryFactoryBean.java:64) ~[spring-data-mybatis-1.0.17.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
I'm using springboot and there's no config like #EnableJpaRepositories
But it don't seems to be necessary cause other repository is good .
You are using spring-data in incorrect way. When you write method findAll in repository, it will look for given attribute in entity.
For example, you have an entity User with attribute firstName. Then you can defined method like, findByFirstName.
In given example, spring-data looking for attribute all which is not available as a part of Product.
In this case, you need to write your own query using #Query annotation.
BTW, what you want to achieve?
It works like this for me:
#NonNull
Page<Product> findAll(#Nullable Specification<Product> specification, #NonNull Pageable pageable);

Oracle.ManagedDataAccess.EntityFramework - ORA-01918: user 'dbo' does not exist

I am trying to implemente code First Migrations with Oracle.ManagedDataAccess 6.121.1.0 provider, but with no success at all.
As I am receiving a ORA-code, I am assuming that the connection are been opened successfully. But the Migrations are failing because, maybe, the provider are behaving as a SQL Server, instead of Oracle. I think that beacause it is traying to use 'dbo' as default schema.
Here is my web.config settings:
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
<section name="Oracle.ManagedDataAccess.Client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
<entityFramework>
<contexts>
<context type="MyProject.Context.MainContext, MyProject.Context">
<databaseInitializer type="MyProject.Context.Config.ContextInitializer, MyProject.Context" />
</context>
</contexts>
<defaultConnectionFactory type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess" />
<providers>
<provider invariantName="Oracle.ManagedDataAccess.Client"
type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver"
invariant="Oracle.ManagedDataAccess.Client"
description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="MainContext"
providerName="Oracle.ManagedDataAccess.Client"
connectionString="Data Source=OracleServer:1521/BRSYSDS;User ID=USER;Password=PASSWORD;" />
</connectionStrings>
<!-- other settings -->
</configuration>
Here the Stacktrace:
[OracleException (0x77e): ORA-01918: user 'dbo' does not exist]
OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone) +652
OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean bFirstIterationDone) +39
OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, OracleException& exceptionForArrayBindDML, Boolean isFromEF) +7480
Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery() +678
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.b__0(DbCommand t, DbCommandInterceptionContext1 c) +10
System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) +72
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) +357
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery() +104
System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext) +152
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext) +82
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable1 migrationStatements, DbConnection connection) +626
System.Data.Entity.Migrations.<>c__DisplayClass30.<ExecuteStatements>b__2e() +19
System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation) +9
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable1 migrationStatements, DbTransaction existingTransaction) +194
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable1 migrationStatements) +7
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable1 operations, IEnumerable1 systemOperations, Boolean downgrading, Boolean auto) +825
System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading) +564
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId) +404
System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) +447
System.Data.Entity.Migrations.<>c__DisplayClassc.b__b() +13
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +422
System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +78
System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func3 createMigrator, ObjectContext objectContext) +89
System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +116
System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +218
System.Data.Entity.DropCreateDatabaseAlways1.InitializeDatabase(TContext context) +137
I had the same problem and it was resolved by Thiago Lunardi's response. Thank you. I didn't have enough reputation to vote up your response. To mention here, I succeeded after setting my schema name in UPPERCASE.
Put this in your Context file under your new dbContext class, like this:
public partial class MyAppContext : DbContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("UPPERCASE_SCHEMA_NAME");
...
I solve this just setting the default schema at modelBuilder
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("MyOracleSchema");
// ...
}
Setting default schema didn't work for me.
I found the solution by customizing migrations history table to set a different schema.
You can find a solution here: LINK.
User Dbo also comes in case of missing fully qualified name of the Table. Which may not map to the right Table in the database.
If you use Automatic Migrations (as I was), then note: modelBuilder.HasDefaultSchema whouldn't help until you switch to explicit migrations.
From Oracle Docs:
Code First Automatic Migrations is limited to working with the dbo schema only. Due to this limitation it is recommended to use code-based migrations, that is, add explicit migrations through the Add-Migration command
in Code First you can use the DataAnnotations for Table .
[Table("Emplpoyee",Schema="YOUR SCHEMA NAME"]
I had the same problem. I placed my schema name in OnModelCreating() method.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("MyOracleSchema");
// ...
}
But, setting schema name in UPPERCASE didn't work for me. I added below mentioned code in Confifuration.cs and it worked !!
Go to Migrations -> Configuration.cs
class Configuration : DbMigrationsConfiguration<CodeFirstOracleProject.Context>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
var historyContextFactory = GetHistoryContextFactory("Oracle.ManagedDataAccess.Client");
SetHistoryContextFactory("Oracle.ManagedDataAccess.Client",
(dbc, schema) => historyContextFactory.Invoke(dbc, "YourSchemaName"));
}
}
In my case writing schema name in Uppercase wasn't sufficient I had to use toUpper() function as such :
modelBuilder.HasDefaultSchema("YOURSCHEMA".ToUpper())
alongside adding
public Configuration()
{
AutomaticMigrationsEnabled = false;
var historyContextFactory = GetHistoryContextFactory("Oracle.ManagedDataAccess.Client");
SetHistoryContextFactory("Oracle.ManagedDataAccess.Client",
(dbc, schema) => historyContextFactory.Invoke(dbc, "YOURSCHEMA".ToUpper()));
}
removed the migrations and regenerating them fixed the issue.
As a beginner, the major issue I had with the answers here was, what does user 'dbo' has to do with schema name.
After researching, here is what I found.
In oracle, A Schema is a collection of database objects. A schema is owned by a database user and has the same name as the user.
The default schema for entity framework is however dbo, and you can override this as in the code listing below:
modelBuilder.HasDefaultSchema("YOURSCHEMA".ToUpper())
For oracle, "YOURSCHEMA" has to be the user_id for the database you are connected to.
Then you need to add the below to your configuration file
public Configuration()
{
AutomaticMigrationsEnabled = false;
var historyContextFactory = GetHistoryContextFactory("Oracle.ManagedDataAccess.Client");
SetHistoryContextFactory("Oracle.ManagedDataAccess.Client",
(dbc, schema) => historyContextFactory.Invoke(dbc, "YOURSCHEMA".ToUpper()));
}
Finally, delete the migration files generated and rerun Add-Migration again.
I hope this will help somebody.

SAXParseException cannot resolve SOAP-ENC:Array to a type definition component

I am trying to validate a SOAP response message against the WSDL and I'm following the sample given in this question. However, I get the exception below.
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'SOAP-ENC:Array' to a(n) 'type definition' component.
I've seen a question about a similar error but I'm not sure if this is the same issue. I also don't understand why SOAP-ENC:Array is considered non-standard in that question when it appears in the SOAP spec.
Here is my validation code. The exception is raised on the Schema schema = schemaFactory.newSchema(schemas) line.
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document wsdlDoc = db.newDocument();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source wsdlSource = new StreamSource(new File("d:\\temp\\demo.wsdl"));
transformer.transform(wsdlSource, new DOMResult(wsdlDoc));
NodeList schemaNodes = wsdlDoc.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema");
int nrSchemas = schemaNodes.getLength();
Source[] schemas = new Source[nrSchemas];
for (int i = 0; i < nrSchemas; ++i)
{
schemas[i] = new DOMSource(schemaNodes.item(i));
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemas);
Validator validator = schema.newValidator();
Source soapMessage = new StreamSource(new File("d:\\temp\\soapmessage.xml"));
Result result = new StreamResult(System.out);
validator.validate(soapMessage, result);
I've trimmed the WSDL and only left the relevant parts, or at least what I think is relevant. If more is needed, I'll update the question.
<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="run:demo"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="run:demo">
<types>
<xsd:schema targetNamespace="run:demo">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
<xsd:complexType name="itemsCT">
<xsd:all>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="Address" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="itemsArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType"
wsdl:arrayType="tns:itemsCT[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</types>
</definitions>
The immediate problem is that the schema validator being called is not loading any schema document for namespace http://schemas.xmlsoap.org/soap/encoding/ -- either because it's a generic validator and doesn't have any inbuilt knowledge of SOAP namespaces, or because it did not manage to retrieve the schema document from the server at schemas.xmlsoap.org.
If you have a local copy of the schemas for the http://schemas.xmlsoap.org/soap/encoding/ and http://schemas.xmlsoap.org/wsdl/ namespaces, you might try adding schema location information to the two xsd:import elements in your schema. If you don't have a local copy, then I hope you have better luck getting responses out of schemas.xmlsoap.org than I did just now.

Resources