-->
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.  [ 2 posts ] 
Author Message
 Post subject: Native sql in hibernate
PostPosted: Wed Sep 15, 2004 3:53 am 
Newbie

Joined: Wed Aug 11, 2004 5:15 am
Posts: 2
Hibernate version:
- Hibernate 2.1.2

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
************* initialize the sessionFactory *********** net.sf.hibernate.impl.SessionFactoryImpl@385f6c3a
Hibernate: select ttkwqworkq0_.QUE_ID as x0_0_, ttkwqworkq0_.QUE_DESC_X as x1_0_, ttkwqworkq0_.NODE_ID as x2_0_, ttkwqworkq0_.FID_CO_NM as x3_0_, ttkwqworkq0_.SYS_ADM_GRP_C as x4_0_, ttkwqworkq0_.USE_NODE_TRNF_RULE_I as x5_0_, ttkwqworkq0_.DEL_I as x6_0_, ttkwqworkq0_.MOD_DEST_I as x7_0_, ttkememail1_.EMAIL_ADDR as x8_0_, ttkememail1_.SEND_MAIL_IND as x9_0_ from T_TKWQ_WORK_QUE ttkwqworkq0_ left outer join T_TKEM_EMAIL_NOTICE ttkememail1_ on ttkwqworkq0_.QUE_ID=ttkememail1_.QUEUE_ID where (ttkwqworkq0_.QUE_ID=? )AND(ttkwqworkq0_.ORG_ID=? )
[ERROR] catalog - -com.fmr.xtrac.catalog:E_Persistence - Error occurred in persistence operation: No column name found for property [usr_Scty_Grp_Id] [select {trnsfscty}.USR_SCTY_GRP_ID as {trnsfscty.usr_Scty_Grp_Id}, {trnsfsctygrp}.USR_SCTY_GRP_ID as {trnsfsctygrp.usr_Scty_Grp_Id} {trnsfsctygrp}.usr_Scty_Grp_Desc as {trnsfsctygrp.usr_Scty_Grp_Desc} from T_TKTS_TRNF_SCTY {trnsfscty} right outer join T_TKSG_SCTY_GRP {trnsfsctygrp} on {trnsfscty.usr_Scty_Grp_Id}= {trnsfsctygrp.usr_Scty_Grp_Id} AND {trnsfscty}.QUE_ID= :que_id AND {trnsfscty}.ORG_ID= :org_id ]
com.fmr.xtrac.catalog.E_Persistence: com.fmr.xtrac.catalog:E_Persistence - Error occurred in persistence operation: No column name found for property [usr_Scty_Grp_Id] [select {trnsfscty}.USR_SCTY_GRP_ID as {trnsfscty.usr_Scty_Grp_Id}, {trnsfsctygrp}.USR_SCTY_GRP_ID as {trnsfsctygrp.usr_Scty_Grp_Id} {trnsfsctygrp}.usr_Scty_Grp_Desc as {trnsfsctygrp.usr_Scty_Grp_Desc} from T_TKTS_TRNF_SCTY {trnsfscty} right outer join T_TKSG_SCTY_GRP {trnsfsctygrp} on {trnsfscty.usr_Scty_Grp_Id}= {trnsfsctygrp.usr_Scty_Grp_Id} AND {trnsfscty}.QUE_ID= :que_id AND {trnsfscty}.ORG_ID= :org_id ]
at com.fmr.xtrac.catalog.E_Persistence.throwExc(E_Persistence.java:630)
at com.fmr.xtrac.dao.TTkwqWorkQueDAO.retrieve(TTkwqWorkQueDAO.java:336)
at com.fmr.xtrac.dao.TTkwqWorkQueDAO.main(TTkwqWorkQueDAO.java:55)
Exception in thread "main"

Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
select {trnsfscty}.USR_SCTY_GRP_ID as {trnsfscty.usr_Scty_Grp_Id}, {trnsfsctygrp}.USR_SCTY_GRP_ID as {trnsfsctygrp.usr_Scty_Grp_Id} {trnsfsctygrp}.usr_Scty_Grp_Desc as {trnsfsctygrp.usr_Scty_Grp_Desc} from T_TKTS_TRNF_SCTY {trnsfscty} right outer join T_TKSG_SCTY_GRP {trnsfsctygrp} on {trnsfscty.usr_Scty_Grp_Id}= {trnsfsctygrp.usr_Scty_Grp_Id} AND {trnsfscty}.QUE_ID= :que_id AND {trnsfscty}.ORG_ID= :org_id
Debug level Hibernate log excerpt:



I am trying to write a native sql in hibernate using createSQLQuery method of Session class and getting an error "No column name found for property [usr_Scty_Grp_Id]".

The code is follows

