java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist - oracle

In this method I am getting error java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist I have gone through posts and I m not getting any Idea to fix it
public void saveOrUpdateProcessRun(ProcessRun argProcessRun) {
LOGGER.info(METHOD_START);
getHibernateTemplate().saveOrUpdate(argProcessRun);
LOGGER.info(METHOD_END);
}
This is Mapping I have XML Based Configurations Generator class is not Working(PROC_RUN_ID_SEQ)
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.uhg.esbdb.common.beans">
<class name="ProcessRun" table="PROC_RUN">
<id name="processRunID" type="integer" column="PROC_RUN_ID">
<generator class="sequence">
<param name="sequence">PROC_RUN_ID_SEQ</param>
</generator>
</id>
<property name="processID" type="integer" column="PROC_ID" />
<property name="processRunStartDatetime" type="timestamp"
column="PROC_RUN_STRT_DTTM" />
<property name="processRunEndDatetime" type="timestamp"
column="PROC_RUN_END_DTTM" />
<property name="processRunStatusCode" type="integer" column="PROC_RUN_STS_CD" />
<property name="createdByID" type="string" column="CRE_BY_ID" />
<property name="createdDatetime" type="timestamp" column="CRE_DTTM" />
<property name="modifiedByID" type="string" column="MOD_BY_ID" />
<property name="modifiedDatetime" type="timestamp" column="MOD_DTTM" />
</class>
<class name="FileLoad" table="FL_LOAD">
<id name="fileLoadID" type="integer" column="FL_LOAD_ID">
<generator class="sequence">
<param name="sequence">FL_LOAD_ID_SEQ</param>
</generator>
</id>
<property name="dataFileName" type="string" column="DATA_FL_NM" />
<property name="dataFileSizeByteNumber" type="integer"
column="DATA_FL_SZ_BYTE_NBR" />
<property name="fileLoadStatusCode" type="integer" column="FL_LOAD_STS_CD" />
<property name="loadStartDatetime" type="timestamp" column="LOAD_STRT_DTM" />
<property name="loadEndDatetime" type="timestamp" column="LOAD_END_DTM" />
<property name="createdByID" type="string" column="CRE_BY_ID" />
<property name="createdDatetime" type="timestamp" column="CRE_DTTM" />
<property name="modifiedByID" type="string" column="MOD_BY_ID" />
<property name="modifiedDatetime" type="timestamp" column="MOD_DTTM" />
<many-to-one name="processRun" class="ProcessRun" column="PROC_RUN_ID" />
</class>
<class name="ControlTotal" table="CTL_TOT">
<composite-id name="id" class="ControlTotalID">
<key-many-to-one name="fileLoad" class="FileLoad"
column="FL_LOAD_ID" />
<key-property name="controlTotalTypeCode" type="integer"
column="CTL_TOT_TYP_CD" />
</composite-id>
<property name="controlTotal" type="string" column="CTL_TOT" />
<property name="createdByID" type="string" column="CRE_BY_ID" />
<property name="createdDatetime" type="timestamp" column="CRE_DTTM" />
<property name="modifiedByID" type="string" column="MOD_BY_ID" />
<property name="modifiedDatetime" type="timestamp" column="MOD_DTTM" />
</class>
<!-- Added for loading wfg transaction ids from BE017 and BNKACH feeds to the EDB table EDBREF.WFG_ACH_PAYMENTS-->
<class name="WfgTransactionIdBean" table="EDBREF.WFG_ACH_PAYMENTS">
<id name="traceNumber" type="string" column="TRACE_NUMBER"></id>
<property name="sourceSystem" type="string" column="SOURCE_SYSTEM" />
<property name="transactionDate" type="timestamp" column="TRANSACTION_DATE" />
<property name="processed" type="string" column="PROCESSED" />
</class>
</hibernate-mapping>
Instead of PROC_RUN_ID_SEQ I am getting-> DEBUG main SQL logStatement:92 - select hibernate_sequence.nextval from dual

The causes can be different:
The name of the sequence you have mapped in your pojo is different
You have no permission to use sequence
You have no defined a sequence on your database
Solutions
Fix the sequence name on your pojo
Grant the sequence for your database user
Add the sequence on your database
EDIT AFTER UPDATED QUESTION
Try as follow:
<id name="propName" type="long" unsaved-value="null">
<column name="columnName" not-null="true" unique="true"
index="pkName" />
<generator
class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="optimizer">none</param>
<param name="increment_size">1</param>
<param name="sequence_name">PROC_RUN_ID_SEQ</param>
</generator>
</id>

Related

