readthefuckingmanual.net

[SOLVED] org.hibernate.MappingException: property mapping has wrong number of columns:

Error added: 2008-02-26T09:40:24Z

4 people waiting for the answer...

8 answers found.

Answer 2479 (100.0% helpful)

Argh. I just noticed why I was seeing this error. In my implementation of UserType, I had mistyped:

    @Override
    public int[] sqlTypes() {
        return new int[]{Types.INTEGER};
    }

as ...

    @Override
    public int[] sqlTypes() {
        return new int[Types.INTEGER];
    }

Of course it compiled, but was ultimately wrong...
Permalink

Answer 969 (70.0% helpful)

A clue: if a persistent property on an entity is declared as java.lang.Object, it throws this error, but change it to java.io.Serializable (or something that implements it), and it doesn\'t complain.
Permalink

Answer 1165 (62.5% helpful)

Be sure that your custom type class (the one implementing UserType) returns an array of length n from sqlTypes(), where n is the number of columns that the property maps. I\'m guessing the property is only mapped to only one column.

Note that sqlTypes() returns an array of types that MUST be used, not the different types that CAN be used. So if sqlTypes() returns an array of length 3, hibernate will assume you must have three columns mapped to the custom type.
Permalink

Answer 1385 (50.0% helpful)

If using a CompositeUserType for a property, the property\'s getter method must be annotated with the @Columns annotation and the composite user type class\' getPropertyTypes() method must return an array of the exact same size as the number of @Column annotations specified in your @Columns annotation

(Hibernate 3.5.1 + Java)
Permalink

Answer 1312 (40.0% helpful)

If the column mapped in the database is of type CLOB or BLOB just put the @Lob annotation in hibernate mapping.
Permalink

Answer 1678 (40.0% helpful)

Check that your @TypeDef annotation is correct.  Ensure that "typeClass" is the type descriptor class and that "defaultForType" is the object instance class.
Permalink

Answer 1949 (33.333332% helpful)

In Grails this might also happen with CompositeUserType if the

static embedded = ['nameOfCompositeAttribute']

isn't specified
Permalink

Answer 1542 (20.0% helpful)

No one works to me !
Permalink

Add an answer/solution

If you know the answer, please add your own solution below.
If you don't know, but find out later, please come back and share your answer - there will be other people struggling with this too.


Please enter 61948 here

If you want to be notified via email when this is solved, enter your email address here: