-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to add auto generated value with hibernate annotations
PostPosted: Tue Feb 17, 2009 2:23 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
Im finding a way to generate key for table and it needed to be increment one by one. like we did earlier in hibernate mapping file: like

Code:
<class name="com.Employee" table="Employee">
     <id name="empid" type="long" column="id" >
        <generator class="increment"/>
     </id>

    <property name="empname">
         <column name="name" />
     </property>
</class>


I want do this in my application and then insert incremented value to the table.

I tried this option:
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy=GenerationType.AUTO)

but it doesn't work.

Please help....

regards,
Dil.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 3:14 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
The increment type generator is not available in JPA annotations.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 3:35 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You need to use Hibernate specific annotations if you want to use the 'increment' generator. See http://www.hibernate.org/hib_docs/annot ... identifier for some information about it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 3:37 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
I found the solution:


Code:
     
    @Id
    @GenericGenerator(name="generator", strategy="increment")
    @GeneratedValue(generator="generator")
    @Column(name="ID")

    public int getId() {
        return id;
    }


This really works........


Top
 Profile  
 
 Post subject: Re: How to add auto generated value with hibernate annotations
PostPosted: Thu Aug 01, 2013 2:18 pm 
Newbie

Joined: Thu Aug 01, 2013 2:10 pm
Posts: 1
really thanks..... dilanalex

it worked for me


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