Hi!

It seems to me that a mapping of:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

and changing the config to the new generators in hibernate.cfg.xml:
<property name="hibernate.id.new_generator_mappings">true</property>
// 
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-id-enhanced

solve my problem!

Before I had the (incorrect?) mapping of:
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;

I could conclude that it was either a unique key constraint violation
(of primary key) of hibernate or
my fault with the wrong explicit generationtype.table and not .auto!

Regards,
Peter.

On Jul 14, 10:46 pm, Peter <tableyourt...@googlemail.com> wrote:
> maybe I hit this:
>
> http://opensource.atlassian.com/projects/hibernate/browse/HHH-5042
>
> On Jul 14, 10:44 pm, Peter <tableyourt...@googlemail.com> wrote:
>
> > Hi again,
>
> > now. this seems to be really a problem of hibernate+h2. hibernate
> > generates already existing ids!!??
>
> > The observations I made when importing data from an external data
> > source:
> > 1. I executed the import once. A lot of data (say X*1000) -> every
> > thing is fine
> > 2. The next import -> exception
>
> > But if I would have only imported less data (say X*100) in step 1. I
> > can execute this step multiple times without an error.
>
> > What id generation strategy should be used when using h2 with
> > hibernate?
>
> > Regards,
> > Peter.
>
> > On Jul 13, 8:22 pm, Peter <tableyourt...@googlemail.com> wrote:
>
> > > Hi Thomas,
>
> > > thanks for the quick response, this helped me.
>
> > > But why a different message occur for other ('normal') cases?
> > > Is it different because the primary key (MYTABLE.ID) instead of the
> > > additional unique constraint (on MYTABLE.NAME) is violated?
>
> > > Regards,
> > > Peter.
>
> > > On Jul 13, 8:10 pm, Thomas Mueller <thomas.tom.muel...@gmail.com>
> > > wrote:
>
> > > > Hi,
>
> > > > > Unique index or primary key violation: "MYTABLE_DATA ON
> > > > > PUBLIC.MYTABLE(ID, CREATEDAT, ..., ...)"
>
> > > > The problem is that there was a primary key violation. I agree it's a
> > > > weird error message, I will fix that in the next release. However,
> > > > it's definitely a primary key violation. Here is a test case that
> > > > throws a similar exception:
>
> > > > DROP TABLE IF EXISTS TEST;
> > > > CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
> > > > INSERT INTO TEST VALUES(1, 'Hello');
> > > > INSERT INTO TEST VALUES(1, 'World');
> > > > -- Unique index or primary key violation: "TEST_DATA ON PUBLIC.TEST(ID, 
> > > > NAME)"
>
> > > > > Is my database corrupt like suggested 
> > > > > here:http://fri13th.com/blog/archives/285
>
> > > > No. This blog article is quite old (2007). There were a lot of changes
> > > > in H2 since then. And this error message is not related to corruption.
>
> > > > Regards,
> > > > Thomas

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to h2-datab...@googlegroups.com.
To unsubscribe from this group, send email to 
h2-database+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to