-->
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.  [ 14 posts ] 
Author Message
 Post subject: problem of mapping with composite id
PostPosted: Mon Nov 17, 2003 11:22 am 
Newbie

Joined: Fri Oct 31, 2003 6:27 am
Posts: 6
hello,

i have two table :

Table1 : ptl_point_livraison

column a pk, fk
column b pk
column c fk
column d
column e


Table2
column a pk
column c pk
column g


********mapping table1 : Classe PointLivraison

<!-- Cle primaire -->
<composite-id name="ptlPK" class="PointLivraisonPK">
<key-property column="a" name="replique" />
<key-property column="b" name="codePtl" />
</composite-id>
<!-- Champs simples -->
<property column="c" name="codeScl" />
<property column="d" name="codeExpSrc" />
<property column="e" name="codePtlLingerie" />

<many-to-one name="serviceClient" class="ServiceClient" insert="false" update="false">
<column name="a"/>
<column name="c"/>
</many-to-one>

*******mapping table2 : Classe ServiceClient

<composite-id name="sclPK" class="ServiceClientPK">
<key-property name="replique" column="a" />
<key-property name="codeScl" column="c" />
</composite-id>
<property name="liblScl" column="g" />



when i load table1 : i have duplicate column 'a' in sql query :

select pointliv0_.a as a, pointliv0_.b as b, pointliv0_.c as c, pointliv0_.d as d , pointliv0_.e as e, pointliv0_.a as a from ptl_point_livraison pointliv0_ where (......

and is not supported by sybase


how to modify my code for avoid this.

thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 11:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What version of Hibernate is this? This should not happen in the latest release.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 11:38 am 
Newbie

Joined: Fri Oct 31, 2003 6:27 am
Posts: 6
it's hibernate 2.0.3


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 11:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
try 1.2b6, tell me what happens


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 11:47 am 
Newbie

Joined: Fri Oct 31, 2003 6:27 am
Posts: 6
with 2.1b6, it's just the same error.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 11:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK. I notice that the duplication is only occuring for the column that is duplicated b/w the id mapping and the property mapping, not for the other duplication. Add a test main() method to JIRA and I will try to find time to fix it.

Bloody Sybase. No other database on earth has a problem with this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 4:16 am 
Newbie

Joined: Fri Oct 31, 2003 6:27 am
Posts: 6
JIRA key : HB-477


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 6:30 am 
Newbie

Joined: Fri Oct 31, 2003 6:27 am
Posts: 6
test main add in jira


Top
 Profile  
 
 Post subject: Proposed fix
PostPosted: Thu Dec 11, 2003 7:46 am 
Newbie

Joined: Thu Dec 11, 2003 7:38 am
Posts: 2
Gavin, what do you think of this proposed fix :

currently, all SelectFragment are only used inside methods and not propagated. I propose to make Loadable.identifierSelectFragment and Loadable.propertySelectFragment return a SelectFragment instead of a String (and it would match better the name), add a method append(SelectFragment) to SelectFragment. This way, inside a SelectFragment, we could check for a duplication, or delay this check inside QuerySelect, with a new method public void addSelectFragmentString(SelectFragment fragment), in order to keep the distinct columns as long as needed. Since the problem is encountered only with relations on partial composite keys, this should be sufficient.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 8:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yeah I have toyed with this idea. Theres another reason why we need something like that. But it breaks everyone's custom persisters! I dunno, I'm not so keen on that.

Its something that I know needs to be addressed at some stage, but I don't know the right answer yet.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 10:24 am 
Newbie

Joined: Thu Dec 11, 2003 7:38 am
Posts: 2
Well of course, compatibility should not be broken... There is an heavier solution, to parse the sql fragments in QuerySelect.addSelectFragmentString(String). There we should take care mainly of formulas... and perhaps add a boolean in the Dialect to indicate that we don't want duplicate columns...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 8:05 am 
Newbie

Joined: Fri Feb 27, 2004 7:55 am
Posts: 17
Hi all,

I have the same problem using MS-Access. Has a solution evolved in the meantime?

Thanks for your attention,

--Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 7:10 am 
Newbie

Joined: Thu Feb 26, 2004 11:13 am
Posts: 3
Hi,

I have similar problem using Oracle 9i.
Normally, Oracle tolerates duplicate columns, however
when I set limit (setFirstResult, setMaxResults) then I get
the following error:

"ora-00918 column ambiguously defined"

The reason is that Oracle does not tolerate duplicate columns
in the statements:

SELECT * FROM (SELECT ... ) where rownum < ?

So, is anything new regarding this issue ?

Thanks,
Stm


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 3:08 pm 
Newbie

Joined: Wed Sep 03, 2003 6:08 pm
Posts: 5
I'm porting from Hibernate 2.0.2 to 2.1.2 and running into the same (or similar) issue with a mapping file that worked fine in the older version. Oracle 9i. My mapping looks like this:

Code:
    <class name="AccountBO" table="ACCOUNT">
      <!-- Fails whether or not the id is mapped to a property -->
      <id column="ACCOUNT_ID" type="long">
        <generator class="sequence">
          <param name="sequence">seq_account_id</param>
        </generator>
      </id>

      <component name="account" class="Account">
        <!- - NOTE double mapping of this columns. - ->
        <property name="accountID" column="ACCOUNT_ID"/>
        <!-- ... -->
      </component>

      <!-- ... -->
    </class>


Yes I know its an ugly model but its a mapping to a legacy database I can't change.

On HBN 2.0.2 I had insert="false" update="false" on the component, but 2.1.2 complains about that so I had to remove it.

The generated SQL has a double use of ACCOUNT_ID:
Code:
select accountbo0_.ACCOUNT_ID as ACCOUNT_ID, accountbo0_.ACCOUNT_ID as ACCOUNT_ID,
accountbo0_.BILLER_COMPANY_ID as BILLER_C2_,
accountbo0_.PAYER_COMPANY_ID as PAYER_CO3_,
accountbo0_.VENDOR_ID as VENDOR_ID
from ACCOUNT accountbo0_ where (accountbo0_.BILLER_COMPANY_ID is not null )and(accountbo0_.PAYER_COMPANY_ID is not null )and(accountbo0_.VENDOR_ID is not null )


Again, this mapping worked just fine in 2.0 but is now broken in 2.1. Anybody have workaround?


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