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
9
votes
2 answers

Hibernate: unmapped class association exception

I know this should be a pretty elementary issue to fix, but 1) I'm relatively new to Hibernate, and 2) the fixes I've found don't (seem to) apply here. Here is the exception I am getting: org.hibernate.MappingException: An association from the table…
Magsol
  • 4,640
  • 11
  • 46
  • 68
9
votes
1 answer

How to enforce a validation constraint on an Embeddable entity property?

I have a Person entity with an Email collection property: @ElementCollection @CollectionTable(schema="u",name="emails",joinColumns=@JoinColumn(name="person_fk")) @AttributeOverrides({ …
ftkg
  • 1,652
  • 4
  • 21
  • 33
9
votes
3 answers

@ManyToOne and @BatchSize

I found in some old code strange thing (at least for me). The field which is annotated @ManyToOne is also annotated with @BatchSize. I always thought that @BatchSize annotation only affects when annotated at class level or on a collection…
9
votes
1 answer

Specify default value in Hibernate's XML configuration file

I'm configuring Hibernate via the mapping configuration file.
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
8
votes
6 answers

Hibernate association references unmapped class exception

I have the following class: public class Car implements Comparable{ private long idCar; private String model; private String immat; //Car License Plate private Company company; private Manufacturer manufacturer; private Calendar…
Dark Star1
  • 6,986
  • 16
  • 73
  • 121
8
votes
5 answers

IllegalArgumentException in class: ..., getter method of property: id

I have two classes Role and Privilege with the relation ManyToMany. When adding a Privilege to a Role, and then calling saveOrUpdate(role), I get the exception below. Here is the Role class: @Entity @Table(name = "ROLES") public class Role…
storm_buster
  • 7,362
  • 18
  • 53
  • 75
8
votes
2 answers

Create native SQL query without creating entity class in SpringBoot

The fundamental of ORM is mapping with the objects. But, for some reason, I don't want to create objects for running a query. Is there any way, in which without creating entities (managed classes), I can run a native SQL query?
Jitindra Fartiyal
  • 107
  • 1
  • 1
  • 5
8
votes
1 answer

Hibernate mapping for complex joins

I have legacy code that I am trying to map to the new code. OLD_PERSON pid sid name age NEW_PERSON pid sid fid age RESOLVE_PERSON pid fid status Java class domain.Person { ID _id; String _name; Integer _age; } In the legacy world, there was…
imgr8
  • 501
  • 4
  • 11
  • 25
8
votes
2 answers

Hibernate map enum by property value

I'm trying to do the following using Hibernate: When an object is saved to the DB, it is saved as a the value of the enum's name property. When an object is retrieved from the DB, the object reads in the string from the database, and instantiates…
teuber789
  • 1,527
  • 16
  • 28
8
votes
2 answers

How to use Space in column name with JPA and Hibernate

I have used in my java DAO class which contains Space in between LANG PREF @Column(name = "LANG PREF") private String langprefid; Once my java class runs, I am getting org.hibernate.exception.SQLGrammarException: Incorrect syntax near the…
user2563648
  • 87
  • 2
  • 4
8
votes
1 answer

Hibernate @Where annotation on a ManyToOne relation

I have recently started to refactor my project because I had to add an extra column to some of my table. The extra column is an Enum (Pending, or Active). Because of that change I would need now to refactor ALL my queries to only retrieves a row if…
Johny19
  • 5,364
  • 14
  • 61
  • 99
8
votes
1 answer

How to return an Enum using the addScalar() method with Hibernate

I have: @Column(name = "UserType", nullable = false) @Enumerated(EnumType.STRING) private UserType userType; How to return this field by SQL request using addScalar() method?
Dark Hydra
  • 265
  • 6
  • 21
8
votes
9 answers

How to add data of different records to a single record?

If do not have time please have a look at the example I have two types of users, temporary users and permanent users. Temporary users use the system as guest just provide their name and use it but system needs to track them. Permanent users are…
J888
  • 1,944
  • 8
  • 42
  • 76
8
votes
2 answers

How do you retrieve nested Sets?

Is there an annotation I'm missing or is this a limitation to hibernate retrieval? Entities: class A { Long id; Set b; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"),…
stackoverflow
  • 18,348
  • 50
  • 129
  • 196
8
votes
4 answers

Why do I need the third table for many to many mapping ? Why can't I just use two tables?

I have been trying many to many relationship between two classes Person and Address. I don't know but somewhere I am not thinking along the correct lines. For example for many to many mapping, I made two tables CREATE TABLE person(p_id…
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328