When generating tables in intellIj 2016.3, classes are created as follows:

@Entity @Table(name = "mir", schema = "ipm", catalog = "ipm") public class Mir { private long entityId; private Long fileseq; @Id @Column(name = "ENTITY_ID", nullable = false) public long getEntityId() { return entityId; } public void setEntityId(long entityId) { this.entityId = entityId; } @Basic @Column(name = "FILESEQ", nullable = true) public Long getFileseq() { return fileseq; } public void setFileseq(Long fileseq) { this.fileseq = fileseq; } } 

How do I get the tables to be generated like this:

 @Entity @Table(name = "mir", schema = "ipm", catalog = "ipm") public class Mir { @Id @Column(name = "ENTITY_ID", nullable = false) public long ENTITY_ID; @Basic @Column(name = "FILESEQ", nullable = true) public Long FILESEQ; } 

without getters and setters? (don't ask why)

Is it possible to do something like this? if not, can it be done so that the underscore in the column title is not removed? not getEntityId() , but getEntity_Id() at least?

  • The second option will work, just checked. Better what IDE you use to generate a get / set, since Intellij IDEA generates such a geth: long getENTITY_ID() - MrFylypenko
  • Try lombok - Artem Konovalov
  • The question about the spherical horse in a vacuum - very little information. 1. By doing public class fields, you break one of the principles of OOP, encapsulation. 2. By calling the getEntity_Id() methods, you are violating the Java convention ( oracle.com/technetwork/java/codeconventions-135099.html ). I am sure that there is a more elegant solution for your task. PS Not in JSON, by chance, mapite to entity_id ? :) - ruslanys
  • Getters and setters are needed to read and write the base. Without them, he will give an error that he cannot count from the base or write there - Chechil Crimea
  • one
    IDEA normally creates a gett / set, in accordance with the Java convention, and if there is an underscore in the field name of the object, then it will be in the gett / set. Most likely you will convert the data from JSON to a JAVA object, then use ready-made libraries for this (for example, FasterXML), for which a het / set is not a problem than using public fields. - MrFylypenko

2 answers 2

Try reading about the lombok library. It can generate code on the fly, all sorts of getters, setters, constructors, equals, hashcode.

You should get something like this:

 @Data @Entity @Table(name = "mir", schema = "ipm", catalog = "ipm") public class Mir { @Id @Column(name = "ENTITY_ID", nullable = false) private long ENTITY_ID; @Basic @Column(name = "FILESEQ", nullable = true) private Long FILESEQ; } 

You also need to enable support for this library in your IDE, a tick is set in the netbins in the project settings. In Idea, you need to download the plugin.

  • this is a cool thing when you write everything from scratch or when you automatically refactor, but! I have all the classes already generated, and the refactoring deletes all the annotations, there is no time for all classes, methods and fields to finish writing. - user214105
  1. By doing public class fields, you break one of the principles of OOP, encapsulation.
  2. Calling getEntity_Id() methods violates the Java convention ( http://www.oracle.com/technetwork/java/codeconventions-135099.html ).

Guava has everything you need to solve your problem "correctly":

CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "SomeInput");

Just translate the field name from one view to another.

  • Yes, I know all this, I am fine. No, not json, but I need to process json (and not only) data, where it would be easier to get the class field by name, as, for example, in json would come. so I did not ask why I did it. - user214105