简体   繁体   English

使用Hibernate读取未映射的字段吗?

[英]Read not mapped fields with Hibernate?

Suppose database table Customer which is mapped to class Customer has more fields, then described in annotations. 假设映射到类Customer数据库表Customer具有更多字段,然后在注释中进行描述。

Is it possible to read any of such not mapped fields? 是否可以读取任何此类未映射的字段?

If you dont want to map them to your Customer. 如果您不想将它们映射到您的客户。 You can create a second Customer object like SpecialCustomer where you can map whatever you want that is not mapped in the Customer. 您可以创建第二个Customer对象,例如SpecialCustomer,在其中可以映射未​​在Customer中映射的任何所需对象。 If you have some field that distinguishes in between the two types of customer you can use @DiscriminatorColumn and value in addition. 如果您有一些字段可以区分两种类型的客户,则可以另外使用@DiscriminatorColumn和value。

Read the Hibernate Inheritance strategies. 阅读Hibernate继承策略。 https://docs.jboss.org/hibernate/orm/3.5/reference/en/html/inheritance.html https://docs.jboss.org/hibernate/orm/3.5/reference/zh/html/inheritance.html

Alternatively if you real really really dont want to map any extra classes and fields you have the option to use a NativeSQL query and Map the results to some structure of your choice. 或者,如果您确实真的不想映射任何其他类和字段,则可以选择使用NativeSQL查询并将结果映射到您选择的某个结构。

http://www.thoughts-on-java.org/result-set-mapping-basics/ http://www.thoughts-on-java.org/result-set-mapping-basics/

If I was in your place I would go for the SpecialCustomer approach. 如果我在您的位置,我会选择SpecialCustomer方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM