-->
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: Getting generated primary keys with TableGenerator (JPA)
PostPosted: Wed May 14, 2008 4:52 am 
Newbie

Joined: Wed May 14, 2008 4:47 am
Posts: 1
Hibernate version:
3.2
Name and version of the database you are using:
Oracle 10g

Hi,
I got the following problem

I am generating primary Keys (Id) with the help of an extra table ("HIBERNATE_KEY_TABLE")

[HTML]
/**
* gets Id (primary key)
*
* @return id Id (primary key)
*/
@Id
@TableGenerator(name = "TABLENAME_GENERATOR", table = "HIBERNATE_KEY_TABLE",pkColumnName = "TABLE_NAME", valueColumnName = "NEXT_VALUE", pkColumnValue = "TABLENAME",allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLENAME_GENERATOR")
@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, precision = 10)
public long getId() {
return this.id;
}

/**
* sets Id (primary key)
*
* @param id Id (primary key)
*/
public void setId(long id) {
this.id = id;
}
[/HTML]

This iw working fine so far. The persist of an entity is ok, but if I try to get the Id with getId() I receive "0" instead of the original Id.

[HTML]
/* persist the object */
manager.persist(brain);
long id = brain.getId();
[/HTML]

Any ideas?

Tns in advance,
Markus


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 7:26 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Try to use Long instead of long

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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.