Discussion:
[Middlegen-user] Incompatible ID types when using sequence generator
Endre Meckelborg Rognerud
2005-03-31 11:55:49 UTC
Permalink
Hello!

I'm new to Hibernate and Middlegen. I think this is an easy issue, but I
haven't found a solution yet.

I'm porting an application to Hibernate, so the Oracle database is
already there. I have used Middlegen (with Maven) to create the
hibernate mapping files. Here is some of my configuration:

maven.middlegen.0.hibernate.javatypemapper=middlegen.plugins.hibernate.HibernateJavaTypeMapper
maven.middlegen.0.hibernate.standardgeneratorscheme=sequence
maven.middlegen.0.hibernate.standardgeneratorarg={0}_SEQ

I'm using Oracle, and default all the number-fields are mapped to the
type BigDecimal. This also includes the id-fields.

When I try to save a new object in Hibernate, I get the following exception:

"net.sf.hibernate.id.IdentifierGenerationException: this id generator
generates long, integer, short"

What is the way to fix this? Should I change my id-fields to be of type
Long? Can I use a property etc. to let Middlegen fix this automatically
when running Middlegen again?

Thanks for some tips :)
--
Regards...
Endre Rognerud
Wouter Boers
2005-03-31 19:09:46 UTC
Permalink
The sollution is quite easy.

Set the property middlegen.hibernate.gui = true (I'm sure this is the
correct one, doing this from the top of my head)

This wil allow the gui to run when you invoke middlegen via maven. The gui
allows you to specify the types of the collumn. My advise with middlegen and
oracle is to always do this, since the default mapping is always almost not
what you want. Always use Integer over int because and Interger is allowed
to be 'null' and an int is always initialized by Java to '0'.

Once you have set all your column types you can disable the gui since the
settings are saved in the preferences file created by middlegen.



-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net] On Behalf Of Endre
Meckelborg Rognerud
Sent: 31 March 2005 15:55
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] Incompatible ID types when using sequence
generator


Hello!

I'm new to Hibernate and Middlegen. I think this is an easy issue, but I
haven't found a solution yet.

I'm porting an application to Hibernate, so the Oracle database is
already there. I have used Middlegen (with Maven) to create the
hibernate mapping files. Here is some of my configuration:

maven.middlegen.0.hibernate.javatypemapper=middlegen.plugins.hibernate.Hiber
nateJavaTypeMapper
maven.middlegen.0.hibernate.standardgeneratorscheme=sequence
maven.middlegen.0.hibernate.standardgeneratorarg={0}_SEQ

I'm using Oracle, and default all the number-fields are mapped to the
type BigDecimal. This also includes the id-fields.

When I try to save a new object in Hibernate, I get the following exception:

"net.sf.hibernate.id.IdentifierGenerationException: this id generator
generates long, integer, short"

What is the way to fix this? Should I change my id-fields to be of type
Long? Can I use a property etc. to let Middlegen fix this automatically
when running Middlegen again?

Thanks for some tips :)
--
Regards...
Endre Rognerud


-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/info/Sentarus/hamr30
Endre Meckelborg Rognerud
2005-04-01 04:22:35 UTC
Permalink
Post by Wouter Boers
The sollution is quite easy.
Set the property middlegen.hibernate.gui = true (I'm sure this is the
correct one, doing this from the top of my head)
This wil allow the gui to run when you invoke middlegen via maven.
The gui allows you to specify the types of the collumn. My advise
with middlegen and oracle is to always do this, since the default
mapping is always almost not what you want. Always use Integer over
int because and Interger is allowed to be 'null' and an int is always
initialized by Java to '0'.
Once you have set all your column types you can disable the gui since
the settings are saved in the preferences file created by middlegen.
Thanks! That was my thoughts. I will do this, using Integers. I asked
because I thought Middlegen would use a type mapper with working
defaults :)
--
Med vennlig hilsen
Endre Rognerud (Webgruppa, SAUS, USIT, UIO)

