gpt4 book ai didi

Spring 和 Hibernate,找到位,预期为 TINYINT(1) DEFAULT 0

转载 作者:行者123 更新时间:2023-12-02 03:46:14 24 4
gpt4 key购买 nike

在数据库中:有一个字段的类型是TINYINT(1),默认值为0。在Model中它被定义为TINYINT(1) DEFAULT 0。但是它给出了如下错误:

错误

[jar:file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/NetaCommerceFrameworkAdmin/WEB-INF/lib/NetaCommerceFramework-0.0.1-SNAPSHOT.jar!/com/netasoft/commerce/framework/lang/dao/LangDaoImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type 
[org.hibernate.SessionFactory]: :Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/admin-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type in kaft.nc_alert_log for column alerted. Found: bit, expected: TINYINT(1) DEFAULT 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/admin-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type in kaft.nc_alert_log for column alerted. Found: bit, expected: TINYINT(1) DEFAULT 0

模型定义

@Column(name="alerted", columnDefinition = "TINYINT(1) DEFAULT 0")
private int alerted;

public int getAlerted() {
return alerted;
}

public void setAlerted(int alerted) {
this.alerted = alerted;
}

数据库属性

hibernate.hbm2ddl.auto=validate
#hibernate.hbm2ddl.auto=create-drop
hibernate.hbm2ddl.import_files=/import_standard.sql
hibernate.show_sql=false
hibernate.format_sql=true
hibernate.generate_statistics=false
hibernate.use_sql_comments=true
hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
hibernate.cache.use_second_level_cache=true
#-------------------------------------------------------------------------------
# MySQL Settings

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/xxx?autoReconnect=true
jdbc.username=xxx
jdbc.password=xxx

# Property that determines which Hibernate dialect / MySQL5Dialect || MySQLDialect
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

方言版本:

2013-01-17 08:45:36,920 INFO [org.hibernate.cfg.SettingsFactory] - Database ->
name : MySQL
version : 5.0.96-community-nt
major : 5
minor : 0
2013-01-17 08:45:36,921 INFO [org.hibernate.cfg.SettingsFactory] - Driver ->
name : MySQL-AB JDBC Driver
version : mysql-connector-java-5.1.12 ( Revision: ${bzr.revision-id} )
major : 5
minor : 1

它也在服务器和另一台计算机上运行。但是,在我的计算机和只是为了尝试而安装的新计算机中,它给出了相同的错误。我在谷歌上搜索了几天,无法弄清楚是什么原因导致了这个问题。尝试在模型中使用 boolean columnDefinition 并更改 MySqlDialect 定义,但没有任何变化。甚至错误消息都是一样的。

最佳答案

使用 BIT 作为列定义

这对我有用:

@Column(name = "my_field",columnDefinition = "BIT")
private int myField;

关于Spring 和 Hibernate,找到位,预期为 TINYINT(1) DEFAULT 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14381749/

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