Announcement Announcement Module
Collapse
No announcement yet.
mapping error with postgres Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mapping error with postgres

    Hi,

    im using Hibernate 3/Spring 2 and Postgres 8.2

    Im trying to map an existig table with a column of char(10). Im working on it since yesterday morning, but i cant find the right mapping-configuration. I thought Hibernate would return a Character[] from a char(x>1), but it seams this was a mistake... Ive tried different datatypes but nothing worked, maybe the error lies somewhere else. hope you guys can help me out with this:

    Code:
    create table foobar(... birthdate character(10)...);
    Code:
    <property name="birthdate"
                              type="character"
                              >
                              <column name="birthdate" length="10"/> 
                              </property>
    Code:
    public Character[] getBirthdate() {
            return _birthdate;
        }
    
        public void setBirthdate(Character[] birthdate) {
            this._birthdate = birthdate;
        }
    Code:
    org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of dao.impl.HibernateUbAccountDAOImpl.birthdate
       at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
       at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
       at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
       at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3566)
       at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
       at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
       at org.hibernate.loader.Loader.doQuery(Loader.java:729)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
       at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
    ....
    Caused by: java.lang.IllegalArgumentException: argument type mismatch
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ....

  • #2
    String should work. Hibernate doesn't care about difference between char and varchar.

    Comment


    • #3
      I've thought so too, but it seems hibernate DOES make a difference.

      If i change the setter/getter in my java-file to string then there are 2 cases:
      - if i set the mapping in the xml to string too, i get a
      Code:
      Wrong column type: birthdate, expected: varchar(10)
      - if i set it to character (as before), i still get the
      Code:
      IllegalArgumentException occurred while calling setter of dao.impl.HibernateUbAccountDAOImpl.birthdate

      Comment


      • #4
        Where do you get the "Wrong column type" error?

        Comment


        • #5
          Here the code that causes the wrong column-type error:
          Code:
          <property name="birthdate"
                                    type="string"
                                    >
                                    <column name="birthdate" length="10"/>  
                                    </property>
          Code:
           
           public String getBirthdate() {
                  return _birthdate;
              }
          
              public void setBirthdate(String birthdate) {
                  this._birthdate = birthdate;
              }
          
          private String _birthdate;
          Stacktrace:
          Code:
          Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type: birthdate, expected: varchar(10)
          Caused by: org.hibernate.HibernateException: Wrong column type: birthdate, expected: varchar(10)
          	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.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:822)
          	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:748)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
          	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
          	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
          	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
          	at Main.main(Main.java:16)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:585)
          	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
          
          Process finished with exit code 1

          Comment


          • #6
            It seems you have schema validation turned on. It should work if you turn it off.

            Comment


            • #7
              I need new glasses... The char[] type is called "characters" not "character".

              Comment


              • #8
                I thougth "update" would make some changes in my schema.. It works indeed using update, but what would be an apropriate use-case for "validate" ?

                Comment


                • #9
                  Originally posted by dejanp View Post
                  I need new glasses... The char[] type is called "characters" not "character".
                  nope, doesnt work :
                  Code:
                  Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: characters, for columns: [org.hibernate.mapping.Column(birthdate)]
                  Caused by: org.hibernate.MappingException: Could not determine type for: characters, for columns: [org.hibernate.mapping.Column(birthdate)]
                  	at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
                  	at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
                  	at org.hibernate.mapping.Property.isValid(Property.java:185)
                  	at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
                  	at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
                  	at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
                  	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
                  	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:822)
                  	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:748)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
                  	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
                  	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
                  	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
                  	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
                  	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
                  	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
                  	at Main.main(Main.java:16)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                  	at java.lang.reflect.Method.invoke(Method.java:585)
                  	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
                  
                  Process finished with exit code 1

                  Comment


                  • #10
                    Which version of Hibernate exactly?

                    Comment


                    • #11
                      Also, try "char[]" as a type name.

                      Comment


                      • #12
                        Im using maven for depedency-handling. Here the configuration:
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate</artifactId>
                        <version>3.2.4.sp1</version>

                        Comment

                        Working...
                        X