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??