Query query =
session.createSQLQuery(
"select
{trnsfscty}.USR_SCTY_GRP_ID as {trnsfscty.usr_Scty_Grp_Id}, {trnsfsctygrp}.USR_SCTY_GRP_ID as {trnsfsctygrp.usr_Scty_Grp_Id} {trnsfsctygrp}.usr_Scty_Grp_Desc as {trnsfsctygrp.usr_Scty_Grp_Desc} "
from T_TKTS_TRNF_SCTY {trnsfscty} right outer join
T_TKSG_SCTY_GRP {trnsfsctygrp}
on {trnsfscty.usr_Scty_Grp_Id}= {trnsfsctygrp.usr_Scty_Grp_Id}
AND {trnsfscty}.QUE_ID= :que_id
AND {trnsfscty}.ORG_ID= :org_id ",
new String[] {"trnsfscty","trnsfsctygrp"},
new Class[] {com.fmr.xtrac.hibernate.TTktsTrnfScty.class,
com.fmr.xtrac.hibernate.TTksgSctyGrp.class});

query.setString("que_id","");
query.setBigDecimal("org_id",new BigDecimal(95));


My table definition is as follows:
SQL> desc T_TKTS_TRNF_SCTY
Name Null? Type
----------------------------------------- -------- ----------------------------
QUE_ID NOT NULL VARCHAR2(7)
USR_SCTY_GRP_ID NOT NULL VARCHAR2(10)
SYS_ADM_GRP_C NOT NULL VARCHAR2(4)
CRE_OPER_ID NOT NULL VARCHAR2(7)
CRE_D NOT NULL DATE
MOD_OPER_ID NOT NULL VARCHAR2(7)
MOD_D NOT NULL DATE
DEL_I NOT NULL CHAR(1)
ORG_ID NOT NULL NUMBER

SQL> desc T_TKSG_SCTY_GRP
Name Null? Type
----------------------------------------- -------- ----------------------------
USR_SCTY_GRP_ID NOT NULL VARCHAR2(10)
USR_SCTY_GRP_DESC NOT NULL VARCHAR2(30)
SYS_ADM_GRP_C NOT NULL VARCHAR2(4)
MAX_PSWD_AGE_N NOT NULL NUMBER(5)
CRE_OPER_ID NOT NULL VARCHAR2(7)
CRE_D NOT NULL DATE
MOD_OPER_ID NOT NULL VARCHAR2(7)
MOD_D NOT NULL DATE
DEL_I NOT NULL CHAR(1)
ORG_ID NOT NULL NUMBER


The
class TTktsTrnfScty do have attribute usr_Scty_Grp_Id
and class TTksgSctyGrp do have attributes usr_Scty_Grp_Id ,usr_Scty_Grp_Desc.

Can you suggest what is the error in the sql?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 4:30 am 
Newbie

Joined: Wed Aug 11, 2004 5:15 am
Posts: 2
I found out one mistake. basically my mapping document had composite-key as the primary key and i have to select one of the columns of the composite key.

e.g the mapping document looks like this
<class name="com.fmr.xtrac.hibernate.TTktsTrnfScty"
table="T_TKTS_TRNF_SCTY" dynamic-
update="true">
<composite-id name="tTktsTrnSctyPk" c
class="com.fmr.xtrac.hibernate.TTktsTrnSctyPk">
<key-property name="usr_Scty_Grp_Id"
column="USR_SCTY_GRP_ID" type="java.lang.String"
length="10"/>
<key-property name="queId" column="QUE_ID"
type="java.lang.String" length="10"/>
</composite-id>
</class>

and I have to select USR_SCTY_GRP_ID which is part of the composite id.

Now the question is how to select one column which is part of composite id.

If i use the below sql:
select {trnsfscty}.USR_SCTY_GRP_ID as
{trnsfscty.tTktsTrnSctyPk.usr_Scty_Grp_Id},
{trnsfsctygrp}.USR_SCTY_GRP_ID as
{trnsfsctygrp.usr_Scty_Grp_Id} {trnsfsctygrp}.usr_Scty_Grp_Desc
as {trnsfsctygrp.usr_Scty_Grp_Desc} from T_TKTS_TRNF_SCTY
{trnsfscty} right outer join T_TKSG_SCTY_GRP {trnsfsctygrp} on
{trnsfscty.usr_Scty_Grp_Id}= {trnsfsctygrp.usr_Scty_Grp_Id} AND
{trnsfscty}.QUE_ID= :que_id AND {trnsfscty}.ORG_ID= :org_id

the i get an error "Error occurred in persistence operation: Alias [trnsfscty.tTktsTrnSctyPk] does not correspond to any of the supplied return aliases = {[trnsfscty,trnsfsctygrp]}"

How do i write this sql??


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.