[英]Entity with ID type String error
I'm having the following entity when i do the persist Im getting dump, I moving to the field string value(this is how the model defined there is ID type string with value such as (vacation,WORK_ACCIDENT...so i cant change it) and the error is 当我执行持久化操作时,我具有以下实体我正在转储,我移动到字段字符串值(这是模型定义的方式,ID类型字符串的值是(vacation,WORK_ACCIDENT ...所以我不能更改它),错误是
Invalid character string format for type INTEGER. INTEGER类型的字符串格式无效。
@Entity
public class LeaveReType {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private String id;
I having another entity with ID type string and when i move to it number the persistence working OK ,can i use some annotation for ID to ignore this restriction ? 我有另一个ID类型为string的实体,当我将其移至其编号时,持久性工作正常,我可以对ID使用一些注释来忽略此限制吗?
Exception in thread "main" javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLDataException: Invalid character string format for type INTEGER.
Error Code: 20000
Call: INSERT INTO LESTTYPE (ID, AVAILABLEBALANCE, ENTITLEMENT, NAME, PENDINGITEMS) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
Query: InsertObjectQuery(LESTTYPE [id=WORK_ACCIDENT, name=Work Accident, entitlement=n/a, availableBalance=n/a, pendingItems=0 pending items])
I also tried with and i getting the same error 我也尝试过,并且遇到相同的错误
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@TypeConverter(dataType = Long.class, name = "id")
private String id;
If you database type is NUMBER are you want your object type to be String you should use a Converter to convert the type. 如果您的数据库类型为NUMBER,则您希望对象类型为String,则应使用Converter来转换类型。
ie @TypeConverter(dataType=Long.class) 即@TypeConverter(dataType = Long.class)
But really, if you database type is NUMBER you should use a numeric type in Java. 但实际上,如果您的数据库类型为NUMBER,则应在Java中使用数字类型。 You could still have get/set method that take String if you wish.
如果愿意,您仍然可以使用采用String的get / set方法。 Also using @GeneratedValue on a String type is odd.
在String类型上也使用@GeneratedValue是奇数的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.