-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using serial columns with PostgreSQL 8.0 and Hibernate Tools
PostPosted: Mon Apr 25, 2005 9:41 am 
Newbie

Joined: Mon Apr 25, 2005 8:39 am
Posts: 2
Location: Düsseldorf
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?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 12:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you have a "0" placed in the middle which shouldnt be there.

overriding much of these settings is available in cvs now, unfortunately not the id settings, but we will add that soon.

_________________
Max
Don't forget to rate


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

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.