servicemix, oracle datasource, connection pooling, max connections

I'm trying to configure connection pooling in servcemix 4.4.1. I've created a oracle datasource object and set the properties like user, password,url. I deployed the following xml as osgi service in my smx.
Here's my datasource configuration:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="jdbc:oracle:thin:#connection:url"/>
<property name="user" value="****"/>
<property name="password" value="*****"/>
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="oracleds"/>
</service-properties>
</service>
</blueprint>
The datasource object is created succesfully and I'm able to retrieve the object using jndi lookup in my bundle.
Now I want to apply connection pooling for which I need to declare "maximum connections". Please suggest me how can I declare max no. of connections in the above xml
Thanks in advance.
Here is an example of my blueprint.xml:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation=
"http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
default-activation="eager">
<cm:property-placeholder id="server.placeholder" persistent-id="test.datasource">
<cm:default-properties>
<cm:property name="driverClassName" value="oracle.jdbc.pool.OracleDataSource" />
<cm:property name="validationQuery" value="SELECT 1 FROM DUAL" />
<cm:property name="defaultReadOnly" value="false" />
<cm:property name="defaultAutoCommit" value="true" />
<cm:property name="maxActive" value="100" />
<cm:property name="whenExhaustedAction" value="2" />
<cm:property name="maxWait" value="-1" />
<cm:property name="maxIdle" value="8" />
<cm:property name="minIdle" value="1" />
<cm:property name="testOnBorrow" value="true" />
<cm:property name="testOnReturn" value="true" />
<cm:property name="timeBetweenEvictionRunsMillis" value="-1" />
<cm:property name="numTestsPerEvictionRun" value="3" />
<cm:property name="minEvictableIdleTimeMillis" value="1800000" />
<cm:property name="testWhileIdle" value="false" />
<cm:property name="softMinEvictableIdleTimeMillis" value="-1" />
<cm:property name="lifo" value="true" />
</cm:default-properties>
</cm:property-placeholder>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value= "${driverClassName}" />
<property name="url" value="jdbc:oracle:thin:#${db.host}:${db.port}:${db.instance}" />
<property name="username" value="${db.user}" />
<property name="password" value="${db.password}" />
<property name="maxIdle" value="1" />
</bean>
<bean id="connectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
<argument ref="dataSource" />
</bean>
<bean id="connectionPool" class="org.apache.commons.pool.impl.GenericObjectPool" >
<argument><null/></argument>
<argument value="${maxActive}" />
<argument value="${whenExhaustedAction}" />
<argument value="${maxWait}" />
<argument value="${maxIdle}" />
<argument value="${minIdle}" />
<argument value="${testOnBorrow}" />
<argument value="${testOnReturn}" />
<argument value="${timeBetweenEvictionRunsMillis}" />
<argument value="${numTestsPerEvictionRun}" />
<argument value="${minEvictableIdleTimeMillis}" />
<argument value="${testWhileIdle}" />
<argument value="${softMinEvictableIdleTimeMillis}" />
<argument value="${lifo}" />
</bean>
<bean id="pooledConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory" >
<argument ref="connectionFactory" />
<argument ref="connectionPool" />
<argument><null/></argument>
<argument value="${validationQuery}" />
<argument value="${defaultReadOnly}" />
<argument value="${defaultAutoCommit}" />
</bean>
<bean id="poolingDataSource" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="pooledConnectionFactory">
<argument ref="connectionPool" />
</bean>
<service interface="javax.sql.DataSource" ref="poolingDataSource"> <!--ref="oracleDataSource"-->
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/testdb"/>
<entry key="datasource.name" value="jdbc/testdb" />
</service-properties>
</service>
</blueprint>
This datasource work fine.
I think the attribute "maxActive" close to what you need.
You can choose between two ways:
use oracle.jdbc.pool.OracleConnectionPoolDataSource as datasource class
use commons-dbcp https://gist.github.com/splatch/2d631ec09f9be0730b1e (this is fork of somebody else gist)

Integrating JSF2 with Spring3 and Hibernate4 - applicationContext.xml error?

