These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: custom collection loading - invalid column names?
PostPosted: Thu Apr 13, 2006 1:59 pm 
Newbie

Joined: Fri Jul 15, 2005 10:02 am
Posts: 12
I am using a custom sql query to load a collection into a HashSet. The error happens after the query is run and hibernate tries to load the data from the columns.

The column it is looking for is 'ID', if I override the column name 'PERMISSION_ID' to 'ID', it gets past this error and then I get another looking for column 'elt'.

Code:
<class name="Article" table="ARTICLES">
        <id name="id" column="ARTICLE_ID">
         <generator class="native"/>
        </id>
        <property name="guid" column="GUID" unique="true" />

        <set name="permissionSet">
             <key />
             <many-to-many class="Permission" />
                <loader query-ref="permissionSet" />
        </set>
    </class>

    <sql-query name="permissionSet">
        <load-collection alias="perms" role="Article.permissionSet" />
        SELECT perms.*
        FROM PERMISSIONS perms
        LEFT OUTER JOIN PERMISSION_X_GUID permsx ON perms.PERMISSION_ID = permsx.PERMISSION_ID
        LEFT OUTER JOIN ARTICLES arts ON permsx.GUID = arts.GUID
        WHERE arts.ARTICLE_ID = ?
    </sql-query>

<class name="Permission" table="PERMISSIONS">
        <id name="id" column="PERMISSION_ID">
         <generator class="native"/>
        </id>
        <property name="title" column="TITLE" />
        <property name="plevel" column="PLEVEL" />
       
    </class>


the error i get is

Code:
2006-04-13 13:15:46,774 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
2006-04-13 13:15:46,790 DEBUG [org.hibernate.type.LongType] binding '163971' to parameter: 1
2006-04-13 13:15:46,837 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
2006-04-13 13:15:46,837 DEBUG [org.hibernate.loader.Loader] result set contains (possibly empty) collection: [Article.permissionSet#163971]
2006-04-13 13:15:46,837 DEBUG [org.hibernate.engine.CollectionLoadContext] uninitialized collection: initializing
2006-04-13 13:15:46,837 DEBUG [org.hibernate.loader.Loader] processing result set
2006-04-13 13:15:46,837 DEBUG [org.hibernate.loader.Loader] result set row: 0
2006-04-13 13:15:46,837 DEBUG [org.hibernate.loader.Loader] result row:
2006-04-13 13:15:46,868 INFO  [org.hibernate.type.LongType] could not read column value from result set: id; Invalid column name
2006-04-13 13:15:46,868 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
2006-04-13 13:15:46,868 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-04-13 13:15:46,868 DEBUG [org.hibernate.jdbc.AbstractBatcher] closing statement
2006-04-13 13:15:46,868 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not execute query [SELECT perms.*
        FROM PERMISSIONS perms
        LEFT OUTER JOIN PERMISSION_X_GUID permsx ON perms.PERMISSION_ID = permsx.PERMISSION_ID
        LEFT OUTER JOIN ARTICLES arts ON permsx.GUID = arts.GUID
        WHERE arts.ARTICLE_ID = ?]
java.sql.SQLException: Invalid column name
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
   at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3295)
   at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914)
   at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1575)
   at org.jboss.resource.adapter.jdbc.WrappedResultSet.getLong(WrappedResultSet.java:338)
   at org.hibernate.type.LongType.get(LongType.java:28)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
   at org.hibernate.persister.collection.AbstractCollectionPersister.readKey(AbstractCollectionPersister.java:676)
   at org.hibernate.loader.Loader.readCollectionElement(Loader.java:962)
   at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
   at org.hibernate.loader.Loader.doQuery(Loader.java:689)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2145)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
   at org.hibernate.persister.collection.NamedQueryCollectionInitializer.initialize(NamedQueryCollectionInitializer.java:54)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)


I am using hibernate 3.1.3, JBoss 4.03, Oracle 9.2.0.4.

If anyone can give me a hand I would appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 15, 2006 12:50 am 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
From the Hibernate documentation, it looks like it should be:
<sql-query name="permissionSet">
<load-collection alias="perms" role="Article.permissionSet" />
SELECT {perms.*}
FROM PERMISSIONS perms
LEFT OUTER JOIN PERMISSION_X_GUID permsx ON perms.PERMISSION_ID = permsx.PERMISSION_ID
LEFT OUTER JOIN ARTICLES arts ON permsx.GUID = arts.GUID
WHERE arts.ARTICLE_ID = :id
</sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 9:58 am 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Hi,

Did it work??

Is it possible to write native SQL for many-to-many assosiations?

10x!
Michael.


Top
 Profile  
 
 Post subject: query
PostPosted: Thu May 22, 2008 3:13 pm 
Newbie

Joined: Thu May 22, 2008 2:16 pm
Posts: 9
please consider to write queries like that

Code:
SQLQuery sqlQry = openedSession.createSQLQuery(""
                   +"SELECT {c.*}"
                   +" FROM CUSTOMERS {c} WHERE {c}.username='" +getUsername()+ "'" + " AND {c}.password =" +getPassword()+"");



SELECT {c.*}


dev anut


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.