I get this DDL (postgres target) when I add the goal hbm2ddl
using the Maven plugin hibernate3-maven-plugin
:
create table listing (
id varchar(36) not null,
hash_code int4 not null,
version int4,
name varchar(100),
primary key (id)
);
I defined all the columns shown.
All examples of using that I have seen on the web of:
private static final long serialVersionUID = -8402611044513083864L;
never have a @Column
annotation. My DDL does not have a column for it. Does anybody else's?
So how does the deserialization code in Java know what version of a class was serialized and stored vs the one that it is being deserialized into?
Serial version UID is used when object is serialized / deserialized.
If you annotate your object as an JPA Entity you're not using a serialization but just transforming your object to another representation - as a row in the database table.
When you fetch the row from the database, this data is used to create a new instance of object with properly set state.
Serialization, on the other hand, is used if you want to construct a binary representation of your object and then recreate the object instance using deserialization process.
Note that you can use serialization with JPA i.e. if you want to persist a field (within your JPA entity) which is neither a basic type, embeddable nor other entity but just a plain Java class which implements Serializable marker interface.
However, in this case only this given field in your entity is using serialization/deserialization to put binary data into database column. Still - the serial version UID is not stored anywhere in the database.
For more information about persistent fields (which are persisted and which are not) you can take a look at 2.2 Persistent Fields and Properties chapter in JPA 2.0 FR specification.