Hello together,
I used Hibernate Tools 3.0 alpha with Eclipse 3.1M5 to generate the data class and configuration files from an existing PostgreSQL 8.0-DB. This db has a table named "acronym" which contains a column "acronym_id" of type serial.
Everything seemed to be allright until I tried to get a SessionFactory.
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
After reading the documentation and several forum entries I recognized that I have to change the id-tag in Acronym-hbm.xml from the generated
Code:
<id
name="AcronymId"
type="java.lang.Integer"
>
<column name="acronym_id" length="4" not-null="true" unique="true" sql-type="int4" /> 0
<generator class="sequence" />
</id>
to (acronym_acronym_id_seq was created by Postgre automatically when I created the db)
Code:
<id
name="AcronymId"
type="java.lang.Integer"
>
<column name="acronym_id" length="4" not-null="true" unique="true" sql-type="int4" /> 0
<generator class="sequence">
<param name="sequence">acronym_acronym_id_seq</param>
</generator>
</id>
This changes caused the following error:
Code:
13:37:02,234 ERROR [XMLHelper] Error parsing XML: XML InputStream(25) The content of element type "id" must match "(meta*,column*,generator?)".
13:37:02,234 ERROR [LogInterceptor] RuntimeException in method: public abstract java.lang.Object jacro.interfaces.JAcroFacade.getData(java.lang.Object) throws java.rmi.RemoteException:
org.hibernate.MappingException: Error reading resource: jacro/data/db/Acronym.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1313)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1285)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1267)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1234)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1148)
at jacro.ejb.JAcroFacadeBean.getData(JAcroFacadeBean.java:73)
......
After that I tried to change the id-tag as shown in some tutorials.
Code:
<id name="AcronymId" type="java.lang.Integer" column="acronym_id">
<generator class="sequence">
<param name="sequence">acronym_acronym_id_seq</param>
</generator>
</id>
With this id-tag I was able to get a SessionFactory-object and to insert new data to my table (removed the <column />-tag). Is the internal column-tag not allowed if there is a generator-tag too? Bug or feature?
By the way, is there a possibility to apply the default values of the database?