GPG Public Key:
http://folk.uio.no/endremr/emr_gpg_pubkey.txt
Daniel Rosenbaum
2005-04-01 05:28:40 UTC
Permalink
Middlegen will use BigDecimal for Oracle numbers that have no bound,
since it is unknown how large the number can go. But if you know the
limit of your number, you could define the column as a NUMBER(3) or
NUMBER(9) or whatever and the HibernateJavaTypeMapper would choose an
int or Integer.
The sollution is quite easy.

Set the property middlegen.hibernate.gui = true (I'm sure this is the
correct one, doing this from the top of my head)

This wil allow the gui to run when you invoke middlegen via maven. The
gui
allows you to specify the types of the collumn. My advise with
middlegen and
oracle is to always do this, since the default mapping is always almost
not
what you want. Always use Integer over int because and Interger is
allowed
to be 'null' and an int is always initialized by Java to '0'.

Once you have set all your column types you can disable the gui since
the
settings are saved in the preferences file created by middlegen.



-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net] On Behalf Of Endre
Meckelborg Rognerud
Sent: 31 March 2005 15:55
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] Incompatible ID types when using sequence
generator


Hello!

I'm new to Hibernate and Middlegen. I think this is an easy issue, but
I
haven't found a solution yet.

I'm porting an application to Hibernate, so the Oracle database is
already there. I have used Middlegen (with Maven) to create the
hibernate mapping files. Here is some of my configuration:

maven.middlegen.0.hibernate.javatypemapper=middlegen.plugins.hibernate.Hiber
nateJavaTypeMapper
maven.middlegen.0.hibernate.standardgeneratorscheme=sequence
maven.middlegen.0.hibernate.standardgeneratorarg={0}_SEQ

I'm using Oracle, and default all the number-fields are mapped to the
type BigDecimal. This also includes the id-fields.

When I try to save a new object in Hibernate, I get the following
exception:

"net.sf.hibernate.id.IdentifierGenerationException: this id generator
generates long, integer, short"

What is the way to fix this? Should I change my id-fields to be of
type
Long? Can I use a property etc. to let Middlegen fix this
automatically
when running Middlegen again?

Thanks for some tips :)
--
Regards...
Endre Rognerud


-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/info/Sentarus/hamr30
_______________________________________________
middlegen-user mailing list
middlegen-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/middlegen-user



-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/info/Sentarus/hamr30
Endre Meckelborg Rognerud
2005-04-01 06:36:36 UTC
Permalink
Post by Daniel Rosenbaum
Middlegen will use BigDecimal for Oracle numbers that have no bound,
since it is unknown how large the number can go. But if you know the
limit of your number, you could define the column as a NUMBER(3) or
NUMBER(9) or whatever and the HibernateJavaTypeMapper would choose an
int or Integer.
This works! Thanks :)
--
Regards...
Endre Rognerud
Daniel Rosenbaum
2005-04-01 13:20:16 UTC
Permalink
You're welcome.

An alternative is to implement your own HibernateJavaTypeMapper. Just
grab the source for this class and modify it (perhaps changing the name
and package as well) to remove the code that returns BigDecimal, and
just code it to return Integers.

Then you also change

maven.middlegen.0.hibernate.javatypemapper=middlegen.plugins.hibernate.HibernateJavaTypeMapper

to

maven.middlegen.0.hibernate.javatypemapper=your.package.YourHibernateJavaTypeMapper

and/or the property in your ant script.

It is not very difficult to do. You can put any of your own default
types this way.

Daniel
Post by Daniel Rosenbaum
Middlegen will use BigDecimal for Oracle numbers that have no bound,
since it is unknown how large the number can go. But if you know
the
Post by Daniel Rosenbaum
limit of your number, you could define the column as a NUMBER(3) or
NUMBER(9) or whatever and the HibernateJavaTypeMapper would choose
an
Post by Daniel Rosenbaum
int or Integer.
This works! Thanks :)
--
Regards...
Endre Rognerud


-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/info/Sentarus/hamr30
Loading...