3

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'")、プロジェクトの展開は成功します。なので「UNSIGNED」は認識されていないようです。

私の質問は次のとおりです。列 (フィールド) を署名なしの 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>
4

1 に答える 1