-->
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: many-to-one
PostPosted: Mon Jul 18, 2005 5:58 pm 
Newbie

Joined: Thu Feb 17, 2005 3:01 pm
Posts: 9
Hi ,

We get SQL Grammer exception when using many-to-one inside a sub-class with join table .

We also get the same error when using many-to-one inside a joined-subclass

Attached is the hbm file

<subclass name="com.fox.residuals.model.system.schedule.SalaryUnit"
discriminator-value="SALARYUNIT">
<join table="RESD_SALARY_UNIT" fetch="select">
<key column ="SALARY_UNIT_ID" />

<!-- Cast Contract Type -->
<many-to-one name="castContractType" fetch="join"
class="com.fox.residuals.model.contract.Contract">
<column name="CON_TYPE_CODE"></column>
</many-to-one>


The exception does not happen if the many to one is changed to a base property

<property
name = "castContractType"
type = "java.lang.String"
column="CON_TYPE_CODE"
length="200"
/>

We are having the same problem when using many-to-one inside a joined subclass


<joined-subclass name="com.fox.residuals.model.system.schedule.SalaryUnit" table="RESD_SALARY_UNIT" >
<key column ="SALARY_UNIT_ID" />

<!-- Cast Contract Type -->
<many-to-one
name="castContractType"
class="com.fox.residuals.model.system.lookup.ResidualsLookup"
not-null="true"
fetch="join">
<column name = "cast_con_type_code" />

</many-to-one>

We are using version = 3.05

Any help would be appreciated

Thanks
murparth


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 6:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Who would ever imagine that it could be helpful to actually post the stacktrace and message of the exception that is the subject of the post?


Top
 Profile  
 
 Post subject: many-to-one
PostPosted: Mon Jul 18, 2005 7:00 pm 
Newbie

Joined: Thu Feb 17, 2005 3:01 pm
Posts: 9
Sorry by bad,

On further investigation the problem gets resolved when the fetch is changed from fetch="select" to fetch="join" and the queries get generated as expected

Here is the Stack Trace
Code:
Hibernate: select schedule0_.SCHED_ID as SCHED1_, schedule0_.version as version11_, schedule0_.CREATION_DATE as CREATION3_11_, schedule0_.MODIFIED_DATE as MODIFIED4_11_, schedule0_.ACTIVE_FLAG as ACTIVE5_11_, schedule0_.SCHED_NAME as SCHED6_11_, schedule0_.DESCRIPTION as DESCRIPT7_11_, schedule0_.sched_type as sched8_11_ from RESD_SCHED schedule0_
Hibernate: select rules0_.SCHED_ID as SCHED7___, rules0_.RULE_ID as RULE1___, rules0_.RULE_ID as RULE1_2_, rules0_.version as version8_2_, rules0_.CREATION_DATE as CREATION4_8_2_, rules0_.MODIFIED_DATE as MODIFIED5_8_2_, rules0_.ACTIVE_FLAG as ACTIVE6_8_2_, rules0_.SCHED_ID as SCHED7_8_2_, rules0_1_.NO_OF_DAYS as NO2_9_2_, rules0_1_.UNITS as UNITS9_2_, rules0_.RULE_TYPE as RULE2_2_, residualsl1_.LOOKUP_CODE_ID as LOOKUP1_0_, residualsl1_.version as version21_0_, residualsl1_.LOOKUP_CODE as LOOKUP3_21_0_, residualsl1_.lookup_type as lookup4_21_0_, residualsl1_.sort_order as sort5_21_0_, residualsl1_.lookup_description as lookup6_21_0_, residualsl1_.active_flag as active7_21_0_, residualsl1_.creation_date as creation8_21_0_, residualsl1_.modified_date as modified9_21_0_, residualsl1_.DISPLAYED_VALUE as DISPLAYED10_21_0_, lookuptype2_.lookup_type as lookup1_1_, lookuptype2_.version as version20_1_, lookuptype2_.ACTIVE_FLAG as ACTIVE3_20_1_, lookuptype2_.creation_date as creation4_20_1_, lookuptype2_.modified_date as modified5_20_1_, lookuptype2_.LOOKUP_DESCRIPTION as LOOKUP6_20_1_, lookuptype2_.DISPLAY_NAME as DISPLAY7_20_1_ from RESD_RULE rules0_ left outer join RESD_TIME_UNIT rules0_1_ on rules0_.RULE_ID=rules0_1_.TIME_UNIT_ID left outer join RESD_LOOKUP_CODE residualsl1_ on rules0_2_.CAST_CON_TYPE_CODE=residualsl1_.LOOKUP_CODE_ID left outer join RESD_LOOKUP_TYPE lookuptype2_ on residualsl1_.lookup_type=lookuptype2_.lookup_type where rules0_.SCHED_ID=?
com.fox.residuals.exception.DataStoreException: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.fox.residuals.model.system.schedule.Schedule.rules#3023]
   at com.fox.residuals.dao.hibernate.ContractDAOHibernate.deleteSchedule(ContractDAOHibernate.java:1444)
   at com.fox.residuals.dao.hibernate.ContractDAOHibernateFUnit.testDeleteSchedule(ContractDAOHibernateFUnit.java:741)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)Residuals WARN [main] JDBCExceptionReporter.logExceptions(71) | SQL Error: 904, SQLState: 42000
Residuals ERROR [main] JDBCExceptionReporter.logExceptions(72) | ORA-00904: "RULES0_2_"."CAST_CON_TYPE_CODE": invalid identifier

Residuals DEBUG [main] ContractDAOHibernate.deleteSchedule(1441) | org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.fox.residuals.model.system.schedule.Schedule.rules#3023]

   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 7:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, two possibilities:

(1) Hibernate *really* is generating SQL with a table alias in the where clause that does not appear in the from clause
(2) This is just total BS

In case of (1), you should submit a *very simple*, *easily runnable* test case to JIRA that reproduces the failure.

In case of (2), you should expect to get yelled at extremely harshly for wasting our time.

Frankly, I think (2) is waaaay more likely, but it's impossible to tell given the total lack of detail in your post. Do not ever post here again without basic information like: are you running a query or calling load(), all the relevant mapping documents, full exception stack trace, etc.

Yes, I am very impatient with this kind of stuff.


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.