-->
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.  [ 1 post ] 
Author Message
 Post subject: Native SQL to load a mapped class with COMPOSITE key??
PostPosted: Tue Mar 08, 2005 5:15 pm 
Newbie

Joined: Thu Feb 03, 2005 4:25 pm
Posts: 7
Hi, all. I'm SO close to getting this working! Argh! :-) I can't figure out how to use native SQL to populate a mapped class with a composite primary key. It keeps saying "Column CL1_0_ not found". I'm pretty sure it's looking to load up the PK. This is just about the last thing I need to get off the ground. Thanks!

Patrick

Hibernate version: 3.0 rc1

Mapping documents:
<composite-id
class="ASUClassImpl"
unsaved-value="undefined"
access="property">

<key-property name="year" type="string" column="CL_YR"/>
<key-property name="term" type="char" column="CL_TERM"/>
<key-property name="SLN" type="int" column="CL_SLN"/>
</composite-id>

<property name="additionalTitle" column="CL_ADDL_TITLE" update="false" insert="false"/>
<property name="year" type="string" column="CL_YR" insert="false" update="false"/>
<property name="term" type="char" column="CL_TERM" insert="false" update="false"/>
<property name="SLN" type="int" column="CL_SLN" insert="false" update="false"/>

Code between sessionFactory.openSession() and session.close():
String sql = "SELECT " +
"CLR.CL_YR as {ASUClass.year}, " +
"CLR.CL_TERM as {ASUClass.term}, " +
"CLR.CL_SLN as {ASUClass.SLN}, " +
"CLR.CL_ADDL_TITLE as {ASUClass.additionalTitle} " +
"FROM " +
"UIS001PD.\"CLASS-DET-REC\" CDR, " +
"UIS001PD.\"CLASS-REC\" CLR , " +
"UIS001PD.\"COURSE-REC\" CR, " +
"UIS001PD.\"ENRL-TERM-REC\" ETR, " +
"UIS001PD.\"ID-REC\" IR, " +
"UIS001PD.\"STUD-REC\" SR " +
"WHERE " +
"( \"STUD-DET-SET\" AND \"CLASS-DET-SET\" AND \"ENRL-TERM-SET\" " +
"AND \"CLASS-SET\" AND \"STUD-SET\" " +
"AND IR.ASU_ID = 411358284 ) ";

Session session = sessionFactory.openSession();
SQLQuery results = session.createSQLQuery(sql)
.addEntity("ASUClass", ASUClassImpl.class);

List stuff = results.list();
session.close();

Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
at edu.asu.sis.Test.sqltest(Test.java:94)
at edu.asu.sis.Test.main(Test.java:30)
Caused by: java.sql.SQLException: Column CL1_0_ not found

Name and version of the database you are using: IDMS!

The generated SQL (show_sql=true):
SELECT CLR.CL_YR as CL1_2_0_, CLR.CL_TERM as CL2_2_0_, CLR.CL_SLN as CL3_2_0_, CLR.CL_ADDL_TITLE as CL4_2_0_ FROM UIS001PD."CLASS-DET-REC" CDR, UIS001PD."CLASS-REC" CLR , UIS001PD."COURSE-REC" CR, UIS001PD."ENRL-TERM-REC" ETR, UIS001PD."ID-REC" IR, UIS001PD."STUD-REC" SR WHERE ( "STUD-DET-SET" AND "CLASS-DET-SET" AND "ENRL-TERM-SET" AND "CLASS-SET" AND "STUD-SET" AND IR.ASU_ID = 411358284 )


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

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.