[英]mapping Field with variable type using Hibernate Annotaion
how can I have a field with variable type in my class? 我班上怎么有一个变量类型的字段? I use hibernate annotation for mapping to DB.
我使用休眠注释来映射到数据库。 I tried to use java.io.Serializable as field's type, but it mapped to database as a 01 amount which is true if I get it's object and cast it to it's true type.
我尝试使用java.io.Serializable作为字段的类型,但它以01的数量映射到数据库,如果我得到它的对象并将其转换为它的真实类型,则为true。 but I need to run a query on this objects that needs true amount of field.(right now I can't compare an integer field with a number) Does anyone have any idea how can I do this?
但是我需要在需要真实字段数量的对象上运行查询。(现在我不能将整数字段与数字进行比较)有人知道如何执行此操作吗?
Thanks in advance. 提前致谢。
You can't have variable types in Java - it is statically typed language. 您不能在Java中使用变量类型-它是静态类型的语言。
I guess you can achieve something like this with groovy (+ grails ), which is dynamically typed . 我猜您可以使用动态输入的 groovy (+ grails )实现类似的功能。 Using something like
def someField
you can later use someField
as whatever you expect it to be. 使用类似
def someField
类的东西,您以后可以将someField
用作您希望的样子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.