Faced a problem when creating classes from a database. When generating, if you check the client_id field and the one-to-many connection for this type field, then a code of the following type is generated:

@Basic @Column(name = "client_id", nullable = false) public int getClientId() { return clientId; } public void setClientId(int clientId) { this.clientId = clientId; } @ManyToOne @JoinColumn(name = "client_id", referencedColumnName = "id", nullable = false) public ClientEntity getClientByClientId() { return clientByClientId; } public void setClientByClientId(ClientEntity clientByClientId) { this.clientByClientId = clientByClientId; } 

This causes a failedorg.hibernate.MappingException: Repeated column in mapping for entity: com.tr1nksgroup.model.data.entities.ReturnEntity column: client_id (should be mapped with insert="false" update="false") error failedorg.hibernate.MappingException: Repeated column in mapping for entity: com.tr1nksgroup.model.data.entities.ReturnEntity column: client_id (should be mapped with insert="false" update="false") What actually logical and correct. But I need to have a setter id number and a setter entity. Is it possible?

  • ORM does not work that way, in ORM you work not with aids, but with entities. - etki
  • I agree, but at a certain stage I just need to set the id with a number so as not to drag out a bulky essence. There is no possibility at all? - Tr1nks
  • one
    Because the same field is displayed twice and both times on the record. clientId needs to be done only on reading @Column(name = "client_id", insertable=false, updatable=false) - Sergey
  • @Sergey Thanks, that works. And these parameters will not change the regular addition of the essence? After all, insertable=false says that the column is not included in the INSERT which is generated by the provider - Tr1nks
  • one
    It will be possible to install only through the second clientByClientId mapping. By the way, in order not to pull a large entity, you can try to get an instance of ClientEntity using an EntityManager.getReference . Such an instance will be loaded in a lazy way. - Sergey

0