-->
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.  [ 8 posts ] 
Author Message
 Post subject: GUID(uniqueidentifier) Types and Compound Keys
PostPosted: Tue Aug 26, 2003 3:21 pm 
Newbie

Joined: Tue Aug 26, 2003 2:31 pm
Posts: 15
Location: San Diego, CA
I have two tables, we can call them A and B. I am using Microsoft SQL Server 2000, compound keys that map to each other, and one of them is a uniqueidentifier. I am having problems with my hibernate mapping (I believe, since I am getting an error on generation.

(ill modify these tables to eliminate the extra rows that I know are working fine)

A is defined as:
Col1 varchar(5) *** Primary Key
Col2 uniqueidentifier *** Primary Key
uname varchar(50)

B is defined as:
Col1 varchar(5) *** Primary Key
Col2 uniqueidentifier *** Primary Key
qtrNum integer *** Primary Key
subject varchar(50)

The two tables are joined by a one-to-many relationship. Col1 and Col2 are the keys used in the relationship mapping.


In my Hibernate Mapping file, I have the following (again, going to cut out extra stuff):
For A:

<composite-id name="comp_id" class="com.hibernate.TableAPK">
<key-property name="Col1" column="Col1"/>
<key-property name="Col2" column="Col2"/>
</composite-id>
...
<set
name="TableBs"
lazy="true"
inverse="true"
>
<key>
<column name="Col1" />
<column name="Col2" />
</key>
<one-to-many
class="com.hibernate.TableB"
/>
</set>

For B:
<composite-id name="comp_id" class="com.hibernate.TableBPK">
<key-property name="Col1" column="Col1"/>
<key-property name="Col2" column="Col2"/>
<key-property name="qtrNum" column="qtrNum"/>
</composite-id>
...
<many-to-one
name="TableA"
class="com.hibernate.TableA"
not-null="true"
>
<column name="Col1"/>
<column name="Col2"/>
</many-to-one>


The files have a bunch of other <property> tags for the other columns, but this is the part I'm pretty sure I'm having problems with.

When I run the ant task, I get the following:


BUILD FAILED: file:E:/project/build.xml: Schema text failed: Problem trying to set property type by reflection: Could not find a getter for Col1 in the class com.hibernate.TableAPK.


So I'm not certain what I left out in order for the program to be able to create a getter. If I add type statements to the fields in the composite-id area, such as making them strings, then it will create the java no problem, but when I run the application, I get the same error. I am not certain if it is because I have a uniqueidentifier type or not. That really isn't a string, but I couldnt find in the documentation anything about uniqueidentifier types.

If anyone can help me out at all, I would really appreciate it. I have been trying to solve this problem for hours and just keep hitting a wall.

Thanks,
Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2003 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
>> <key-property name="Col1" column="Col1"/> <<

is "Col1" _really_ the property name??!

anyway, it should really be named col1, if the get/set pair is getCol1() / setCol1()


Top
 Profile  
 
 Post subject: It's not really called that
PostPosted: Tue Aug 26, 2003 4:37 pm 
Newbie

Joined: Tue Aug 26, 2003 2:31 pm
Posts: 15
Location: San Diego, CA
the real names are something like:
companyId and companySummaryId

it does have lower case.

However, the issue seems to be that in the java PK classes, not getter or setter is being created. In my PK classes, I have toString() and equals() methods, but no getter or setter.

In the main class, same name, but no PK after it, I dont have a getter or setter for the individual columns either (col1, col2, or in tableB's case, qtrNum). The only getter/setter I have is the getComp_id/setComp_id.

So it has mushed all of the ID's into a field called comp_id. So the PK class I assume is suppsed to handle the individual getters/setters, yet they are not being generated.

Is there something I have to set in my XML file to force the composite key's to have getters and setters made for them?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2003 5:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't follow; what is doing the generating??

hbm2java?


Top
 Profile  
 
 Post subject: yeah, hbm2java
PostPosted: Tue Aug 26, 2003 5:40 pm 
Newbie

Joined: Tue Aug 26, 2003 2:31 pm
Posts: 15
Location: San Diego, CA
We have the ANT script (hibernate-mapping.xml) and just run ant. I have other tables that generate fine. They include tables that don't have mapping and dont have composite key's. I think, though, that the problem has to do with either the composite key's or that one of the columns in the composite key is of the type uniqueidentifier in SQL Server.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2003 5:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Dude Hibernate is not a code generator!

What is doing code generation?? Middlegen? hbm2java?


I've no idea what you are talking about. Normally it is the user's responsibility to implement the get/set pair!


Top
 Profile  
 
 Post subject: hbm2java
PostPosted: Tue Aug 26, 2003 6:25 pm 
Newbie

Joined: Tue Aug 26, 2003 2:31 pm
Posts: 15
Location: San Diego, CA
Yes, it is using hbm2java. I realize it's not a code generator. However, in the past when I have the hibernate mapping file correctly formatted, hbm2java creates all the getters and setters. And it does so for all the tables in my current hibernate mapping file, except for the ones with compsite id's. The ones with composite id's have a correspodning PK java class that is created. These are the classes where I would expcet there to be a getter/setter, but it isn't there. I do, however, have another table with no foreign key mappings, but does have a composite id. The id's are both strings. And the correspodning PK class has the getter and setter.

It is because of the latter that I believe the problem has something to do with either the many-to-one relationship, or because I am using a uniqueidentifier type. What type should be assigned in the hibernate mapping file if you have a uniqueidentifier. I couldnt find them listed in the documentation.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2003 9:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK. Then it may be a bug in hbm2java. Max?


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