-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate in Spring @GeneratedValue annotations not working
PostPosted: Sat Apr 02, 2016 9:33 am 
Newbie

Joined: Sat Apr 02, 2016 9:19 am
Posts: 2
I use Scaffolding in MyEclipse to generate Web Application project, using spring MVC and MySQL database. Please give me some clues to solve problem bellow.

I get problem with id primary key. It doesn't auto increment event if i use:
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy=GenerationType.AUTO)
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@GeneratedValue(strategy=GenerationType.TABLE)


I have several tables with the primary key set to AUTO_INCREMENT. Like this example:
Code:
    CREATE TABLE IF NOT EXISTS `ehealthdb`.`timestamp` (
      `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '',
      `login_date` DATETIME NULL COMMENT '',
      `logout_date` DATETIME NULL COMMENT '',
      `create_date` DATETIME NOT NULL COMMENT '',
      `update_date` DATETIME NULL COMMENT '',
      `isActive` TINYINT(1) NULL COMMENT '',
      PRIMARY KEY (`id`)  COMMENT '')
    ENGINE = InnoDB;


When I try to use the save using the generated post URL and the following json payload:

Code:
    {
     "loginDate":"1374839856000",
     "logoutDate":"1374839856000",
     "createDate":"1374839856000",
     "updateDate":"1374839856000",
     "isActive":true
    }


Quote:
> Request processing failed; nested exception is javax.persistence.PersistenceException:
org.hibernate.id.IdentifierGenerationException: ids for this class
must be manually assigned before calling save():
ehealth.domain.Timestamp


I think this is caused by a missing @GeneratedValue, which scaffolding has not created on my primary keys. I had to add it in manually like below:

But It's still not work. It's still get error.
Code:
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY) //add this
    @Column(name = "id", unique = true, nullable = false)
    @Basic(fetch = FetchType.EAGER)
    @XmlElement
    Integer id;
   


Top
 Profile  
 
 Post subject: Re: Hibernate in Spring @GeneratedValue annotations not working
PostPosted: Sun Apr 03, 2016 1:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I think this issue is related to MyEclipse and not to Hibernate. You need to post this question on their forum.


Top
 Profile  
 
 Post subject: Re: Hibernate in Spring @GeneratedValue annotations not working
PostPosted: Sun Apr 03, 2016 5:09 am 
Newbie

Joined: Sat Apr 02, 2016 9:19 am
Posts: 2
Thank you so much for your reply. :)
I see that. MyEclipse doesn't generate @GenerateValue annotation It's the problem of MyEclipse.:(
but even I try to add it manually, It's still doesn't work. So I think that it's the problem of Hibernate. :(
Do you have any ways to solve this problem ?
Please help me!!
Thanks,


Top
 Profile  
 
 Post subject: Re: Hibernate in Spring @GeneratedValue annotations not working
PostPosted: Sun Apr 03, 2016 2:58 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The mapping loooks fine, so I don't know what it can be.


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