I'm trying to create a JSF2 application which uses Spring3 for the DI and hibernate to handle the persistence.
I'm stock on the following error and don't know how to proceed:
26/10/2012 1:57:04 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
at org.hibernate.cfg.Configuration.add(Configuration.java:478)
at org.hibernate.cfg.Configuration.add(Configuration.java:474)
at org.hibernate.cfg.Configuration.add(Configuration.java:647)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:685)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:272)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 36 more
Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
... 43 more
my applicationContext.xml is listed below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.myapp.techrro" />
<context:annotation-config />
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="view">
<bean class="com.myapp.util.ViewScope" />
</entry>
</map>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver">
</property>
<property name="url" value="jdbc:jtds:sqlserver://localhost:1433/myapp">
</property>
<property name="username" value="mydb"></property>
<property name="password" value="somepass"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.idle_test_period">300</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="c3p0.acquire_increment">1</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/myapp/techrro/hibernate/UserOrderHist.hbm.xml
</value>
<value>com/myapp/techrro/hibernate/UserAccessHist.hbm.xml
</value>
<value>com/myapp/techrro/hibernate/User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="userOrderHistDAO" class="com.myapp.techrro.hibernate.userOrderHistDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userAccessHistDAO" class="com.myapp.techrro.hibernate.userAccessHistDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userDAO" class="com.myapp.techrro.hibernate.userDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
Update:
below are my mapping files, they were generated by myEclipse:
User.hbm.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.myapp.techrro.hibernate.User" table="User" schema="dbo" catalog="mydb">
<id name="user_PK" type="java.lang.Long">
<column name="user_PK" />
<generator class="identity" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="20" not-null="true" unique="true" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="40" not-null="true" />
</property>
<property name="userRole" type="java.lang.String">
<column name="userRole" length="1" not-null="true" />
</property>
<property name="active" type="java.lang.String">
<column name="active" length="1" />
</property>
<property name="type" type="java.lang.String">
<column name="type" length="3" not-null="true" />
</property>
<property name="firstName" type="java.lang.String">
<column name="firstName" length="30" />
</property>
<property name="lastName" type="java.lang.String">
<column name="lastName" length="30" />
</property>
<set name="userOrderHistLog" inverse="true">
<key>
<column name="user_PK" />
</key>
<one-to-many class="com.myapp.techrro.hibernate.userOrderHist" />
</set>
<set name="userAccessHistLog" inverse="true">
<key>
<column name="user_PK" not-null="true" />
</key>
<one-to-many class="com.myapp.techrro.hibernate.userAccessHist" />
</set>
</class>
</hibernate-mapping>
UserOrderHist.hbm.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.myapp.techrro.hibernate.userOrderHist" table="userOrderHist" schema="dbo" catalog="mydb">
<id name="userOrderHis_PK" type="java.lang.Long">
<column name="userOrderHis_PK" />
<generator class="identity" />
</id>
<many-to-one name="user" class="com.myapp.techrro.hibernate.User" fetch="select">
<column name="user_PK" />
</many-to-one>
<property name="action" type="java.lang.String">
<column name="action" length="1" not-null="true" />
</property>
<property name="prod" type="java.lang.String">
<column name="username" length="20" not-null="true" />
</property>
<property name="type" type="java.lang.String">
<column name="userRole" length="1" />
</property>
<property name="Updated" type="java.lang.String">
<column name="deleteFG" length="1" />
</property>
</class>
</hibernate-mapping>
UserAccessHist.hbm.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.myapp.techrro.hibernate.userAccessHist" table="userAccessHist" schema="dbo" catalog="mydb">
<id name="userAccessHistPK" type="java.lang.Long">
<column name="userAccessHistPK" />
<generator class="identity" />
</id>
<many-to-one name="user_PK" class="com.myapp.techrro.hibernate.User" fetch="select">
<column name="adminUserPK" not-null="true" />
</many-to-one>
<property name="createdDate" type="java.sql.Timestamp">
<column name="createdDate" length="23" not-null="true" />
</property>
<property name="accessDetail" type="java.lang.String">
<column name="accessDetail" length="100" not-null="true" />
</property>
</class>
</hibernate-mapping>
Can someone please possible causes of such error? Thanks
Based on your stacktrace (org.hibernate.InvalidMappingException: Unable to read XML), the problem is most likely in one of your hibernate mapping XML files.
Update:
Now that you have posted your hibernate files, it appears that you have an extra space at the end of the DTDs. Removing the trailing spaces should fix the problem.

where to put applicationcontext.xml and .hbm files?

