[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-759) problem for mixxing setmaxresults and setlockmode

Jean CHARBONNEAU (JIRA) noreply at atlassian.com
Fri Sep 28 04:37:57 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-759?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28244 ] 

Jean CHARBONNEAU commented on HHH-759:
--------------------------------------

As Frederic Leitenberger said, it's possible to do a work around this bug, also in Criteria type of query this way :

		Criteria criteria = getSession().createCriteria(MyClass.class)
		.add(Restrictions.eq("myField", false))
		.setLockMode(LockMode.UPGRADE);

		// This won't work under hibernate : criteria.setMaxResults(1);

		// I've provided the Dialect, but any other mean of detecting it's Oracle would work
		if(hibernateDialect.contains("Oracle")) {
			criteria.add(Restrictions.sqlRestriction("rownum <= 1"));
		}

Adapt this code to other kind of Criteria as needed, this one is for returning a single result.
K

> problem for mixxing setmaxresults and setlockmode
> -------------------------------------------------
>
>                 Key: HHH-759
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-759
>             Project: Hibernate3
>          Issue Type: Bug
>    Affects Versions: 3.0.2
>         Environment: Client:windows2000 professional,jre1.4.2, oracle8client,eclipse3.1-RC3,hibernate-tools 3.0 alpha4a,JBossIDE1.5M1
> Server:Solaris 2.8, oracle 8.1.7
>            Reporter: johnhua
>            Priority: Minor
>
> there is a problem for mixxing setmaxresults and setlockmode.
> the problem is that "ORA-00904: invalid column name". 
> The error info is as the below:
> Hibernate: select * from ( select idmapp0_.RI as col_0_0_ from PCTMNGT.IDMAP_P idmapp0_ where idmapp0_.STATUS=? ) where rownum <= ? for update of idmapp0_.RI
> 14:21:54,076 DEBUG  AbstractBatcher:AbstractBatcher.java:365 - preparing statement
> 14:21:54,082 DEBUG  AbstractBatcher:AbstractBatcher.java:285 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
> 14:21:54,083 DEBUG  AbstractBatcher:AbstractBatcher.java:403 - closing statement
> 14:21:54,090  WARN  JDBCExceptionReporter:JDBCExceptionReporter.java:71 - SQL Error: 904, SQLState: 42000
> 14:21:54,091 ERROR  JDBCExceptionReporter:JDBCExceptionReporter.java:72 - ORA-00904: invalid column name
> The source code is as the below:
>     	//query an unused emid for new tone
>     	query = av_session.createQuery("select v_idmap from IdmapP as v_idmap where v_idmap.status=:v_status");
>     	query.setCharacter("v_status",EMID_STATUS.UNUSED.charValue());
>     	query.setMaxResults(1);
>     	query.setLockMode("v_idmap",LockMode.UPGRADE);
>     	it = query.iterate();
>     	if( !it.hasNext() )
>     	{
>     		tx.rollback();
>         	lv_err = "addRing::doAddRingFile: no unused EMID for new tone in idmap. toneid="+av_tone;
>         	throw new InterfaceErrException(lv_err,INTERFACE_RETCODE.SYSTEM_ERR);
>     	}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list