Skip to main content



      Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Auto-increment a non-id column using annotations
[Teneo] Auto-increment a non-id column using annotations [message #1611338] Wed, 11 February 2015 04:52 Go to next message
Eclipse UserFriend
Hi everybody,

I have an ecore model which I'm persisting in a PostgreSQL database using Teneo with Hibernate. In this model there is an attribute (an order number), which should be automatically incremented. I solved this using these annotations:
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(insertable=false, updatable=false, columnDefinition="Serial not null")

This works fine, but using 'Serial' in columnDefinition will make me dependent on postgres, so I'm searching for another solution.
I can't define it as id, because I already have an id-attribute.

Thanks for any hints.
Re: [Teneo] Auto-increment a non-id column using annotations [message #1611785 is a reply to message #1611338] Wed, 11 February 2015 11:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Stefanie,
I am not a postgres expert.., but can't you try another type than serial?

gr. Martin

On 11-02-15 15:46, Stefanie Müller wrote:
> Hi everybody,
>
> I have an ecore model which I'm persisting in a PostgreSQL database using Teneo with Hibernate. In this model there is
> an attribute (an order number), which should be automatically incremented. I solved this using these annotations:
> @GeneratedValue(strategy=GenerationType.IDENTITY)
> @Column(insertable=false, updatable=false, columnDefinition="Serial not null")
>
> This works fine, but using 'Serial' in columnDefinition will make me dependent on postgres, so I'm searching for another
> solution.
> I can't define it as id, because I already have an id-attribute.
>
> Thanks for any hints.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Auto-increment a non-id column using annotations [message #1622049 is a reply to message #1611785] Wed, 18 February 2015 03:16 Go to previous messageGo to next message
Eclipse UserFriend
Yes, I could use another type than serial, but then I have to generate the sequence for auto-incrementing on my own. I don't have a clue how to do that with annotations for a non-id column. Actually there is a sequence generated by using the type "serial".

By the way, I only use the second annotation
@Column(insertable=false, updatable=false, columnDefinition="Serial not null")

the other annotation is obsolete for my purpose.

Re: [Teneo] Auto-increment a non-id column using annotations [message #1622112 is a reply to message #1622049] Wed, 18 February 2015 04:13 Go to previous messageGo to next message
Eclipse UserFriend
Hi Stefanie,
I have never used it myself but afaics you can define sequences also in JPA, so tell the DB to create a sequence:
http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Sequence_Strategies

Probably there are more links on the net on this providing information on it.

gr. Martin

On 18-02-15 09:16, Stefanie Müller wrote:
> Yes, I could use another type than serial, but then I have to generate the sequence for auto-incrementing on my own. I
> don't have a clue how to do that with annotations for a non-id column. Actually there is a sequence generated by using
> the type "serial".
>
> By the way, I only use the second annotation @Column(insertable=false, updatable=false, columnDefinition="Serial not
> null")
> the other annotation is obsolete for my purpose.
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Auto-increment a non-id column using annotations [message #1622175 is a reply to message #1622112] Wed, 18 February 2015 05:08 Go to previous messageGo to next message
Eclipse UserFriend
Hi Martin,

thanks for this hint.

I tried to use these annotations
@TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="EMP_SEQ")
@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")

but the sequence_table isn't generated correctly. I found a previous topic (www.eclipse.org/forums/index.php/t/154301/) where you said: "...that pkColumn* are not being picked up by Teneo". Is this still the behaviour of Teneo?

Thanks in advance!

Regards, Steffi
Re: [Teneo] Auto-increment a non-id column using annotations [message #1622187 is a reply to message #1622175] Wed, 18 February 2015 05:16 Go to previous messageGo to next message
Eclipse UserFriend
Ha indeed, I can probably solve this (that the pkcolumnname is ignored), can you enter a bugzilla for it?

I can probably find time within 1-2 weeks to solve this.

Which version of Teneo are you on? (I prefer to solve things in the latest 2.1.0 version)

gr. Martin

On 18-02-15 11:08, Stefanie Müller wrote:
> Hi Martin,
>
> thanks for this hint.
>
> I tried to use these annotations
> @TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT",
> pkColumnValue="EMP_SEQ")
> @GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")
> but the sequence_table isn't generated correctly. I found a previous topic (www.eclipse.org/forums/index.php/t/154301/)
> where you said: "...that pkColumn* are not being picked up by Teneo". Is this still the behaviour of Teneo?
>
> Thanks in advance!
>
> Regards, Steffi


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Auto-increment a non-id column using annotations [message #1622341 is a reply to message #1622187] Wed, 18 February 2015 07:26 Go to previous messageGo to next message
Eclipse UserFriend
Hi Martin,

I'm afraid I forgot to test, if the sequence-table is also generated with a non-id column... The resolution is - it doesn't.
Thus these annotations are unfortunately no solution and I won't enter a bugzilla Sad

Nevertheless I'm really thankful for your input Smile

Regards, Steffi
Re: [Teneo] Auto-increment a non-id column using annotations [message #1622355 is a reply to message #1622341] Wed, 18 February 2015 07:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi Stefanie,
I found this thread on the same topic:
http://stackoverflow.com/questions/277630/hibernate-jpa-sequence-non-id

It describes some workarounds, the main thing (after reading really quickly) is to generate the value yourselve in java.

The above is an old thread, maybe latest Hibernate versions provide different support, for the latest Hibernate you need
to use Teneo 2.1.0.

Hope it helps.

gr. Martin


On 18-02-15 13:26, Stefanie Müller wrote:
> Hi Martin,
>
> I'm afraid I forgot to test, if the sequence-table is also generated with a non-id column... The resolution is - it
> doesn't.
> Thus these annotations are unfortunately no solution and I won't enter a bugzilla :(
>
> Nevertheless I'm really thankful for your input :)
>
> Regards, Steffi


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo] Auto-increment a non-id column using annotations [message #1634477 is a reply to message #1622355] Wed, 25 February 2015 04:37 Go to previous message
Eclipse UserFriend
Hi Martin,

we decided to keep our actual solution. If we get a feature request to support a non-postgres database, we will then try to find another solution. It seems, that won't be in the near future...

Thanks for your help!
Previous Topic: [ECP] ECP and element links inside widgets
Next Topic:[EMFForms] TableControl Master/Detail Error
Goto Forum:
  


Current Time: Thu Jul 10 22:32:55 EDT 2025

Powered by FUDForum. Page generated in 0.07516 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top