Thank you for your replies,
my code is the following:
in the Entity:
@Id
@GeneratedValue(generator="MyGenerator")
@TableGenerator(
name="MyGenerator",
table=DBSCHEMA + "COUNTERTABLE",
pkColumnName="IDCOUNTER",
valueColumnName="COUNTER",
pkColumnValue="CONFIGS",
initialValue=1,
allocationSize=1) //increment
@JoinColumn(name="ID", nullable=false)
public int getId() {
return id;
}
In the table related to this entity I have preloaded some negative ids
(-1,-2...etcc..). Moreover, this entity has relation (ontomany, many to
one...) with other entity that have yet negative Ids. If I try to load
some entity i have no problem but, when I try to make persistent or
merge some new/edit entity I got the following error on entiry relations:
"Exception Description: Null primary key encountered in unit of work
clone".
If I work with positive Ids I have no problem.
So I tried to add in the persistence.xml the:
<property name="eclipselink.allow-zero-id" value="true"/>
(this is just to enable zero-id I think, by the name of the
property,...or it has some effect also on negative ids?).
Using this property the exception is solved but it seems that the Id are
not generated correctly (making persistent two entities, just one is
stored on the DB with ID=0).
Enrico
James ha scritto:
I don't think currently singleton primitive negative ids are allowed
without the flag (non-primitive or composite are ok, 0 or negative).
Are you trying to allow negative ids on something that uses
sequencing? That would be odd, but if you allow 0, and have a
primitive int/long id then it will default to 0, so EclipseLink will
think your two new objects are the same object. You would need to use
a Integer or Long so that the value is null when not assigned, or
remove the allow zero id flag. You can also set allowing 0 as an id
on a per class basis using the @PrimaryKey and IdValidation settings,
See,
http://www.eclipse.org/eclipselink/api/1.1.1/org/eclipse/persistence/annotations/PrimaryKey.html