-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate is ignoring @Table(name = "foo") annotat
PostPosted: Sun Oct 09, 2005 10:41 pm 
Beginner
Beginner

Joined: Thu Sep 16, 2004 8:14 pm
Posts: 27
I'm using Hibernate 3.1rc1 and Hibernate Annotations 3.1beta6. I have an Address class that is annotated like so:

@org.hibernate.annotations.Entity(
selectBeforeUpdate = true,
dynamicInsert = true,
dynamicUpdate = true,
optimisticLock = OptimisticLockType.ALL)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@BatchSize(size = 5)
@Table(name = "addresses")
@javax.persistence.Entity
public class Address implements Serializable {
private static final long serialVersionUID = 123;

...
}


I have some code that tries to save an address:

Transaction tx = session.beginTransaction();
Address address = new Address();
address.setCity(city);
address.setStreet(street);
session.persist(address);
tx.commit();

The SQL that is getting generated is:

insert into Address (city, lat, street, long, id) values (?, ?, ?, ?, ?)

The problem is that my table name is "addresses", but Hibernate seems to be using the name of the class instead. The spec says that the classname is the default table name unless the @Table(name) attribute is specified.
So, is there some reason that Hibernate is ignoring that annotation and trying to use the class name instead?
-M@


Top
 Profile  
 
 Post subject: found my problem
PostPosted: Mon Oct 10, 2005 2:28 am 
Beginner
Beginner

Joined: Thu Sep 16, 2004 8:14 pm
Posts: 27
For some reason I was thinking that I needed to import org.hibernate.annotations.Table. I changed this to javax.persistence.Table and it started working as advertised.
This makes me wonder what the org.hibernate.annotations package is for. Is there a time when I would ever want to code against those instead of the similarly named annotations in javax.persistence?
-M@


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 5:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
define metadata not available in javax.persistence
Look at the (java)doc

_________________
Emmanuel


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