Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

Juzar Roopawalla

Ranch Hand
+ Follow
since Oct 30, 2001
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Juzar Roopawalla

We are using the CFU streaming api to upload multiple image files. Our form has input text fields as well as input file fields. Before uploading the files we need to validate our text fields. This requires us to iterate over the FileItemIterator twice, once while validating to get the text field values and the second time to acutally get the file field values and save to disk. Our problem is that while trying to iterate the second time, the iter.hasNext() returns false even though we are trying to get the new iterator.
Below is our code:

The onBind code works fine. The onSubmit does not. Why is the FileItemIterator not being able to iterate in onSubmit even though we are obtaining a new iterator instance for the request??
14 years ago

For any computer related books in mumbai, you can blindly go to the computer bookshop in south Mumbai. It is on D.N. Road.
I have been going there for years...they have the best collection and also give a discount on ALL books.
I had to enhance my project and add a new column to the database. I added this new column to the database, the hbm.xml, the pojo with set/get. When I restarted the server I am getting the following:
Could not read mappings from resource: BenchmarkCS.hbm.xml
at org.apache.naming.NamingContext.lookup(
at org.apache.naming.NamingContext.lookup(
at org.apache.naming.NamingContext.lookup(
at org.apache.naming.NamingContext.lookup(

As soon as I remove the added property from the xml, the app starts working fine again. There are no typos or silly mistakes in naming (have made sure). WHAT COULD THE PROBLEM BE??? Please treat this question as urgent.
Hi I have a one to many relationship defined in the following way:

<list name="timeEntryDetailsList" cascade="all-delete-orphan" lazy="false" >
<key column="timeEntryId" not-null="true"/>
<index column="idx"/>
<one-to-many class="com.msdw.pbefficiency.servicestracker.hibernate.pojo.TimeEntryDetails"/>

When I remove an object from my list using iterator.remove() and the call saveOrUpdate() the removed object still exists in the database. I thought all that was required was a cascade="all-delete-orphan" in the hbm, but this did not work. Any suggestions on why?
We changed to named parameters and it worked, so we changed from :
Query q = session.createQuery("from Project_BC where projectId=?")
.setLong( 0, projId );


Query q = session.createQuery("from Project_BC where projectId= rjId")
.setLong( "prjId", projId );

We have changed all parameterized queries the same way.
Thanks Mark for looking into it.
No. They are 0 based. I had tried changing it to 1, it gives me the following exception:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Positional parameter does not exist: 1 in query: from Project_BC where projectId =?

btw... the strange thing is that it works from a program where the sessionfactory is created from a config file using a fixed path, where as I am creating it using JNDI. Don't think this should be of any consequence to the way hibernate executes the queries...but this is the only difference between the two programs. one works and one throws the above exception.
I have a method call:

project = ( Project_BC ) session.createQuery("from Project_BC where projectId =?").setLong( 0, longValue ).uniqueResult();

which throws the following exception:

Encountered exception while executing runInsert: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.loader.Loader.doList(
at org.hibernate.loader.Loader.listIgnoreQueryCache(
at org.hibernate.loader.Loader.list(
at org.hibernate.loader.hql.QueryLoader.list(
at org.hibernate.hql.ast.QueryTranslatorImpl.list(
at org.hibernate.engine.query.HQLQueryPlan.performList(
at org.hibernate.impl.SessionImpl.list(
at org.hibernate.impl.QueryImpl.list(
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(
at com.msdw.pbefficiency.servicestracker.dao.BussConsDAO.getProjectByProjId(Unknown Source)

And the cause of the problem is :
Caused by: java.sql.SQLException: JZ0SA: Prepared Statement: Input parameter not set, index: 1.

Why is this the cause of the problem when there is a setLong method has been used?
Also what is runInsert - mentioned at the beginning of the exception??
I am
Trying to meet a deadline so please let me know if you happen to have any pointers.
[ October 22, 2007: Message edited by: Mark Spritzler ]
yes, thanks that was the problem. but due to the nature of the error i was concentrating more on the hbm.xml rather than looking into the cfg.xml.
thanks once again.
I have all my hbm.xml files in a jar which is inside a war. I get the following on initialization:

Caused by: org.hibernate.DuplicateMappingException: Duplicate collection role mapping com.msdw.pbefficiency.servicestracker.hibernate.pojo.TimeEntry.timeEntryDetailsList at org.hibernate.cfg.Mappings.addCollection(
at org.hibernate.cfg.HbmBinder.createClassProperties(
at org.hibernate.cfg.HbmBinder.createClassProperties(
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder
at org.hibernate.cfg.HbmBinder.bindRootClass(
at org.hibernate.cfg.HbmBinder.bindRoot(
at org.hibernate.cfg.Configuration.add(
at org.hibernate.cfg.Configuration.addInputStream(
at org.hibernate.cfg.Configuration.addResource(
... 62 more
Initial SessionFactory creation failed.javax.naming.NamingException: Could not read
mappings from resource: com/msdw/pbefficiency/servicestracker/TimeEntry.hbm.xml

TimeEntry.hbm.xml is:

<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping (View Source for full doctype...)>
- <hibernate-mapping default-cascade="none" default-access="property" default-lazy="true" auto-import="true">
- <class name="com.msdw.pbefficiency.servicestracker.hibernate.pojo.TimeEntry" table="TimeEntry" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">
- <id name="timeEntryId">
<generator class="native" />
- <!-- foreign key will be inserted by parent class - TimeSheet
<property name="timeSheetId" insert="false" update="false" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<property name="userMins" column="userMinutes" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<property name="clientId" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<property name="comments" unique="false" optimistic-lock="true" lazy="false" generated="never" />
- <list name="timeEntryDetailsList" cascade="all" lazy="false" inverse="false" mutable="true" optimistic-lock="true" embed-xml="true">
<key column="timeEntryId" not-null="true" on-delete="noaction" />
<index column="idx" />
<one-to-many class="com.msdw.pbefficiency.servicestracker.hibernate.pojo.TimeEntryDetails" not-found="exception" embed-xml="true" />

Unfortunately there is no help on this anywhere on the internet. Could any one throw some light on this issue ASAP. Thanks a lot in advance!
Hi Mark,
I have tried without the dots too. The error remains the same.
The proc is just a simple select :

select * from Opportunity where id = @cid

I guess returning a cursor is not a restriction that hibernate has for sybase.

One question though, my mapping file just has the sql-query and the class name is not mapped anythere to a <class> element. Is that a problem?

Thanks in advance.
I am using this on Sybase
Here is the exception stack trace: is :

sessionFactoryWG = (SessionFactory) c.lookup("hibernate/wg");

I just cannot understand wht the error is in the Named query.

Oct 9, 2007 10:41:50 AM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
org.hibernate.HibernateException: Errors in named queries: Opps.By.CompanyId
at org.hibernate.impl.SessionFactoryImpl.<init>(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at com.msdw.pbefficiency.servicestracker.naming.HibernateSessionObjectFactory.initSessionFactory(
at com.msdw.pbefficiency.servicestracker.naming.HibernateSessionObjectFactory.getObjectInstance(
at org.apache.naming.factory.ResourceFactory.getObjectInstance(
at javax.naming.spi.NamingManager.getObjectInstance(
at org.apache.naming.NamingContext.lookup(
at org.apache.naming.NamingContext.lookup(
at org.apache.naming.NamingContext.lookup(
at org.apache.naming.NamingContext.lookup(
at com.msdw.pbefficiency.servicestracker.utils.HibernateUtil.<clinit>(
hibernate config file:

<?xml version='1.0'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

<property name="connection.datasource">
<property name="dialect">
<property name="current_session_context_class">
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<mapping resource="com/msdw/pbefficiency/servicestracker/WGOpportunity.hbm.xml" />

mapping file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<sql-query name="Opps.By.CompanyId" callable="true">
<return alias="opp" class="com.msdw.pbefficiency.servicestracker.hibernate.pojo.Opportunity">
<return-property name="opportunityName" column="opportunityName" />
<return-property name="companyId" column="itemId" />
<return-property name="status" column="status" />
{ ? = call qryOpportunityByCompanyId (:itemId) }

The moment I try looking up the session factory (jndi), I get the following error:

Initial SessionFactory creation failed.javax.naming.NamingException: Errors in named queries: Opps.By.CompanyId

The proc contents is just a simple select statement. I have checked the return types, column names, class methods etc. Everything is in order.
I also tried to put the proc call like this:

1) { call qryOpportunityByCompanyId (:itemId) }
2) { call qryOpportunityByCompanyId (?) }
3) { ? = call qryOpportunityByCompanyId (?) }

Any help will be appreciated.
I have the following structure:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="com.msdw.pbefficiency.servicestracker.Opportunity" table="OPPORTUNITY">
<id name="id" column="OPPID">
<generator class="identity"/>
<property name="name" column="NAME" not-null="true"/>
<set name="projectList" cascade="save-update" lazy="false">
<key column="OPPID" not-null="true" />
<one-to-many class="com.msdw.pbefficiency.servicestracker.Project" />
<sql-query name="n1">
<return alias="opp" class="com.msdw.pbefficiency.servicestracker.Opportunity"/>
<return-join alias="proj" property="opp.projectList"/>
select * from OPPORTUNITY o, PROJECT p where o.OPPID = p.OPPID
</hibernate-mapping> has a property called projectList of type Set.

When I execute the query like this:

Query q = session.getNamedQuery( "n1" );
List<Opportunity> entries = q.list();

The List returned is of type 'Object' and not Opportunity.
Is there some kind of additional parameter in the mapping file that I have to set. I have read the docs and there is nothing additional that was required. Could someone please help me out?

thanks a lot for your reply. the issue is resolved. somehow i overlooked that attribute...something tells me there will be many more queries to come in the very near future