-->
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.  [ 1 post ] 
Author Message
 Post subject: Populate Primary Key Using Database Trigger
PostPosted: Fri Mar 01, 2013 1:01 pm 
Newbie

Joined: Fri Dec 21, 2012 9:28 pm
Posts: 2
Hello

I am using Hibernate 4.1.0.Final with Spring 3

I have the following in Entity class

Code:
@Id
@Column(name = "PROJECT_NO")
@GeneratedValue(strategy=GenerationType.TABLE)
private String projectNumber;

Is it possible to use database trigger to populate the primary key of a table?
Or I have to use a CustomGenerator for this? i.e. trigger on my table will be used to insert primary key value rather than
Hibernate doing it.

In database trigger I have the following to populate value

Code:
SELECT NVL (MAX (project_no), 0) + 1 FROM projects


Any help is highly appreciable?

Edit, If I try with the following I am getting
Code:
:org.hibernate.id.IdentifierGenerationException:no natural-id property defined;
need to specify [key] in generator parameters

Code:
@Id
    @GeneratedValue(generator="triggerAssigned")
    @GenericGenerator(name="triggerAssigned",
      strategy = "org.hibernate.id.SelectGenerator",parameters = {
                @Parameter( name="keys", value="projectNo" )
        })
    @Column(name = "PROJECT_NO")   

   public int getProjectNo() {
    return projectNo;
   }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.