Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Problem with mapping: Wrong column type
PostPosted: Tue Jan 13, 2009 12:10 pm 
Newbie

Joined: Tue Jan 13, 2009 11:23 am
Posts: 12
Hi everyone,
I'm devolpping a jboss seam 2.0.3GA application, and I have same problems when I try to map my tables from my database (Postgresql 8.2) , here is the exception and I can't deploy my application to the server:

Code:
16:18:57,609 INFO  [TableMetadata] table found: public.aire_protegee
16:18:57,609 INFO  [TableMetadata] columns: [rv_est, vent_vitesse_min, superficie, rv_so, pluviom_moyenne, vent_vitesse_moyenne, vent_vitesse_max, poi_id, temp_moyenne, id, pluviom_min, rv_no, nom_ap, temp_max, pluviom_max, rv_se, rv_ouest, rv_nord, temp_min, rv_sud, rv_ne, cla_id, ind_id]
16:18:57,625 ERROR [[/sigpn]] Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.jboss.seam.servlet.SeamListener
org.jboss.seam.InstantiationException: Could not instantiate Seam component: sigpnEntityManagerFactory
   at org.jboss.seam.Component.newInstance(Component.java:1986)
   at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
   at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
   at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
   at org.jboss.seam.init.Initialization.init(Initialization.java:596)
   at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
............

Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: temp_moyenne, expected: int8
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
   at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:85)
   at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
   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.jboss.seam.util.Reflections.invoke(Reflections.java:21)
   at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
   at org.jboss.seam.Component.callComponentMethod(Component.java:2100)
   at org.jboss.seam.Component.callCreateMethod(Component.java:2015)
   at org.jboss.seam.Component.newInstance(Component.java:1976)
   ... 162 more
Caused by: org.hibernate.HibernateException: Wrong column type: temp_moyenne, expected: int8
   at org.hibernate.mapping.Table.validateColumns(Table.java:261)
   at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)
   at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
   ... 175 more


This is my table:

Code:
CREATE TABLE aire_protegee
(
  id serial NOT NULL,
  poi_id integer,
  cla_id integer NOT NULL,
  ind_id integer,
  nom_ap text,
  temp_moyenne integer,
  temp_max integer,
  temp_min integer,
  pluviom_moyenne integer,
  pluviom_max integer,
  pluviom_min integer,
  vent_vitesse_moyenne integer,
  vent_vitesse_max integer,
  vent_vitesse_min integer,
  rv_nord integer,
  rv_sud integer,
  rv_est integer,
  rv_ouest integer,
  rv_ne integer,
  rv_no integer,
  rv_se integer,
  rv_so integer,
  superficie double precision,
  CONSTRAINT pk_aire_protegee PRIMARY KEY (id),
  CONSTRAINT fk_aire_pro_aire_prot_classe_a FOREIGN KEY (cla_id)
      REFERENCES classe_ap (id) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT,
  CONSTRAINT fk_aire_pro_indicateu_indicate FOREIGN KEY (ind_id)
      REFERENCES indicateur_ap (id) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT,
  CONSTRAINT fk_aire_pro_point_obs_point_ob FOREIGN KEY (poi_id)
      REFERENCES point_observation (id) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT
)
WITHOUT OIDS;
ALTER TABLE aire_protegee OWNER TO "admin";


My persistance.xml file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
             
   <persistence-unit name="sigpn" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/sigpnDatasource</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
      </properties>
   </persistence-unit>
   
</persistence>


and finally, the declaration of my java class:
Code:
public class AireProtegee implements java.io.Serializable {

   private int id;
   private IndicateurAp indicateurAp;
   private PointObservation pointObservation;
   private ClasseAp classeAp;
   private String nomAp;
   private Long tempMoyenne;
   private Long tempMax;
   private Long tempMin;
   private Long pluviomMoyenne;
   private Long pluviomMax;
   private Long pluviomMin;
   private Long ventVitesseMoyenne;
   private Long ventVitesseMax;
   private Long ventVitesseMin;
   private Long rvNord;
   private Long rvSud;
   private Long rvEst;
   private Long rvOuest;
   private Long rvNe;
   private Long rvNo;
   private Long rvSe;
   private Long rvSo;
   private Double superficie;
        ......
        }

I really need your help!!!

Thx[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 3:48 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The error message really says it. In your database your columns are integer:s but in your java code you have Long:s. You have two options:

1. Change your database to use the bigint column type instead.
2. Change your code to use Integer:s instead.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 4:10 am 
Newbie

Joined: Tue Jan 13, 2009 11:23 am
Posts: 12
Hi nordborg ,
I tried to change the type in both database and java class by I get the same error,
Do you have an other idea,
thx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 4:16 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You should only change in one of the places, not both!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 4:23 am 
Newbie

Joined: Tue Jan 13, 2009 11:23 am
Posts: 12
I changed the first time in my database it doesn't work,
so I changed it in my class the second time and it doesn't work
I did the change in place not both


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 5:06 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Hmmm... maybe the PostgreSQL dialect is broken with respect to schema validation. According to the PostgreSQL documentation, bigint and int8 should be equivalent and so should integer, int and int4.

See http://www.postgresql.org/docs/8.1/stat ... TYPE-TABLE

I don't know if PostgreSQL remembers if you used one of the aliases when you created the table. If you change the column type to int8 does it still show up as bigint?

One possible solution would be to subclass the PostgreSQLDialect class used by Hibernate and override the type mapping done in the constructor.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 5:35 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 8:25 am
Posts: 46
Location: Saint Petersburg, Russian Federation
soussou126 wrote:
I changed the first time in my database it doesn't work,
so I changed it in my class the second time and it doesn't work
I did the change in place not both


I suggest you to autogenerate database table for the AireProtegee class via hibernate and check resulted column type. That may give you a clue about what type should be used.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 6:35 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I made a test against PostgreSQL 8.3.5 by creating columns with bigint and int8. Both column types are reported as bigint. I guess this is actually what is expected since the int8 is only an alias. I guess this means that the PostgreSQLDialect in Hibernate is broken since it registers int2, int4 and int8 as datatypes and not smallint, integer and bigint.

It may be that this is required by older PostgreSQL version so it may not be a good idea to change this in the PostgreSQLDialect class. In any case, it would be safe to create a subclass that registers the proper colum types. Eg something like this:

Code:
public class PostgreSQL8Dialect extends PostgreSQLDialect {
   public PostgreSQL8Dialect{
      super();
      registerColumnType( Types.BIGINT, "bigint" );
      registerColumnType( Types.INTEGER, "integer" );
      registerColumnType( Types.SMALLINT, "smallint" );
      registerColumnType( Types.TINYINT, "smallint" );
      // and maybe some more...
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 11:09 am 
Newbie

Joined: Tue Jan 13, 2009 11:23 am
Posts: 12
thx for your help,
I resolved the problem, I recreate my database with the type Bigint and all the class are mapped correctelly, and all work very fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 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.