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]