JPA: How do I specify the table name corresponding to a class at runtime?

前端 未结 5 2273
执笔经年
执笔经年 2020-12-01 05:11

(note: I\'m quite familiar with Java, but not with Hibernate or JPA - yet :) )

I want to write an application which talks to a DB2/400 database through JPA and I ha

5条回答
  •  [愿得一人]
    2020-12-01 05:14

    It sounds to me like what you're after is Overriding the JPA Annotations with an ORM.xml.

    This will allow you to specify the Annotations but then override them only where they change. I've done the same to override the schema in the @Table annotation as it changes between my environments.

    Using this approach you can also override the table name on individual entities.

    [Updating this answer as it's not well documented and someone else may find it useful]

    Here's my orm.xml file (note that I am only overriding the schema and leaving the other JPA & Hibernate annotations alone, however changing the table here is totally possible. Also note that I am annotating on the field not the Getter)

    
    
        models.jpa.eglobal
        
            
            

    提交回复
    热议问题