gpt4 book ai didi

mysql - 如何使用 JPA/Hibernate 注释将 MySQL char(n) 列映射到实例变量?

转载 作者:IT老高 更新时间:2023-10-28 23:54:50 26 4
gpt4 key购买 nike

我在类型为 char(7) 的 MySQL 表中的“语言”列上遇到 JPA/Hibernate 映射问题。在我的实体中,为该字段生成的代码是:

    private String language;

这会在运行时导致以下异常:

        ... 43 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: prosvetaPersistenceUnit] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:911)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 58 more
Caused by: org.hibernate.HibernateException: Wrong column type in joo16_dev.jos_categories for column language. Found: char, expected: varchar(255)
at org.hibernate.mapping.Table.validateColumns(Table.java:283)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1313)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:378)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
... 63 more

提前致谢!

日本

最佳答案

试试这个:

@Column(name="language",columnDefinition="char(7)")

看看是否可行。

关于mysql - 如何使用 JPA/Hibernate 注释将 MySQL char(n) 列映射到实例变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6207788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com