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
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Juzar Roopawalla

Hi,
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.
http://www.cb-india.com
I have been going there for years...they have the best collection and also give a discount on ALL books.
Hi,
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(NamingContext.java:804)
at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)

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"/>
</list>

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?
Hi,
We changed to named parameters and it worked, so we changed from :
Query q = session.createQuery("from Project_BC where projectId=?")
.setLong( 0, projId );

to

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
.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
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 ]
hi,
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(Mappings.java:124)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2030)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2005)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder
.java:368)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
... 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" />
</id>
- <!-- 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" />
</list>
</class>
</hibernate-mapping>

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:

HibernateUtil.java:46 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>(SessionFactoryImpl.java:339)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at com.msdw.pbefficiency.servicestracker.naming.HibernateSessionObjectFactory.initSessionFactory(HibernateSessionObjectFactory.java:46)
at com.msdw.pbefficiency.servicestracker.naming.HibernateSessionObjectFactory.getObjectInstance(HibernateSessionObjectFactory.java:37)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:129)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:791)
at org.apache.naming.NamingContext.lookup(NamingContext.java:138)
at org.apache.naming.NamingContext.lookup(NamingContext.java:779)
at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
at com.msdw.pbefficiency.servicestracker.utils.HibernateUtil.<clinit>(HibernateUtil.java:46)
hibernate config file:

<?xml version='1.0'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">
java:/comp/env/jdbc/wg
</property>
<property name="dialect">
org.hibernate.dialect.SybaseDialect
</property>
<property name="current_session_context_class">
thread
</property>
<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" />
</session-factory>
</hibernate-configuration>

mapping file:

<?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>
<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" />
</return>
{ ? = call qryOpportunityByCompanyId (:itemId) }
</sql-query>
</hibernate-mapping>

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.
Hi,
I have the following structure:
<?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>
<class name="com.msdw.pbefficiency.servicestracker.Opportunity" table="OPPORTUNITY">
<id name="id" column="OPPID">
<generator class="identity"/>
</id>
<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" />
</set>
</class>
<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
</sql-query>
</hibernate-mapping>

Opprotunity.java 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.
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