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: primary key in my Pojo with a different value
PostPosted: Tue Feb 21, 2006 4:41 pm 
Newbie

Joined: Tue Feb 21, 2006 4:29 pm
Posts: 4
version: Hibernate 3
db: MySql
dialect: org.hibernate.dialect.MySQLDialect
table creation:
create table if not exists myTable
( pk integer(10) unsigned not null auto_increment primary key,
name char(35),
) TYPE=INNODB;

mapping:
<hibernate-mapping>
<class name="com.MyObject" table="myTable">
<id name="pk" column="pk" type="java.lang.Long">
<generator class="native"/>
</id>

In my Pojo class, my primary key is using a java.lang.Long. When I run a simple select with hibernate, the field pk in my pojo would contain a value like 4294967297 instead of 1. If I change the type back to int in my mapping it sets pk to 1 which is fine. However I would like to use a Long in my Pojo. Can you clarify why this is happening and what to do? Sorry if thats a stupid question, I am new to Hibernate. Thanks.


Top
 Profile  
 
 Post subject: could it be the jdbc driver
PostPosted: Wed Feb 22, 2006 6:26 pm 
Newbie

Joined: Tue Feb 21, 2006 4:29 pm
Posts: 4
Actually I was wondering if that was the jdbc driver, the way it was converting datatype from the database to Java?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 10:39 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

Use <generator class="increment" />.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 4:59 pm 
Newbie

Joined: Tue Feb 21, 2006 4:29 pm
Posts: 4
cool it worked. Thanks!
My understanding was that this 'increment' or 'native' attribute was only used when inserting a new row... obviously I was wrong!


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.