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

org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: USERS, for columns: [org.hibernate.mapping.Column(invoices)]

If I remember correctly, Hibernate doesn’t let you mix and match annotation in conjunction with field / getter. If your @Id annotation is set over a field, all your mappings should follow fields. Try moving @OneToMany @JoinColumn(name=”INVOICE_ID”, nullable=false) from getInvoices() to private Set<Invoice> invoices; This pattern should be applied to your Invoice class as well

Can a @ManyToOne JPA relation be null?

The @ManyToOne associations are optional by default, so you don’t need to set anything if you want them to be nullable. However, because you set the optional=false attribute, you made it mandatory. So instead of: @ManyToOne(optional = false, fetch = FetchType.LAZY) Set it like this: @ManyToOne(fetch = FetchType.LAZY) The optional is true by default. On … Read more

Hibernate : No CurrentSessionContext configured

As per the best of my knowledge, your configuration is not proper for current session. Instead of <property name=”hibernate.current_session_context_class”>org.hibernate.context.ThreadLocal‌​SessionContext</property> use <property name=”hibernate.current_session_context_class”>thread</property> For more information on this, please visit this link: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/architecture.html#architecture-current-session Specially, read the last lines of last paragraph. For those who’re using Hibernate 4.1, <property name=”hibernate.current_session_context_class”>org.hibernate.context.internal.ThreadLocalSessionContext</property> Reference: https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/context/internal/ThreadLocalSessionContext.html

When Should I Use @JoinColumn or @JoinTable with JPA?

Let’s say you have an entity A which has a @ManyToOne association ot an entity B @JoinColumn will define the target table Foreign Key (e.g B_ID) while using the target Entity table (e.g. B). @Entity public class A { private Long id; @ManyToOne @JoinColumn(name=”B_ID”) private B b; } @JoinTable will use a separate table to … Read more

AnnotationException: A Foreign key refering has the wrong number of column. should be 2

Your class CiudadPK has two columns in it. You’re only using @JoinColumn which is limited to a single column. You need to use @JoinColumns and list out both columns in the FK, e.g. // bi-directional many-to-one association to Provincia @ManyToOne(fetch=FetchType.LAZY) @JoinColumns({ @JoinColumn(name = “codProvincia”, insertable = false, updatable = false), @JoinColumn(name = “codRegion”, insertable = … Read more

Is it possible to limit the size of a @OneToMany collection with Hibernate or JPA Annotations?

That’s not possible. Hibernate has two options for you: you load the children collection upon fetching the parent entity you load the children collection lazily on first access There’s no middle ground. That’s because Hibernate needs to manage the whole collection entity state transitions. If you were able to load subsets then a unidirectional bag … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)