-->
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: Firebird and a indentity field
PostPosted: Sat Jun 25, 2005 7:38 am 
Newbie

Joined: Sat May 14, 2005 2:17 pm
Posts: 18
I played around with WilsonNHibernateExample (http://weblogs.asp.net/pwilson/archive/ ... 09042.aspx).

It is a nice example program and I got it working with MySql. But when I try to get it to work with FireBird I seem te have problems with the Contacts table.

I think it has to do with te AutoInc field in MySql and the lack of it in FireBird.

So I created the contact table like this:

CREATE GENERATOR "CONTACTS_GENERATOR";

CREATE TABLE "CONTACTS"
(
"CONTACTID" INTEGER NOT NULL,
"CONTACTNAME" VARCHAR(50) NOT NULL,
"CONTACTTYPE" CHAR(1) NOT NULL,
"COMPANYNAME" VARCHAR(50),
"ADDRESSLINE" VARCHAR(50),
"ADDRESSCITY" VARCHAR(50),
"ADDRESSSTATE" VARCHAR(2),
"ADDRESSZIP" VARCHAR(5),
PRIMARY KEY ("CONTACTID")
);
SET TERM ^ ;


/* Triggers only will work for SQL triggers */

CREATE TRIGGER "CONTACTS_BI" FOR "CONTACTS"
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
NEW.ContactId = GEN_ID(CONTACTS_GENERATOR, 1);
END
^

COMMIT WORK ^
SET TERM ;^

Changed the mapping file to:
<id name="Id" column="ContactId" access="nosetter.camelcase" unsaved-value="0">
<!--generator class="identity" /-->
<generator class="sequence" />
</id>

And it ttill doesn't work. I get an error "Could not save object" when I process the line session.SaveOrUpdate(this.contact);

So how do I use FireBird with a generator?

Bas


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 25, 2005 9:36 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
You have to add the name of the generator in the mapping:

Code:
<id name="Id" column="ContactId" access="nosetter.camelcase" unsaved-value="0">
  <!--generator class="identity" /-->
  <generator class="sequence">
    <param name="sequence">CONTACTS_GENERATOR</param>
  </generator>
</id>


It's also an option to change the class of the generator to 'native' and still add the sequence parameter. This way, you don't have to alter the mapping file when switching between MySQL (or SQL Server) and Firebird.

Finally, I don't think you need the insert trigger because NHibernate retrieves the new sequence value itself.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 26, 2005 4:21 am 
Newbie

Joined: Sat May 14, 2005 2:17 pm
Posts: 18
Thank you that worked!
Is this is a wiki entry worth?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 26, 2005 6:08 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Sure, add it if you want.


Top
 Profile  
 
 Post subject: Re: Firebird and a indentity field
PostPosted: Tue Sep 13, 2011 5:22 am 
Newbie

Joined: Mon Sep 07, 2009 4:20 pm
Posts: 12
Is it not possible to configure hibernate not to take care of the PK-generation at all?

I want that only the trigger in Firebird takes care. The application should not need to know about that.


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.