-->
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: generate value in annotations
PostPosted: Wed Aug 18, 2010 8:08 am 
Beginner
Beginner

Joined: Thu Nov 12, 2009 1:57 am
Posts: 22
Hi,
what is the type of generator used when we use the following hibernate annotation
Code:
@GeneratedValue


While using the hbm file, we have option of specifying generator using following tag
Code:
        <id name="id" type="long" unsaved-value="null">
            <generator class="native"/>
        </id>


Do we have similar kind of option while using annotations.

I check the ouput while saving Message entity, and came across following o/p

select GC820NODE3.hibernate_sequence.nextval from dual

How does hibernate associate hibernate_sequence with GeneratedValue.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: generate value in annotations
PostPosted: Wed Aug 18, 2010 4:39 pm 
Newbie

Joined: Tue Aug 17, 2010 3:29 pm
Posts: 12
Code:
@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
public String getId() {

@Id @GeneratedValue(generator="hibseq")
@GenericGenerator(name="hibseq", strategy = "seqhilo",
    parameters = {
        @Parameter(name="max_lo", value = "5"),
        @Parameter(name="sequence", value="heybabyhey")
    }
)
public Integer getId() {


directly copied from documentation.


Top
 Profile  
 
 Post subject: Re: generate value in annotations
PostPosted: Thu Aug 19, 2010 7:17 am 
Beginner
Beginner

Joined: Thu Nov 12, 2009 1:57 am
Posts: 22
@Id @GeneratedValue
@Column(name = "MESSAGE_ID")
private Long id;

If i try to use above statement. The hibernate_sequence sequence is being used, but i have not specified the sequence in my GeneratedValue. It means that hibernate_sequence is being used by default for Id generation.

In case 2 threads simultaneously try to save an object, how will the sequence number generation take place and will hibernate take care of deadlock situations.


Top
 Profile  
 
 Post subject: Re: generate value in annotations
PostPosted: Thu Aug 19, 2010 9:14 am 
Newbie

Joined: Tue Aug 17, 2010 3:29 pm
Posts: 12
There is no problem with multi threading. hybernate takes care of it.


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.