1

我正在尝试将我的项目从休眠 3.6 升级到 4.1.6,我想我已经把所有的罐子都放在了正确的位置,等等,但现在我在谷歌搜索下面有这个异常没有得到答案。我的代码在 Hibernate 3.6 上运行良好,我不确定这是我的映射问题还是其他问题。我正在使用 JPA 方法使用 Spring 3.1.2 配置休眠 4.1。

Caused by: org.hibernate.MappingException: Could not create DynamicParameterizedType for type: org.hibernate.type.EnumType
        at org.hibernate.mapping.SimpleValue.createParameterImpl(SimpleValue.java:398)
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:304)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:294)
        at org.hibernate.mapping.Property.isValid(Property.java:238)
        at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:469)
        at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
        at org.hibernate.cfg.Configuration.validate(Configuration.java:1294)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1738)
        at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
        ... 55 more
    Caused by: java.lang.ClassNotFoundException: char
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)
        at org.hibernate.mapping.SimpleValue.createParameterImpl(SimpleValue.java:389)
        ... 64 more

更新:我在休眠代码中设置了断点,该异常被捕获并找到了它不喜欢的映射,下面是它。

@Entity
@Table(name = "company_addresses")
public class CompanyAddress extends TimeStampedPersistableObject
{
public enum AddressType
{
    PUBLIC('p'), SHAREHOLDER('s');

    private final char typeCode;

    AddressType(char typeCode)
    {
        this.typeCode = typeCode;
    }

    public static AddressType parse(char c)
    {
        for (AddressType addressType : AddressType.values())
        {
            if (addressType.value() == c)
            {
                return addressType;
            }
        }
        return null;
    }

    public char value()
    {
        return typeCode;
    }
}

@Column(name = "address_type")
@Enumerated(EnumType.STRING)
private char type;
4

1 回答 1

1

事实证明,我有一个额外的 @Enumerated 被休眠 3.6 忽略,这让休眠 4.1 感到困惑

@Column(name = "address_type")
@Enumerated(EnumType.STRING)
private char type;

I had forgotten @Enumerated on this field which has a char type but the setters and getter using a proper Enum. Removing @Enumerated fixed the problem, which was a bug in my mapping.

Hibernate 4.1 failed to indicated the name of the table and the name of the column which made it a bit hard to figure out which mapping was causing the problem.

于 2012-08-29T18:27:38.167 回答