-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using same column as PK and FK with Sybase
PostPosted: Thu Jun 03, 2004 8:25 pm 
Newbie

Joined: Thu Jun 03, 2004 7:08 pm
Posts: 6
I'm having this issue and I can't figure out how to fix it. I hope this post helps.

NOTE: the same statement works fine with MySQL.

For the example i'm giving here i will show what i think is relevant for getting the picture of the problem, so if you find something is missing is probable that it was my decision just to keep the example clear.

Environment:
-Hibernate 2.1.4
-Sybase 12.5.1 Developer's Edition
-JConnector 2 (jar named jconn2.jar)

Context: I need to use one column as a PK and a FK, but Sybase complains because the same column appears twice in the SQL statement generated by Hibernate.

Here are the classes:

public class A {
String id = null;

B b = null;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}

public B getB() {
return b;
}
public B setB(B b) {
this.b = b;
}

}

/******************/

public class B {
String id = null;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}


...and mappings follow:

<hibernate-mapping>
<class
name="A"
table="A"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
type="java.lang.String"
access="property"
column="code">

<generator class="native"/>

</id>

<many-to-one name="b"
class="B"
update="false"
insert="false"
column="code"/>

</class>

</hibernate-mapping>

/**************************/
<hibernate-mapping>
<class
name="B"
table="B"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
type="java.lang.String"
access="property"
column="code">

<generator class="native"/>

</id>

</class>

</hibernate-mapping>

GENERATED SQL STATEMENT:
Hibernate: select a0_.code as code1_, a0_.code as code1_, from A a0_

ERROR:
(util.JDBCExceptionReporter 38 ) SQL Error: 7348, SQLState: ZZZZZ
(util.JDBCExceptionReporter 46 ) Select expression results in more than one column having same name. Column name 'code1_' is specified more than once



Well, if someone understands what's happening i would appreciate some help.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
mmm, thats not a many-to-one association. that's a one-to-one association.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 2:18 pm 
Newbie

Joined: Thu Jun 03, 2004 7:08 pm
Posts: 6
First of all, thanks for answering.

Yes, you are right, that's a one-to-one association.

But i can't solve the problem when I use a composite-id.

For example if i change the id of class A so that it has something like:

...
<composite-id name="primaryKey" class="A_PK">
<key-property name="key1" type="java.lang.String" column="code"/>
<key-property name="key2" type="java.lang.String" column="code_2"/>
</composite-id>

<many-to-one name="b"
class="B"
update="false"
insert="false"
column="code"/>

....

Now, that's not a one-to-one association, cause many instances of A can have the same "key1" attribute in the primary key but different values of "key2".

Any solutions?


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