-->
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.  [ 1 post ] 
Author Message
 Post subject: Assigned primary key returns null when retrieve from db
PostPosted: Thu Oct 25, 2007 3:17 am 
Newbie

Joined: Thu Oct 25, 2007 2:20 am
Posts: 3
Location: Australia
I'm new to hibernate and this is my first post. Please tell me if I'm breaking protocol in any way.

The only post I could find with a similar issue was this one. http://forum.hibernate.org/viewtopic.php?t=939662

I'm hoping someone has a solution for me. I'm not experiencing the issue with native generator on an int key, only with assigned generator on a char id key.


Hibernate version:

3.2

Mapping documents:

I have a MS SQl Server 2005 table with char(2) primary key and I'm using the following mapping.

<class name="Country" table="country" lazy="false">
<id column="ccode1" type="string">
<generator class="assigned" />
</id>
<property name="ccode2" type="string"/>
<property name="ccode3" type="integer"/>
<property name="continent" type="string"/>
<property name="iddn" type="string"/>
<property name="timezone" type="string"/>
</class>

Code between sessionFactory.openSession() and session.close():

When a result object is return the primary keys is null. i.e.

String cCode = "AU";
session.beginTransaction();
Country c = (Country) session.load(Country.class,cCode);
session.getTransaction().commit();

<:Country>
<CCODE1>NULL</CCODE1>
<CCODE2>AUS</CCODE2>
<CCODE3>36</CCODE3>
<CONTINENT>OC</CONTINENT>
<IDDN>61</IDDN>
<TIMEZONE>+10</TIMEZONE>
</:Country>

This also occurs using criteria query and HQL to return a List of objects.


Name and version of the database you are using:

MS SQl Server 2005

The generated SQL (show_sql=true):

Hibernate: select country0_.ccode1 as ccode1_1_0_, country0_.ccode2 as ccode2_1_0_, country0_.ccode3 as ccode3_1_0_, country0_.continent as continent1_0_, country0_.iddn as iddn1_0_, country0_.timezone as timezone1_0_ from country country0_ where country0_.ccode1=?

_________________
---------------------------------------------------
Jason Sheedy
www.bytespring.com
www.jmpj.net
---------------------------------------------------


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.