-->
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: ID not being retrieved after saveOrUpdate in MySQL
PostPosted: Thu Oct 20, 2005 10:22 pm 
Newbie

Joined: Sat Mar 19, 2005 3:25 am
Posts: 9
Hi,

I have a situtation where I have a MySQL table with the following primary key definition

CREATE TABLE iitem (
`rID` BIGINT NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL default '',
`createdDate` timestamp NOT NULL default CURRENT_TIMESTAMP ,
`createdByID` decimal(10,0) NOT NULL default '1',
`lastModifiedDate` timestamp NOT NULL default '2005-01-01 12:00:00',
`lastModifiedByID` decimal(10,0) NOT NULL default '1',
`sID` varchar(255) NOT NULL default '',
`ownerID` decimal(10,0) NOT NULL default '1',
`parentID` decimal(10,0) default null,
`layoutID` decimal(10,0) default null,
`description` varchar(100) default '',
`securityPolicyID` decimal(10,0) default null,
`itemWorkspaceID` decimal(10,0) default null,
`itemProjectID` decimal(10,0) default null,
`isSecurityPolicyInherited` tinyint(4) default '0',
`contentType` varchar(30) not null default '',
`numberOfChildren` decimal(10,0) default 0,
PRIMARY KEY (`rID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

In the xml file the column is declared as follows:

<id name="id" type="long">
<column name="RID" sql-type="bigint" not-null="true"/>
<generator class="increment"/>
</id>


The column is inserted perfectly with this line of code:
workspaceDAO.makePersistent(workspace);

which does

public void makePersistent(Workspace item) throws InfrastructureException {
try {
HibernateUtil.getSession().saveOrUpdate(item);
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
}


I am expecting that after the makePersistent method is finished, the workspace object will have the id column populated with the newly generated primary key. However all I get is 0. Does anyone know why?


Top
 Profile  
 
 Post subject: More info
PostPosted: Thu Oct 20, 2005 11:02 pm 
Newbie

Joined: Sat Mar 19, 2005 3:25 am
Posts: 9
With I change the table definition to eliminate AUTO_INCREMENT from the primary key, I get this exception.

org.hibernate.HibernateException: The data base returned no natively generated identity value


In MySQL when you select identity for the generator type is AUTO_INCREMENT required on the PK column?

If not how will MySQL generate a PK value?

Thanks
Ed


Top
 Profile  
 
 Post subject: Re: More info
PostPosted: Fri Oct 21, 2005 10:58 am 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
scanzano wrote:
With I change the table definition to eliminate AUTO_INCREMENT from the primary key, I get this exception.

org.hibernate.HibernateException: The data base returned no natively generated identity value


In MySQL when you select identity for the generator type is AUTO_INCREMENT required on the PK column?

If not how will MySQL generate a PK value?

Thanks
Ed


You may want to try using the "native" generator for MySQL - I've had success with this in the past.

Don


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.