-->
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.  [ 2 posts ] 
Author Message
 Post subject: Strange Occurrences with GeneratedValue and Id Column
PostPosted: Wed Sep 13, 2006 10:58 am 
Newbie

Joined: Mon Jun 13, 2005 1:39 pm
Posts: 6
Hibernate version:
Hibernate 3.2CR2
Hibernate Annotation 3.2CR1
Hibernate Entity Manager 3.2CR1

I'd have to double check this, but it's the latest versions that are compatible with each other (I was getting errors with Hibernate 3.2CR4, but fixed it after checking the forums)

Mapping documents:
Using annotations

Code between sessionFactory.openSession() and session.close():
Called from a transacational method with @PersistenceContext
Code:
return getEntityManager().createQuery("select level from Level level where level.featured = true").getResultList();


Name and version of the database you are using:
MySQL 5.0.22

The generated SQL (show_sql=true):
Code:
select level0_.id as id2_, level0_.name as name2_, level0_.location as location2_, level0_.fid as fid2_, level0_.downloads as downloads2_, level0_.featured as featured2_, level0_.fileId as fileId2_ from levels level0_


Problem:

When I run a JUnit test for the Entity's CRUD functionality, the id's generated by Hibernate/MySQL are correct. I'm using an auto-incrementing column in MySQL, and my entity property looks like this

Code:
   @Id
   @Column(name="id") @GeneratedValue(strategy=GenerationType.AUTO)
   public int getLevelId() {
      return levelId;
   }


Both GenerationType.AUTO and GenerationType.IDENTITYgive me the same result. The ID's are generated correctly (1,2,3, etc.). Sounds good so far, but this is where things go pear shaped :(.

When I call my findAllFeatured method (the code posted above) from a Struts Action, the ID's that are returned by getLevelID are incorrect. They are very large numbers like 4294967297, even though when I look at the database they're definitely not these numbers. This is the exact same method I'm calling in the aformentioned JUnit test.

This is way too weird, I'm not even sure how to diagnose the problem. Any help is very much appreciated.[quote][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 2:46 pm 
Newbie

Joined: Mon Jun 13, 2005 1:39 pm
Posts: 6
I changed my id in my entity from a long to an int, then I went to lunch and ate a delicious pastrami sandwich.

I'm not sure which of those solved it, but this problem seems to have disappeared.

Just Remember Kids: No matter how weird problem it is, it's probably not a bug in Hibernate.


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