I spent a lot of time reading answers from 5 years ago, not understanding how to do this (especially if you work in Intellij and not in Eclipse), and why this has not yet been decided. So, I found it here and it is simple:
In Intellij:
- Create an
orm.xml file in the same folder as your persistence.xml with this content
<?xml version="1.0" encoding="UTF-8"?> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="2.0"> <persistence-unit-metadata> <persistence-unit-defaults> <access>FIELD</access> </persistence-unit-defaults> </persistence-unit-metadata> </entity-mappings>
- Now you can generate your pojos (Create a persistence mapping → by database schema → select your tables, etc. and don't forget to check “Generate JPA annotations”)
Your objects will have field annotations!
@Entity @Table(name = "user", schema = "public", catalog = "my_db") public class User { @Id @Column(name = "id") private Integer id; ... }
kopelitsa May 03 '16 at 12:53 on 2016-05-03 12:53
source share