我正在基于 MySQL 数据库中的现有表创建 Java Persistence Entity Bean(使用 NetBeans IDE 8.0.1)。我在此表中遇到了一个类型为"Unsigned TINYINT(3)"的字段。我发现可以执行以下操作来将列的类型定义为 unsigned int:
private long foo;
@Column(columnDefinition = "UNSIGNED INT(11)")
public long getFoo()
{
return foo;
}
重现问题的步骤:
我正在尝试按如下方式创建一个字段:
@Size(max = 3)
@Column(name = "WorkingHours", columnDefinition="UNSIGNED TINYINT(3) default '40'")
private Integer workingHours;
问题:
将项目部署到服务器时收到以下错误:
{"JBAS014671: Failed services" => {"jboss.persistenceunit.\"my-project.ear/my-project-ejb.jar#old-db\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"my-project.ear/my-project-ejb.jar#old-db\": javax.persistence.PersistenceException: Unable to execute JPA schema generation create command [create table ... etc.]
Caused by: javax.persistence.PersistenceException: Unable to execute JPA schema generation create command [create table ... etc.]
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNSIGNED TINYINT(3), ... etc.' at line 1"}}
但是,如果我从我的(因此行变为)中删除“未签名” ,我的项目部署成功。因此,似乎无法识别“UNSIGNED” 。columnDefinition
columnDefinition="TINYINT(3) default '40'"
所以我的问题是:如何将我的列(字段)定义为无符号 TINYINT?
更多细节:
我不确定它是否重要,但我的persistence.xml文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="old-db" transaction-type="JTA">
<jta-data-source>java:/jboss/datasources/mySQL_pool_old</jta-data-source>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>