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
23
votes
3 answers

Delete child from parent and parent from child automatically with JPA annotations

Suppose that we have 3 Entities object class: class Parent { String name; List children; } class Child { String name; Parent parent; } class Toy { String name; Child child; } How can I use JPA2.x (or hibernate)…
user1079877
  • 9,008
  • 4
  • 43
  • 54
22
votes
4 answers

Hibernate map enum to varchar

Suppose I have this enum: public enum TestEnum { EXAMPLE, FURTHER_EXAMPLE, LAST_EXAMPLE } With this mapping in the .hbm:
ipavlic
  • 4,906
  • 10
  • 40
  • 77
22
votes
7 answers

Postgresql UUID supported by Hibernate?

I can't get Hibernate working with java.util.UUID for PostgreSQL. Here is the mapping using javax.persistence.* annotations: private UUID itemUuid; @Column(name="item_uuid",columnDefinition="uuid NOT NULL") public UUID getItemUuid() { return…
forker
  • 2,609
  • 4
  • 23
  • 24
22
votes
4 answers

Why does JPA use FetchType EAGER by default for the @ManyToOne relationship

I came to notice that the default FetchType for the @ManyToOne mapping is EAGER in JPA and Hibernate, whereas for the @OneToMany mapping, the default FetchType is LAZY. What is the specific reason behind this?
vatsal mevada
  • 5,148
  • 7
  • 39
  • 68
22
votes
7 answers

org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags

Following is my code Here I am using multiple lists to fetch data from database. On fetching data from hql query it is showing exception. Pojo Class public class BillDetails implements java.io.Serializable { private Long billNo; // other…
xrcwrn
  • 5,339
  • 17
  • 68
  • 129
21
votes
2 answers

javax.persistence Annotations on field, getter or setter?

I am currently learning Hibernate and the Java Persistence API. I have an @Entity class, and need to apply annotations to the various fields. I have included in the code below all three places where they could go. Should I apply them to the field…
James McGuigan
  • 7,542
  • 4
  • 26
  • 29
21
votes
3 answers

How can I prevent Hibernate from updating NULL values

Is there a setting in hibernate to ignore null values of properties when saving a hibernate object? NOTE In my case I am de-serializing JSON to a Hibernate Pojo via Jackson. The JSON only contains some of the fields of the Pojo. If I save the Pojo…
Jeremy S.
  • 6,423
  • 13
  • 48
  • 67
21
votes
6 answers

How to have a relationship based on a non-key field?

I have two entities as following, when I try to add items to my car table it shows following error message;therefore, it does not allow me to have more than one car with 'Auto' transmission. Error: #1062 - Duplicate entry 'Auto' for key…
Daniel Newtown
  • 2,873
  • 8
  • 30
  • 64
20
votes
5 answers

Bug in Spring Data JPA: Spring Data returns List instead of List

I have DAO implementation over spring-data: public interface TestDataRepository extends CrudRepository { @Query(value = "select distinct(oid) from unit", nativeQuery = true) List testMethod(); } And unit test to test…
Oleksandr_DJ
  • 1,454
  • 2
  • 14
  • 26
19
votes
5 answers

Hibernate SQL Query result Mapping/Convert TO Object/Class/Bean

1 2: select (table.*)/(all column) is OK String sql = "select t_student.* from t_student"; //String sql = "select t_student.id,t_student.name,... from t_student"; //select all column SQLQuery query =…
YETI
  • 928
  • 3
  • 12
  • 24
19
votes
2 answers

How to load only ids from Many to Many mapping tables?

In a Many to Many relation between two table with a Mapping table in between, how can I only load ids for the second entity. Following is the example to explain what I want to achieve here. Below is a sample schema create table user( id int…
Salman A. Kagzi
  • 3,833
  • 13
  • 45
  • 64
19
votes
3 answers

Doesn't work setting default value of property in Hibernate

I have a boolean property in my entity. Here's my annotations for it: @Column(name = "IS_ACTIVE", nullable = false, columnDefinition="BIT DEFAULT 1", length = 1) public Boolean getActive() { return isActive; } But columnDefinition="BIT DEFAULT…
19
votes
1 answer

How Do I Create Many to Many Hibernate Mapping for Additional Property from the Join Table?

I need a many to many hibernate mapping needed 3 joins. I've tried to find out a solution without intermediate entity like LecturerCourse. I have a many to many relation in my database between my lecturer and course tables. A course can be given by…
erencan
  • 3,725
  • 5
  • 32
  • 50
18
votes
7 answers

How should I register custom Hibernate 5 data type (BasicType) when Spring Data is used?

I use Spring Data and decided that I want to create new custom data type that can be used in Hibernate entities. I checked the documentation and choose BasicType and implemented it according to this official user guide. I wanted to be able to…
xMort
  • 1,545
  • 3
  • 11
  • 20
18
votes
3 answers

Proper Hibernate id generator for postgres serial/bigserial column?

My PostgreSQL tables have id's of type bigserial, meaning they are generated at the time rows are inserted (and thus, the id column's value is not supplied in the INSERT statement). I'm having difficulty finding the proper value for the
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218