Hello,
Database: mysql 4.1
Tablemanager: InnoDB
CREATE TABLE db1.`type` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL default '',
`description` varchar(100) default '',
`userid` varchar(100) NOT NULL default '',
`validFrom` timestamp NOT NULL default '0000-00-00 00:00:00',
`validTo` timestamp NOT NULL default '0000-00-00 00:00:00',
`version` int(11) unsigned NOT NULL default '0',
PRIMARY KEY (`id`,`version`),
UNIQUE KEY `u_id_validto` (`id`,`validTo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
This table enables you to have the following entries:
id | name | | validTo | version
-----+----------+-...-+---------------------+---------
1 | name1 | | 11.11.2002 00:00:00 | 0
1 | name1 | | 11.11.2003 00:00:00 | 1
1 | name1 | | 11.11.2004 00:00:00 | 2
...
1 | name1 | | 00.00.0000 00:00:00 | <n>
...
2 | name2 | | 11.11.2002 00:00:00 | 0
2 | name2 | | 11.11.2003 00:00:00 | 1
...
2 | name2 | | 00.00.0000 00:00:00 | <n>
...
<n> | name<n> | | 00.00.0000 00:00:00 | <n>
If you try to insert 'null' into the auto_increment field 'id', the
value is incremented. If you insert an already existing value, it is
accepted. e.g.
insert (id,name,...,validTo,version) into <table>
values (null, 'name<n+1>',...,00.00.0000 00:00:00 | 0);
will create the following entry:
<n+1>| name<n+1>| | 00.00.0000 00:00:00 | 0
insert (id,name,...,validTo,version) into <table>
values (1, 'name1',...,00.00.0000 00:00:00 | <n+1>);
will create the following entry:
1 | name1 | | 00.00.0000 00:00:00 | <n+1>
=====================================================
I tried to set this up with OpenJPA:
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( name = "id",
columnDefinition = "bigint(20) unsigned",
nullable = false, insertable = true, updatable = false )
public java.math.BigInteger getId() { return this.id; }
Not surprisingly, OpenJPA rejects to persist an entity having
the id '1' (analog sql example above).
Not surprisingly, OpenJPA persists entitys having the id 'null'
by replacing 'null' with '0' which makes mysql store an entity
using the id '0'.
...
It's a temporary solution for me to change the entity bean like
this:
@Id
// removed @GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( name = "id",
columnDefinition = "bigint(20) unsigned",
// changed: nullable = false
nullable = true, insertable = true, updatable = false )
public java.math.BigInteger getId() { return this.id; }
Which makes the gameplay between OpenJPA and the mysql database
behave like it should: increment nulls and insert none-nulls.
In the end, this is a poor workarround, because one could never
let the EJB Server create a fully functional database...
So my Question:
Is there a way to fully describe the behaviour I need by annotations?
Ty in advance