Hello.
I'm working with Pervasive Database and i'm trying to successfully make reverse engineering from database to java classes.
When reverse engineering is done, i have ready objects.
But.
In database (table called "Kh") i have column called "datawpr" and it has type "date".
After reverse field "datawpr" in my class has type Serializable.
When i try to get all records from database using hibernate, i get error listed below.
Code:
Exception in thread "main" org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.util.SerializationHelper.doDeserialize(SerializationHelper.java:262)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:306)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:130)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:116)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:39)
at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:62)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:331)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:593)
at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:668)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2542)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at pl.lanox.test.Test.main(Test.java:19)
Caused by: java.io.StreamCorruptedException: invalid stream header: 32303036
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:328)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:318)
at org.hibernate.util.SerializationHelper.doDeserialize(SerializationHelper.java:237)
... 22 more
my hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.pervasive.jdbc.v2.Driver</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.connection.url">jdbc:pervasive://10.10.10.4/NOWY3</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
and method where i try get all records
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<Kh> list = (List<Kh>) session.createCriteria(Kh.class).list();
session.getTransaction().commit();
Strange thing is that if i make Connection to this database via Eclipse, this column has data type "9". All others are fine (int, varchar etc.).
Also tried to add this type to revenge.cfg.xml file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="9" hibernate-type='timestamp' not-null="false"></sql-type>
</type-mapping>
</hibernate-reverse-engineering>
Result is same when i hardcoded types.
I've tried to hardcode types Serializable to other like: Objest, Date, String, but then i get a list of null objects.
Changing dialect also don't make difference.
When i'm trying to get access by sql, i'm receiving List<Object>.
But in my case i have to get List<Kh>.
Any ideas wham i'm doing wrong or what i'm not doing ?
I've just tried to insert new record to db and it worked.
what i get from reverse:
Code:
/**
* Kh generated by hbm2java
*/
@Entity
@Table(name = "KH", catalog = "NOWY3", uniqueConstraints = { @UniqueConstraint(columnNames = { "rodzaj", "typi", "kod" }),
@UniqueConstraint(columnNames = "id"), @UniqueConstraint(columnNames = { "typi", "kod" }),
@UniqueConstraint(columnNames = { "katalog", "kod" }) })
public class Kh {
private KhId id;
public Kh() {
}
public Kh(KhId id) {
this.id = id;
}
@EmbeddedId
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "id", unique = true)),
@AttributeOverride(name = "flag", column = @Column(name = "flag")),
@AttributeOverride(name = "subtypi", column = @Column(name = "subtypi")),
@AttributeOverride(name = "typi", column = @Column(name = "typi")),
@AttributeOverride(name = "znaczniki", column = @Column(name = "znaczniki")),
@AttributeOverride(name = "rodzaj", column = @Column(name = "rodzaj")),
@AttributeOverride(name = "katalog", column = @Column(name = "katalog")),
@AttributeOverride(name = "info", column = @Column(name = "info")),
@AttributeOverride(name = "osoba", column = @Column(name = "osoba", length = 5)),
@AttributeOverride(name = "kod", column = @Column(name = "kod", length = 40)),
@AttributeOverride(name = "nazwa", column = @Column(name = "nazwa", length = 100)),
@AttributeOverride(name = "miejscowosc", column = @Column(name = "miejscowosc", length = 40)),
@AttributeOverride(name = "ulica", column = @Column(name = "ulica", length = 35)),
@AttributeOverride(name = "dom", column = @Column(name = "dom", length = 15)),
@AttributeOverride(name = "lokal", column = @Column(name = "lokal", length = 15)),
@AttributeOverride(name = "kodpocz", column = @Column(name = "kodpocz", length = 10)),
@AttributeOverride(name = "regon", column = @Column(name = "regon", length = 16)),
@AttributeOverride(name = "pesel", column = @Column(name = "pesel", length = 11)),
@AttributeOverride(name = "nip", column = @Column(name = "nip", length = 20)),
@AttributeOverride(name = "statusUe", column = @Column(name = "statusUE")),
@AttributeOverride(name = "idKraju", column = @Column(name = "idKraju")),
@AttributeOverride(name = "tel1", column = @Column(name = "tel1", length = 15)),
@AttributeOverride(name = "tel2", column = @Column(name = "tel2", length = 15)),
@AttributeOverride(name = "fax", column = @Column(name = "fax", length = 15)),
@AttributeOverride(name = "email", column = @Column(name = "email", length = 40)),
@AttributeOverride(name = "naglowek", column = @Column(name = "naglowek", length = 19)),
@AttributeOverride(name = "nazwisko", column = @Column(name = "nazwisko", length = 24)),
@AttributeOverride(name = "imie", column = @Column(name = "imie", length = 14)),
@AttributeOverride(name = "idfk", column = @Column(name = "idfk")), @AttributeOverride(name = "idfk2", column = @Column(name = "idfk2")),
@AttributeOverride(name = "bnazwa", column = @Column(name = "bnazwa", length = 65)),
@AttributeOverride(name = "bkonto", column = @Column(name = "bkonto", length = 50)),
@AttributeOverride(name = "grupaceni", column = @Column(name = "grupaceni")),
@AttributeOverride(name = "upust", column = @Column(name = "upust", precision = 15, scale = 0)),
@AttributeOverride(name = "limiti", column = @Column(name = "limiti")),
@AttributeOverride(name = "limitkwota", column = @Column(name = "limitkwota", precision = 15, scale = 0)),
@AttributeOverride(name = "limitwaluta", column = @Column(name = "limitwaluta", length = 3)),
@AttributeOverride(name = "plattypi", column = @Column(name = "plattypi")),
@AttributeOverride(name = "plattermin", column = @Column(name = "plattermin")),
@AttributeOverride(name = "stanpl", column = @Column(name = "stanpl", precision = 15, scale = 0)),
@AttributeOverride(name = "stannl", column = @Column(name = "stannl", precision = 15, scale = 0)),
@AttributeOverride(name = "khfk", column = @Column(name = "khfk", length = 24)),
@AttributeOverride(name = "rejon", column = @Column(name = "rejon", length = 25)),
@AttributeOverride(name = "formaplatn", column = @Column(name = "formaplatn")),
@AttributeOverride(name = "typks", column = @Column(name = "typks", length = 40)),
@AttributeOverride(name = "negoc", column = @Column(name = "negoc")),
@AttributeOverride(name = "www", column = @Column(name = "www", length = 100)),
@AttributeOverride(name = "wprowadzil", column = @Column(name = "wprowadzil", length = 5)),
@AttributeOverride(name = "datawpr", column = @Column(name = "datawpr")),
@AttributeOverride(name = "zmodyfikowal", column = @Column(name = "zmodyfikowal", length = 5)),
@AttributeOverride(name = "datamod", column = @Column(name = "datamod")),
@AttributeOverride(name = "poledod1", column = @Column(name = "poledod1", length = 60)),
@AttributeOverride(name = "poledod2", column = @Column(name = "poledod2", length = 60)),
@AttributeOverride(name = "poledod3", column = @Column(name = "poledod3", length = 60)),
@AttributeOverride(name = "poledod4", column = @Column(name = "poledod4", length = 60)),
@AttributeOverride(name = "poledod5", column = @Column(name = "poledod5", length = 60)),
@AttributeOverride(name = "poledod6", column = @Column(name = "poledod6", length = 60)),
@AttributeOverride(name = "poledod7", column = @Column(name = "poledod7", length = 60)),
@AttributeOverride(name = "poledod8", column = @Column(name = "poledod8", length = 60)),
@AttributeOverride(name = "osfiz", column = @Column(name = "osfiz")),
@AttributeOverride(name = "zapas", column = @Column(name = "zapas", length = 22)) })
public KhId getId() {
return this.id;
}
public void setId(KhId id) {
this.id = id;
}
}
Code:
@Embeddable
public class KhId implements java.io.Serializable {
private Integer id;
private Short flag;
private Short subtypi;
private Short typi;
private Short znaczniki;
private Integer rodzaj;
private Integer katalog;
private Boolean info;
private String osoba;
private String kod;
private String nazwa;
private String miejscowosc;
private String ulica;
private String dom;
private String lokal;
private String kodpocz;
private String regon;
private String pesel;
private String nip;
private Short statusUe;
private Integer idKraju;
private String tel1;
private String tel2;
private String fax;
private String email;
private String naglowek;
private String nazwisko;
private String imie;
private Integer idfk;
private Integer idfk2;
private String bnazwa;
private String bkonto;
private Short grupaceni;
private Double upust;
private Short limiti;
private Double limitkwota;
private String limitwaluta;
private Short plattypi;
private Short plattermin;
private Double stanpl;
private Double stannl;
private String khfk;
private String rejon;
private Integer formaplatn;
private String typks;
private Boolean negoc;
private String www;
private String wprowadzil;
private Serializable datawpr;
private String zmodyfikowal;
private Serializable datamod;
private String poledod1;
private String poledod2;
private String poledod3;
private String poledod4;
private String poledod5;
private String poledod6;
private String poledod7;
private String poledod8;
private Short osfiz;
private String zapas;
public KhId() {
}
public KhId(Integer id, Short flag, Short subtypi, Short typi, Short znaczniki, Integer rodzaj, Integer katalog, Boolean info, String osoba,
String kod, String nazwa, String miejscowosc, String ulica, String dom, String lokal, String kodpocz, String regon, String pesel,
String nip, Short statusUe, Integer idKraju, String tel1, String tel2, String fax, String email, String naglowek, String nazwisko,
String imie, Integer idfk, Integer idfk2, String bnazwa, String bkonto, Short grupaceni, Double upust, Short limiti, Double limitkwota,
String limitwaluta, Short plattypi, Short plattermin, Double stanpl, Double stannl, String khfk, String rejon, Integer formaplatn,
String typks, Boolean negoc, String www, String wprowadzil, Serializable datawpr, String zmodyfikowal, Serializable datamod,
String poledod1, String poledod2, String poledod3, String poledod4, String poledod5, String poledod6, String poledod7, String poledod8,
Short osfiz, String zapas) {
this.id = id;
this.flag = flag;
this.subtypi = subtypi;
this.typi = typi;
this.znaczniki = znaczniki;
this.rodzaj = rodzaj;
this.katalog = katalog;
this.info = info;
this.osoba = osoba;
this.kod = kod;
this.nazwa = nazwa;
this.miejscowosc = miejscowosc;
this.ulica = ulica;
this.dom = dom;
this.lokal = lokal;
this.kodpocz = kodpocz;
this.regon = regon;
this.pesel = pesel;
this.nip = nip;
this.statusUe = statusUe;
this.idKraju = idKraju;
this.tel1 = tel1;
this.tel2 = tel2;
this.fax = fax;
this.email = email;
this.naglowek = naglowek;
this.nazwisko = nazwisko;
this.imie = imie;
this.idfk = idfk;
this.idfk2 = idfk2;
this.bnazwa = bnazwa;
this.bkonto = bkonto;
this.grupaceni = grupaceni;
this.upust = upust;
this.limiti = limiti;
this.limitkwota = limitkwota;
this.limitwaluta = limitwaluta;
this.plattypi = plattypi;
this.plattermin = plattermin;
this.stanpl = stanpl;
this.stannl = stannl;
this.khfk = khfk;
this.rejon = rejon;
this.formaplatn = formaplatn;
this.typks = typks;
this.negoc = negoc;
this.www = www;
this.wprowadzil = wprowadzil;
this.datawpr = datawpr;
this.zmodyfikowal = zmodyfikowal;
this.datamod = datamod;
this.poledod1 = poledod1;
this.poledod2 = poledod2;
this.poledod3 = poledod3;
this.poledod4 = poledod4;
this.poledod5 = poledod5;
this.poledod6 = poledod6;
this.poledod7 = poledod7;
this.poledod8 = poledod8;
this.osfiz = osfiz;
this.zapas = zapas;
}
+all getters and setters