Hibernate - moving annotations from property (method) level to field level

后端 未结 3 1824
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 21:50

How do I generate hibernate domain classes from tables with annotations at field level? I used Hibernate Tools project and generated domain classes from the tables in the da

3条回答
  •  感动是毒
    2020-12-13 22:03

    I spent a lot of time reading answers from 5+ years ago without understanding how to do it (especially if you work in Intellij and not Eclipse) and how come this is not already solved. So i found it, here it is, and it is simple:

    In Intellij:

    1. Create a file orm.xml in the same folder as your persistence.xml with this content
    
        
            
                
                    FIELD
                
            
        
    
    1. Now you can generate your pojos (Generate persistence mapping -> By database schema -> choose your tables etc and don't forget to tick the "Generate JPA Annotations")

    Your entities will have field annotations!

    @Entity
    @Table(name = "user", schema = "public", catalog = "my_db")
    public class User {
        @Id
        @Column(name = "id")
        private Integer id;
    ...
    }
    

提交回复
热议问题