Hibernate Postgres无法反序列化

时间:2013-01-23 22:26:16

标签: hibernate postgresql

public List<Marki> getMarki()
      {
        List<Marki> markiList = null;
        try {
            Session session = HibernateSession.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Query q = session.createQuery("from Marki ");
            if ( q != null ) {
                markiList = ( List<Marki> ) q.list();
            }
            // session.getTransaction().commit();
        } catch ( Exception e ) {
            e.printStackTrace();
        }
        return markiList;
 }

映射

<hibernate-mapping>
    <class name="bazaMap.Marki" table="marki" schema="public">
        <id name="id" type="int">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="marka" type="serializable">
            <column name="marka" unique="true" />
        </property>
        <set name="modeles" inverse="true">
            <key>
                <column name="markaid" not-null="true" />
            </key>
            <one-to-many class="bazaMap.Modele" />
        </set>
    </class>
</hibernate-mapping>


N



CREATE TABLE marki
(
  id serial NOT NULL,
  marka character varying(32)[],
  CONSTRAINT glowny PRIMARY KEY (id),
  CONSTRAINT marki_marka_key UNIQUE (marka)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE marki
  OWNER TO postgres;
  

FO:Hibernate:选择marki0_.id为id3_,marki0_.marka为marka3_   来自public.marki marki0_               INFO:无法从结果集中读取列值:marka3_;无法反序列化               SEVERE:org.hibernate.type.SerializationException:无法反序列化                 在org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:217)                 在org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:240)                 at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:82)                 在org.hibernate.type.SerializableType.get(SerializableType.java:39)                 在org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)                 在org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)                 在org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)                 在org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)                 在org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)                 在org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)                 在org.hibernate.loader.Loader.getRow(Loader.java:1206)                 在org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)                 在org.hibernate.loader.Loader.doQuery(Loader.java:701)                 在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)                 在org.hibernate.loader.Loader.doList(Loader.java:2220)                 在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)                 在org.hibernate.loader.Loader.list(Loader.java:2099)                 在org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912)                 在org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)                 在org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)                 在org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)                 在DataFetcher.getMarki(DataFetcher.java:40)

1.所有Mappings代码都是由NetBeans生成的。任何想法可能是错误的甚至更好 - 如何解决它?

嗒嗒 “你的帖子没有太多的背景来解释代码部分;请更清楚地解释你的场景。”

1 个答案:

答案 0 :(得分:1)

我敢打赌这是你的问题:

marka character varying(32)[],

您可能不需要数组字符。这可能是你想要的:

marka varchar(32),

最后我检查过Hibernate不知道如何处理开箱即用的Postgres数组,因为很少有RD​​BMS支持它们。