JPA Map mapping

Although answer given by Subhendu Mahanta is correct. But @CollectionOfElements is deprecated. You can use @ElementCollection instead: @ElementCollection @JoinTable(name=”ATTRIBUTE_VALUE_RANGE”, joinColumns=@JoinColumn(name=”ID”)) @MapKeyColumn (name=”RANGE_ID”) @Column(name=”VALUE”) private Map<String, String> attributeValueRange = new HashMap<String, String>(); There is no need to create a separate Entity class for the Map field. It will be done automatically.

Hibernate use of PostgreSQL sequence does not affect sequence table

I had the same problem. It is related to the id allocating strategies of Hibernate. Whe n you choose GenerationType.SEQUENCE, Hibernate uses HiLo strategy which allocates IDs in blocks of 50 by default. So you can explicitly set allocationSize value like this: @Id @SequenceGenerator(name=”pk_sequence”,sequenceName=”entity_id_seq”, allocationSize=1) @GeneratedValue(strategy=GenerationType.SEQUENCE,generator=”pk_sequence”) @Column(name=”id”, unique=true, nullable=false) public int getId() { return this.id; … Read more

@Id @GeneratedValue but set own ID value

It may be an overkill but have you thought about writing your own CustomIDGenerator which probably subclasses say the AutoGenerator of hibernate and exposes a couple of methods where you can set the id of the next class object to be generated so for example class MyGenerator extends …. { public void setIdForObject(Class clazz, Long … Read more

Change database schema during runtime based on logged in user

Assumptions Because I don’t have the reputation yet to post a comment below your question, my answer is based on the following assumptions: The current schema name to be used for the current user is accessible through a Spring JSR-330 Provider like private javax.inject.Provider<User> user; String schema = user.get().getSchema();. This is ideally a ThreadLocal-based proxy. … Read more

HQL Hibernate INNER JOIN

Joins can only be used when there is an association between entities. Your Employee entity should not have a field named id_team, of type int, mapped to a column. It should have a ManyToOne association with the Team entity, mapped as a JoinColumn: @ManyToOne @JoinColumn(name=”ID_TEAM”) private Team team; Then, the following query will work flawlessly: … Read more