-->
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: Hibernate Newbie: better sql generation
PostPosted: Tue Dec 07, 2004 2:42 pm 
Newbie

Joined: Fri Nov 19, 2004 10:49 am
Posts: 1
Hi--Here's the info, the question is down past the generated SQL

Hibernate version: 2.16

Mapping documents (2 in total):

Mapping doc 1:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
name="etest.model.Test"
table="TEST"
>
<id
name="id"
type="long"
column="TEST_ID"
>
<generator class="sequence">
<param name="sequence">test_seq</param>
</generator>
</id>

<property
name="datePublished"
type="java.sql.Timestamp"
column="DATE_PUBLISHED"
not-null="true"
length="7"
></property>
<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="255"
></property>
<property
name="loaded"
type="java.lang.String"
column="LOADED"
not-null="true"
length="1"
></property>

<!-- associations -->
<!-- bi-directional many-to-one association to User -->
<many-to-one
name="Owner"
class="core.model.User"
not-null="true"
outer-join="true"
>
<column name="OWNER_ID" />
</many-to-one>

</class>
</hibernate-mapping>

Mapping doc 2:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
name="core.model.User"
table="mcd_portal.user_xmlapi_view_v1"
>
<cache usage="read-only"/>
<id
name="id"
type="long"
column="USER_ID"
unsaved-value="null"
>
<generator class="assigned" />
</id>

<property
name="firstName"
type="java.lang.String"
column="FIRST_NAME"
length="255"
></property>

<property
name="lastName"
type="java.lang.String"
column="LAST_NAME"
length="255"
></property>

</class>
</hibernate-mapping>


Name and version of the database you are using:
Oracle 9.2.0.5.0

The generated SQL (show_sql=true):
select this.TEST_ID as TEST_ID1_,
this.DATE_PUBLISHED as DATE_PUB2_1_,
this.NAME as NAME1_,
this.LOADED as LOADED1_,
this.OWNER_ID as OWNER_ID1_,
user1_.USER_ID as USER_ID0_,
user1_.FIRST_NAME as FIRST_NAME0_,
user1_.LAST_NAME as LAST_NAME0_
from TEST this
left outer join mcd_portal.user_xmlapi_view_v1 user1_
on this.OWNER_ID=user1_.USER_ID where 1=1

The above query never returns. It's really bad sql for what I need.
I am using a view from another schema to get the user ids. I know this is not standard, but should be doable.

I need sql like this:

select this.TEST_ID as TEST_ID1_,
this.DATE_PUBLISHED as DATE_PUB2_1_,
this.NAME as NAME1_,
this.LOADED as LOADED1_,
this.OWNER_ID as OWNER_ID1_,
user1_.USER_ID as USER_ID0_,
user1_.FIRST_NAME as FIRST_NAME0_,
user1_.LAST_NAME as LAST_NAME0_
from TEST this, mcd_portal.user_xmlapi_view_v1 user1_
WHERE this.OWNER_ID=1
and this.owner_id = user1_.user_id


What do I need to do to get this query, or something like it? Thanks for any help you provide!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 4:12 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
post your HQL or whatever you did to generate this. Chris


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.