如何找出JPA @Entity中列的长度? [英] How can I find out the length of a column in a JPA @Entity?

查看:416
本文介绍了如何找出JPA @Entity中列的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个String列定义为

I've got a String column defined with

@Column(length = 4000)

该属性包含日志信息,可能长于定义的长度。在这种情况下,可以安全地截断该字段而不抛出错误消息。

The attribute contains log information and can be longer than the defined length. In this case, the field can be safely truncated without throwing an error message.

我想找出DAO类中确定的列长度pojo,以便我可以在必要时截断字符串。我怎么能这样做?

I'd like to find out the determined length of the column in the DAO class for the pojo so that I can truncate the string if necessary. How can I do that?

问候,

Chris

推荐答案

查看EJB的回答这个问题;

Check out EJB's answer to this question;


如何在表单,验证和ddl中重用字段长度?

要解释,如果你想要人员表中firstName列的长度,你可以使用这段代码。

To paraphrase, if you wanted the length from the firstName column in the person table, you use this code.

person.getClass().getDeclaredField("firstName").getAnnotation(Column.class).length()

这篇关于如何找出JPA @Entity中列的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