I'm learning spring hibernate zk stack, and doing my first crud following this tutorial
I put applicationContext.xml into webapp/WEB-INF, and .hbm.xml to resources/mappings
But I dont know why my hbm files keep showing can not find my pojos.
in github https://github.com/kossel/firstzk
I have this structure
applicationContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- set other Hibernate properties in hibernate.cfg.xml file -->
<property name="configLocation" value="classpath:/com/iknition/firstzk/hibernate/hibernate.cfg.xml" />
</bean>
hibernate.cfg.xml
<mapping resource="com/iknition/firstzk/hibernate/Company.hbm.xml" />
<mapping resource="com/iknition/firstzk/hibernate/Contact.hbm.xml" />
Company.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.iknition.firstzk.beans">
<class name="Contact" table="contact">
<id name="idcontact" column="idcontact" type="integer">
<generator class="increment" />
</id>
<property name="name" column="name" type="string" />
<property name="email" column="email" type="string" />
<many-to-one name="company" column="companyId" class="com.iknition.firstzk.beans.Company" outer-join="true" />
</class>
</hibernate-mapping>
Contact.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.iknition.firstzk.beans">
<class name="Contact" table="contact">
<id name="idcontact" column="idcontact" type="integer">
<generator class="increment" />
</id>
<property name="name" column="name" type="string" />
<property name="email" column="email" type="string" />
<many-to-one name="company" column="companyId" class="com.iknition.firstzk.beans.Company" outer-join="true" />
</class>
</hibernate-mapping>
UPDATE:
I have reference to contact.hbm.xml too, I missed to put it here.
by "why my hbm files keep showing can not find my pojos" I mean, when I try to build the application, I keep getting error of "Caused by: org.hibernate.MappingException: entity class not found: com.iknition.firstzk.beans.Contact" I have changed many times the location of those configuration files, and still getting same error.
Hmmm... never tried using an external hibernate.cfg.xml. But I think specifying that only loads the properties. You might still need to set the mapping in a separate property.
Here's what my config usually looks like:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<bean
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="propertiesArray">
<list>
<props>...</props>
</list>
</property>
</bean>
</property>
<property name="mappingLocations" value="classpath:com/iknition/firstzk/hibernate/*.hbm.xml"/>
</bean>
I think you have to specify mappingLocations one-by-one like:
<property name="mappingLocations">
<util:list>
<value>hibernate/Company.hbm.xml</value>
<value>hibernate/Contact.hbm.xml</value>
</util:list>
</property>

Hibernate select batch-size

