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
35
votes
7 answers

Hibernate : No CurrentSessionContext configured

I'm stuck due to some silly mistake somewhere but not able to figure out ! Hibernate 4.2.6 I have referred to this question, asked several times previously, for example here hibernate.cfg.xml
Kaliyug Antagonist
  • 3,512
  • 9
  • 51
  • 103
34
votes
3 answers

JPA enumerated types mapping. Best approach

As usual Java enum types have corresponding codes and name description. And Java classes that contain such fields, contain them as Enum: public enum MyEnum{ SOMEINSTANCE(1, "test1"), SOMEINSTANCE(2, "test2"); private final int code; …
Alexandr
  • 9,213
  • 12
  • 62
  • 102
32
votes
3 answers

Can a @ManyToOne JPA relation be null?

I have a table that has foreign key of another table (many to one relationship) but i want it to be nullable. Something like this: public class SubType() { @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name =…
Narges
  • 1,345
  • 6
  • 14
  • 29
32
votes
1 answer

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

I have a problem that Hibernate is unable to determine the type for Set at the table USERS. I am trying to create a foreign key of table INVOICES through one-to-many relationship. One User can generate many Invoices. My User.java is given below.…
31
votes
6 answers

org.hibernate.MappingException: Unable to find column with logical name

hi my tables are as follows: 1- medical_company: medical_company_id foreign key on account_entity table account_entity_id column (not a pk) column1 column2 column3 2- account_entity: account_entity_id (pk) column1 column2 column3 3-…
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
31
votes
4 answers

Hibernate use of PostgreSQL sequence does not affect sequence table

I've configured Hibernate to use PostgreSQL sequence (via annotations) to generate values for primary key id column as follows: @Id…
forker
  • 2,609
  • 4
  • 23
  • 24
30
votes
1 answer

How to join tables on non Primary Key using JPA and Hibernate

I have 3 models User, House, UserHouseMap. And I need to access a user's house through the map. Only problem is this is an old DB & I can't change the fact that I need to map User to UserHouseMap using user.name, which is a non primary…
user2158382
  • 4,430
  • 12
  • 55
  • 97
30
votes
2 answers

Difference between @MapKey, @MapKeyColumn and @MapKeyJoinColumn in JPA and Hibernate

As per Hibernate documentation, there are multiple annotations available if we want to use Map as an association between our entities. The doc says: Alternatively the map key is mapped to a dedicated column or columns. In order to customize the…
Chaitanya
  • 15,403
  • 35
  • 96
  • 137
28
votes
7 answers

Hibernate throws strange error: Class is not mapped

this is the error org.hibernate.hql.ast.QuerySyntaxException: Payment is not mapped [select p from Payment p] I don't understand how come this error is thrown, the class should be mapped as I will show you briefly. I have a very basic config, like…
user1100478
  • 291
  • 1
  • 3
  • 4
28
votes
3 answers

Hibernate annotation or XML configuration

I have started a new project with Hibernate. Is Hibernate annotation a better choice or is Hibernate XML mapping better? I have used Hibernate with XML configuration, but I have no idea about annotation. are there any issues while going for…
TechFind
  • 3,696
  • 18
  • 47
  • 62
27
votes
3 answers

How to do multiple column UniqueConstraint in hbm?

Working on some legacy hibernate code. How do I do the following with hbm.xml(hibernate mapping file) instead of with annotations? @Table(name="users", uniqueConstraints = { @UniqueConstraint(columnNames={"username", "client"}), …
27
votes
1 answer

How to create hibernate composite key using annotations

I am trying to use hibernate annotations to insert data to a MySQL database table which doesn't have a primary key defined. However the fact is 2 fields of that table together are unique in the table.how can i achieve the same using hibernate…
edaklij
  • 4,121
  • 11
  • 31
  • 43
24
votes
1 answer

Hibernate CriteriaBuilder to join multiple tables

I'm trying to join 4 tables using hibernate criteriabuilder.. Below are the tables respectively.. ` @Entity public class BuildDetails { @Id private long id; @Column private String buildNumber; @Column private String…
ktgirish
  • 257
  • 1
  • 2
  • 12
24
votes
5 answers

JPA clear collection and add new items

I have a @OneToMany collection (list) that I would like to clear, and add new elements to in the same transaction. Using collection.clear(); collection.add(new EntityB()); Simply adds the new instance, and never removes anything. I have…
Dennis Thrysøe
  • 1,791
  • 4
  • 19
  • 31
24
votes
14 answers

Hibernate is not auto-creating a table that does not exist in the DB

I have a basic Hibernate code, I have set the property "hibernate.hbm2ddl.auto" as update still it is not auto-creating the table in the Database. These are the required files: employee.hbm.xml
Nick Div
  • 5,338
  • 12
  • 65
  • 127