Questions tagged [hibernate-mapping]

Hibernate uses mapping metadata to find out how to load and store objects of the persistent class. The Hibernate mapping could be specified using configuration files or annotations.

Hibernate uses mapping metadata to find out how to load and store objects of the persistent class. The Hibernate mapping could be specified using configuration files or annotations.

This tag should be used for questions regarding issues with the definition of Hibernate mappings.

3217 questions
356
votes
33 answers

Hibernate - A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

I'm having the following issue when trying to update my entity: "A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance". I have a parent entity and it has a Set<...> of some children entities. When I…
axcdnt
  • 14,004
  • 7
  • 26
  • 31
214
votes
7 answers

Can someone explain mappedBy in JPA and Hibernate?

I am new to hibernate and need to use one-to-many and many-to-one relations. It is a bi-directional relationship in my objects, so that I can traverse from either direction. mappedBy is the recommended way to go about it, however, I couldn't…
brainydexter
  • 19,826
  • 28
  • 77
  • 115
191
votes
5 answers

In which case do you use the JPA @JoinTable annotation?

In which case do you use the JPA @JoinTable annotation?
kostas trichas
  • 2,923
  • 7
  • 28
  • 37
132
votes
3 answers

How to map calculated properties with JPA and Hibernate

My Java bean has a childCount property. This property is not mapped to a database column. Instead, it should be calculated by the database with a COUNT() function operating on the join of my Java bean and its children. It would be even better if…
Francois
  • 2,289
  • 4
  • 20
  • 21
86
votes
11 answers

Hibernate table not mapped error in HQL query

I have a web application that use Hibernate to make CRUD operations over a database. I got an error saying that the table is not mapped. See the Java files: Error message: org.springframework.orm.hibernate3.HibernateQueryException: Books is not…
Pascut
  • 3,291
  • 6
  • 36
  • 64
85
votes
3 answers

How can I mark a foreign key constraint using Hibernate annotations?

I am trying to use Hibernate annotation for writing a model class for my database tables. I have two tables, each having a primary key User and Question. @Entity @Table(name="USER") public class User { @Id @Column(name="user_id") …
vikiiii
  • 9,246
  • 9
  • 49
  • 68
54
votes
2 answers

How can I map "insert='false' update='false'" on a composite-id key-property which is also used in a one-to-many FK?

I am working on a legacy code base with an existing DB schema. The existing code uses SQL and PL/SQL to execute queries on the DB. We have been tasked with making a small part of the project database-engine agnostic (at first, change everything…
Jesse Webb
  • 43,135
  • 27
  • 106
  • 143
54
votes
1 answer

What does the Hibernate proxy object contain?

All I could gather from Google is that: Hibernate uses a proxy object to implement lazy loading. When we request to load the Object from the database, and the fetched Object has a reference to another concrete object, Hibernate returns a proxy…
vineeshchauhan
  • 765
  • 2
  • 7
  • 14
53
votes
3 answers

Unique Constraint Over Multiple Columns

I am using SEAM 2/Hibernate along with PostgreSQL 9 database. I have the following table Active Band =========== active_band_id serial active_band_user text active_band_date timestamp active_band_process integer I would like to add a constraint…
DaveB
  • 2,953
  • 7
  • 38
  • 60
45
votes
5 answers

Hibernate mapping between PostgreSQL enum and Java enum

Background Spring 3.x, JPA 2.0, Hibernate 4.x, Postgresql 9.x. Working on a Hibernate mapped class with an enum property that I want to map to a Postgresql enum. Problem Querying with a where clause on the enum column throws an…
Kenny Linsky
  • 1,726
  • 3
  • 17
  • 41
43
votes
5 answers

“Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements”

Good morning Stackoverflow, I have the problem that it gives me the error: Failed to create sessionFactory object.org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: …
mh123hack
  • 433
  • 1
  • 4
  • 5
42
votes
5 answers

how to return Map with HQL

i have a table Permission: id name desc what i am doing right now is to make a query that returns a permission object then put the values in the map programmatically 1- But i was wondering if it's possible to make an HQL (or native sql if not…
fresh_dev
  • 6,694
  • 23
  • 67
  • 95
40
votes
2 answers

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

If I have the following mapped collection in a POJO using JPA/Hibernate Annotations: @OneToMany(mappedBy = "columnName", fetch = FetchType.LAZY) @OrderBy("aField") @MapKeyJoinColumn(name = "id_fk") @LazyCollection(value =…
rodrigobartels
  • 821
  • 1
  • 9
  • 13
38
votes
2 answers

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

I am mapping my classes with the tables of my database, but when running a test, I get the following error: Caused by: org.hibernate.AnnotationException: A Foreign key refering com.modulos.pvs.acceso.datos.entity.Provincia from…
Elias Vargas
  • 1,126
  • 1
  • 18
  • 32
36
votes
3 answers

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

@JoinColumn gives an Entity a foreign key to another Entity whereas @JoinTable will list the relationship between all relationships between Entity A and Entity B. As far as I can tell, they both appear to do similar things. When should I use one or…
Sarah Szabo
  • 10,345
  • 9
  • 37
  • 60
1
2 3
99 100