-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: PostgreSQL SERIAL data type (INTEGER + SEQUENCE)
PostPosted: Mon Feb 04, 2008 3:03 pm 
Newbie

Joined: Mon Feb 04, 2008 12:49 pm
Posts: 3
Location: Brazil
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.2

Mapping documents:
Atividade.hbm.xml
Code:
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="Atividade" table="Atividade">
      <!-- Coluna identificadora  -->
      <id name="id" type="long" column="id">
         <generator class="sequence">
            <param name="sequence">atividade_id_seq</param>
         </generator>
      </id>
      
      <property name="descricao" column="descricao" type="string" length="60" />
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
It's working fine. No need.

Full stack trace of any exception that occurs:
Here it goes:
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ExceptionInInitializerError
   at HibernateUtil.<clinit>(HibernateUtil.java:14)
   at Teste.<init>(Teste.java:6)
   at Teste.main(Teste.java:41)
Caused by: org.hibernate.PropertyAccessException: Exception occurred inside getter of Atividade.id
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:148)
   at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:44)
   at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
   at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
   at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
   at HibernateUtil.<clinit>(HibernateUtil.java:12)
   ... 2 more
Caused by: java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
   ... 11 more
Caused by: java.lang.NullPointerException
   at Atividade.getId(Atividade.java:20)
   ... 16 more



Name and version of the database you are using:
PostgreSQL 8.2.6

The generated SQL (show_sql=true):
It wasn't showed.

Debug level Hibernate log excerpt:
I dunno where I can find it =/


The question is...
I have an old legacy database schema in wich I'm developing a Web portal to some software modules.
The problem is on PostrgreSQL data columns of type SERIAL, which creates its own sequence (table ATIVIDADE owns ATIVIDADE_ID_SEQ sequence on database).
When I used generator ASSIGNED on the mapping file, it works perfectly since the first row was inserted. The second transaction fails because the primary key (that is only ID column) was violated.
After read the Hibernate reference, I fix the code as it is above, and still causing an error, another one now.

How I can set Serial column types (wich are Integer with a sequence anyways) of PostgreSQL in Hibernate??

_________________
T.J. Adami


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.