Error with a hibernate query

Поиск
Список
Период
Сортировка
Искать

Error with a hibernate query

От:
Vernon <vwu725@yahoo.com>
Дата:

The Java code:

public class User {

	private Long id;
	private String username;
	private String password;

        //...
}

The DB table:

create table USERS (
	id 			SERIAL UNIQUE primary key,	
	username 	VARCHAR(80) NOT NULL,
	password	VARCHAR(80) NOT NULL,
        ...
);

The Hibernate query:

getHibernateTemplate().findByNamedParam("select u from
					  User as u where u.username=:username and
u.password=:password", new String[] { "username",
"password" }

From the stack, the following error seems to be on the
JDBC driver side. Any suggestions of solving this
problem? 


org.springframework.jdbc.BadSqlGrammarException: Bad
SQL grammar [] in task 'Hibernate operation'; nested
exception is java.sql.SQLException: ERROR: operator
does not exist: character varying = bytea
java.sql.SQLException: ERROR: operator does not exist:
character varying = bytea
	at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)
	at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)
	at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:238)
	at
org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
	at
net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
	at
net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
	at
net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
	at
net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
	at
net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
	at
net.sf.hibernate.loader.Loader.list(Loader.java:1024)
	at
net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
	at
net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1553)
	at
net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
	at 


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/

Re: Error with a hibernate query

От:
Dave Cramer <pg@fastcrypt.com>
Дата:
Do you have a hibernate mapping file ?

Dave

Vernon wrote:

>The Java code:
>
>public class User {
>
>	private Long id;
>	private String username;
>	private String password;
>
>        //...
>}
>
>The DB table:
>
>create table USERS (
>	id 			SERIAL UNIQUE primary key,	
>	username 	VARCHAR(80) NOT NULL,
>	password	VARCHAR(80) NOT NULL,
>        ...
>);
>
>The Hibernate query:
>
>getHibernateTemplate().findByNamedParam("select u from
>					  User as u where u.username=:username and
>u.password=:password", new String[] { "username",
>"password" }
>
>From the stack, the following error seems to be on the
>JDBC driver side. Any suggestions of solving this
>problem? 
>
>
>org.springframework.jdbc.BadSqlGrammarException: Bad
>SQL grammar [] in task 'Hibernate operation'; nested
>exception is java.sql.SQLException: ERROR: operator
>does not exist: character varying = bytea
>java.sql.SQLException: ERROR: operator does not exist:
>character varying = bytea
>	at
>org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)
>	at
>org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)
>	at
>org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)
>	at
>org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)
>	at
>org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)
>	at
>org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:238)
>	at
>org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
>	at
>net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
>	at
>net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
>	at
>net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
>	at
>net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
>	at
>net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
>	at
>net.sf.hibernate.loader.Loader.list(Loader.java:1024)
>	at
>net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
>	at
>net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1553)
>	at
>net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
>	at 
>
>
>		
>__________________________________ 
>Do you Yahoo!? 
>Yahoo! Small Business - Try our new resources site!
>http://smallbusiness.yahoo.com/resources/
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
>  
>

-- 
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561

ResultSet.relative(0) throws "Cannot move to index of 0" but should not as explain in the Javadoc.

От:
David Gagnon <dgagnon@siunik.com>
Дата:
Hi all,

  I just ran into what i think is a compliance problem.  I can't call ResultSet.relative(0) without getting in exception.  As stated in the javadoc it's should just do NOTHING.


Am I wrong?

Best regards
/David

rs.relative(skipResults);

if (index==0)
>    	    throw new SQLException("Cannot move to index of 0");


 /**
     * Moves the cursor a relative number of rows, either positive or 
negative.
     * Attempting to move beyond the first/last row in the
     * result set positions the cursor before/after the
     * the first/last row. Calling relative(0) is valid, 
but does
     * not change the cursor position.
     *
     * 

Note: Calling the method relative(1) * is identical to calling the method next() and * calling the method relative(-1) is identical * to calling the method previous(). * * @param rows an int specifying the number of rows to * move from the current row; a positive number moves the cursor * forward; a negative number moves the cursor backward * @return true if the cursor is on a row; * false otherwise * @exception SQLException if a database access error occurs, * there is no current row, or the result set type is * TYPE_FORWARD_ONLY * @since 1.2 */

Re: ResultSet.relative(0) throws "Cannot move to index of 0"

От:
Kris Jurka <books@ejurka.com>
Дата:


On Mon, 18 Apr 2005, David Gagnon wrote:

>   I just ran into what i think is a compliance problem.  I can't call
> ResultSet.relative(0) without getting in exception.  As stated in the
> javadoc it's should just do NOTHING.

This is a bug and is only present in the 7.4 tree.  I've fixed it there.  
I'll gather up a couple more 7.4 changes and put out a new 7.4 release in 
a couple of days.  For now I can offer you 
http://www.ejurka.com/pgsql/jars/dgagnon/pg74-dg-jdbc3.jar as I don't 
happen to have other compilers available.

Kris Jurka

Re: ResultSet.relative(0) throws "Cannot move to index of 0"

От:
David Gagnon <dgagnon@siunik.com>
Дата:
Thanks!

      I also try a rs.relative(-1) when I was positionned before the 
first row.  I was not eable to get my result after that.  I'm note sure 
about this one though.. And it's not easy to test it agains ... I you 
don't know about this one .. it's either a mistake I made myself or 
another bug.  If you want I cant test it when I have a chance...

Let me know!
Thanks again
/David


Kris Jurka wrote:

>On Mon, 18 Apr 2005, David Gagnon wrote:
>
>  
>
>>  I just ran into what i think is a compliance problem.  I can't call
>>ResultSet.relative(0) without getting in exception.  As stated in the
>>javadoc it's should just do NOTHING.
>>    
>>
>
>This is a bug and is only present in the 7.4 tree.  I've fixed it there.  
>I'll gather up a couple more 7.4 changes and put out a new 7.4 release in 
>a couple of days.  For now I can offer you 
>http://www.ejurka.com/pgsql/jars/dgagnon/pg74-dg-jdbc3.jar as I don't 
>happen to have other compilers available.
>
>Kris Jurka
>
>  
>

FAQ