Hello,
i have simple J2EE application that shows first 100 Employee records from db (Oracle DB) with Hibernate (version 3). All of the tables have about 10000 records. There are Country(id, name), City(id, name, country_id), Address(id, address, city_id), Company(id, name), Office(id, company_id, address_id), Employee(id, name, address_id), Position(id, name) and Employee_Position_Office(employee_id, position_id, office_id) in db. And i have some problems with batch-size. I need to do it in 4 sql-request (generated by Hibernate). Let's show you what i have:
In my class-mappings i set batch-size=100 and Hibernate creates 3 sql-request for Employee, OfficePosition and Address loading, look:
select * from ( select employee0_.ID as ID6_, employee0_.NAME as NAME6_, employee0_.ADDRESS as ADDRESS6_ from EMPLOYEE employee0_ ) where rownum <= ?
select officeposi0_.EMPLOYEE_ID as EMPLOYEE1_6_1_, officeposi0_.POSITION_ID as POSITION2_1_, officeposi0_.OFFICE_ID as OFFICE3_1_, position1_.ID as ID5_0_, position1_.NAME as NAME5_0_ from EMPLOYEE_POSITION_OFFICE officeposi0_ inner join POSITION position1_ on officeposi0_.POSITION_ID=position1_.ID where officeposi0_.EMPLOYEE_ID in (100x ?)
select address0_.ID as ID2_2_, address0_.ADDRESS as ADDRESS2_2_, address0_.CITY_ID as CITY3_2_2_, city1_.ID as ID1_0_, city1_.NAME as NAME1_0_, city1_.COUNTRY_ID as COUNTRY3_1_0_, country2_.ID as ID0_1_, country2_.NAME as NAME0_1_ from ADDRESS address0_ left outer join CITY city1_ on address0_.CITY_ID=city1_.ID left outer join COUNTRY country2_ on city1_.COUNTRY_ID=country2_.ID where address0_.ID in (100x ?)
And if i change batch-size to number more than 100 nothing changes - this is good.
But then (after these requests) Hibernate generates request(s) for Office loading, and i have some problems with it, let's show you:
My 100 first Employees work in 397 offices (randomly generated) and Hibernate should loads they with 1 request when batch-size is more than 397, when i set batch-size to 397 it works fine (in 1 sql-request),
select office0_.ID as ID4_4_, office0_.COMPANY_ID as COMPANY2_4_4_, office0_.ADDRESS_ID as ADDRESS3_4_4_, (SELECT COUNT(*) FROM EMPLOYEE_POSITION_OFFICE
E WHERE
E.OFFICE_ID=office0_.ID)
as formula0_4_, company1_.ID as ID3_0_, company1_.NAME as NAME3_0_, address2_.ID as ID2_1_, address2_.ADDRESS as ADDRESS2_1_, address2_.CITY_ID as CITY3_2_1_, city3_.ID as ID1_2_, city3_.NAME as NAME1_2_, city3_.COUNTRY_ID as COUNTRY3_1_2_, country4_.ID as ID0_3_, country4_.NAME as NAME0_3_ from OFFICE office0_ left outer join COMPANY company1_ on office0_.COMPANY_ID=company1_.ID left outer join ADDRESS address2_ on office0_.ADDRESS_ID=address2_.ID left outer join CITY city3_ on address2_.CITY_ID=city3_.ID left outer join COUNTRY country4_ on city3_.COUNTRY_ID=country4_.ID where office0_.ID in (397x ?)
but when i set any another number (less or more than 397) Hibernate generates several sql-requests with same "body" but others "tails".
For example, there are results when batch-size = 400.
...in (200x ?)
...in (100x ?)
...in (50x ?)
...in (25x ?)
...in (12x ?)
...in (10x ?)
Tell, please, what i do wrong and can it be fixed. Thx.
My mappings:
<class name="---.Address" table="ADDRESS"
batch-size="100">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<many-to-one name="city" class="---.City"
fetch="join">
<column name="CITY_ID" />
</many-to-one>
</class>
<class name="---.City" table="CITY">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<many-to-one name="country" class="---.Country"
fetch="join">
<column name="COUNTRY_ID" />
</many-to-one>
</class>
<class name="---.Company" table="COMPANY">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
</class>
<class name="---.Country" table="COUNTRY">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
</class>
<class name="---.Employee" table="EMPLOYEE"
batch-size="100">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<many-to-one name="address" class="---.Address"
fetch="join">
<column name="ADDRESS" unique="true" />
</many-to-one>
<map name="officePositions" table="EMPLOYEE_POSITION_OFFICE" lazy="false"
fetch="join" batch-size="100">
<key>
<column name="EMPLOYEE_ID"></column>
</key>
<map-key-many-to-many class="---.Office">
<column name="OFFICE_ID">
</column>
</map-key-many-to-many>
<many-to-many column="POSITION_ID"
class="---.Position" />
</map>
</class>
<class name="---.Office" table="OFFICE"
batch-size="400">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<many-to-one name="company" class=---.Company"
fetch="join">
<column name="COMPANY_ID" />
</many-to-one>
<many-to-one name="address" class="---.Address"
fetch="join">
<column name="ADDRESS_ID" />
</many-to-one>
<property name="collegues">
<formula>
SELECT COUNT(*) FROM EMPLOYEE_POSITION_OFFICE
E WHERE
E.OFFICE_ID=ID
</formula>
</property>
</class>
<class name="---.Position" table="POSITION">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
</class>
Hibernate cfg:
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:oracle:thin:#localhost:1521:xe</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">---</property>
<property name="connection.password">----</property>
<property name="connection.pool_size">10</property>
<property name="current_session_context_class">thread</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.use_sql_comments">false</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="---/Country.hbm.xml" />
<mapping resource="---/City.hbm.xml" />
<mapping resource="---/Address.hbm.xml" />
<mapping resource="---/Company.hbm.xml" />
<mapping resource="---/Office.hbm.xml" />
<mapping resource="---/Position.hbm.xml" />
<mapping resource="---/Employee.hbm.xml" />
</session-factory>

NHibernate sluggish performance in FindAll(criteria) query

I have a very simple mapping file (se below) and a simple class.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain"
namespace="Domain" default-access="field.camelcase-underscore"
default-lazy="true">
<class name="PricePropStateView" table="V_PRICE_PROP_STATES">
<id name="PriceId" column="PRICE_ID" type="long" />
<property name="DetailId" column="DETAILS_ID" type="long" />
<property name="Moe" column="MOE" type="string" />
<property name="PropId" column="PROP_ID" type="long" />
<property name="PoQteId" column="PO_QTE_ID" type="string" />
<property name="PoLineItemId" column="LINE_ITEM_ID" type="string" />
<property name="PropState" column="PROP_STATE" type="string" />
</class>
</hibernate-mapping>
The class represents a data set returned by a View in Oracle. The performance is very slow. When executed in Toad for Oracle, the result set is returned in less than a second. When using
DetachedCriteria criteria =
DetachedCriteria.For<PricePropStateView>()
.Add(Restrictions.Eq("PoQteId", aQuoteName));
return FindAll(criteria).ToList();
It is very slow...almost 29 seconds. Any ideas> Thanks

Resources