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

Hibernate @OrderBy for nested properties

I need to use @OrderBy (JPA, Hibernate as provider) to sort collection for nested property: @OneToMany(mappedBy = "paramSpec", cascade = CascadeType.ALL) @OrderBy("release.ordinal") private List pkdbParams; In…
Piotr Sobczyk
  • 6,443
  • 7
  • 47
  • 70
12
votes
3 answers

Overriding @Id defined in a @MappedSuperclass with JPA

I have a class AbstractEntity that is extended by all the entities in my application and basically acts as an Identifier provider. @MappedSuperclass public class AbstractEntity implements DomainEntity { private static final long…
Sushant
  • 173
  • 1
  • 4
  • 15
12
votes
2 answers

How do I map entity association using a query instead of a @JoinColumn with JPA?

I’m using Hibernate 4.1.3.Final with JPA 2.1 and MySQL 5.5.37. I have an entity with the following field: @Entity @Table(name = "category", uniqueConstraints = { @UniqueConstraint(columnNames = { "NAME" })} ) public class Category implements…
Dave A
  • 2,780
  • 9
  • 41
  • 60
12
votes
1 answer

How to exclude an entity field when doing an update with JPA

Is there a way to make a field non-persistent at update operation but persistent at create operation with JPA - Hibernate 4? I tried it in this way @Transient @Id @Column(name = "USER_NAME", nullable = false, length = 75) private String…
aurelius
  • 3,946
  • 7
  • 40
  • 73
12
votes
2 answers

Hibernate many to many - fetch method eager vs lazy

New to Hibernate. I have User Group many to many relation. Three tables : User , Group and UserGroup mapping table. Entities: @Entity @Table(name = "user") public class User { @Id @Column (name = "username") private String userName; @Column (name…
john Smith
  • 1,565
  • 7
  • 34
  • 54
12
votes
4 answers

How to avoid creating a new row if similar row exists?

I need to configure hibernate to avoid creating duplicate rows, (although the row exists it creates a new one, and since only one filed is set it set all the rest to NULL) Lets say I have a row as following id des index age 1 MyName 2 …
user2071377
12
votes
2 answers

native generator class in hibernate

I have this part of hibernate mapping xml file, and I was looking for a good example for what does native mean.
Rimchik
  • 145
  • 1
  • 3
  • 8
11
votes
3 answers

mapping multiple sets in one table in hibernate

I've got a User an a Log class (which I cannot change): class User { private long id; private String name; private Set accessLogs; private Set actionLogs; } class Log { private String what; private Date when; } A…
cherouvim
  • 31,725
  • 15
  • 104
  • 153
11
votes
4 answers

How to define Friendship relationship using Hibernate?

I need to have "FriendRequest" and "ListOfFriends" functionalities.Similar to facebook, which shows number of received friend requests and number of approved friends. By "FriendRequest", I mean to have a list of friend requests that the user…
Daniel Newtown
  • 2,873
  • 8
  • 30
  • 64
11
votes
2 answers

Can hibernate scan packages to create SessionFactory automatically?

Can I configure Hibernate to scan packages automatically to create a SessionFactory from @Entity annotated beans ? Currently I am using Configuration config = new Configuration() ; config.addAnnotatedClass(MyEntity.class); I do not want to use…
Gautam
  • 1,030
  • 13
  • 37
11
votes
3 answers

Hibernate Many to one Mapping with different Number of columns

Hi I have 2 tables as below Table1: +-------------------+ | ID LOB col1 col2 | +-------------------+ Primary Key (ID and LOB) Table2: +-----------------+ | SK ID col3 col4 | +-----------------+ Primary Key (SK) I…
Siva
  • 1,938
  • 1
  • 17
  • 36
11
votes
3 answers

How to specify a Primary Key on @ElementCollection

So, there is that behavior with innodb that can cause problem if some tables lack of primary key. So with Hibernate, I am looking for a key to specifies a primary key on a @ElementCollection table with a Set as the underling data structure. I found…
plcstpierre
  • 171
  • 1
  • 2
  • 11
11
votes
1 answer

Hibernate mapping exception - Could not determine type for:

Im trying to configure my entities but hibernate throws the following exception: org.hibernate.MappingException: Could not determine type for: com.sd.entity.SDUserProductAcess, at table: SDUser, for columns:…
Fabio K
  • 1,297
  • 4
  • 13
  • 24
11
votes
4 answers

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

I have the tables as in the screenshot above Class are written as below @Entity public class Object { @Id private int id; private String name; @OneToMany(mappedBy="object",fetch=FetchType.LAZY) private…
chiranjeevigk
  • 1,636
  • 1
  • 23
  • 43
11
votes
3 answers

Native SQL throwing Invalid Column Name Exception

I am using Hibernate 3.2.5 for my application. I have a Dept table and an Employees table. Dept.java private int deptId; private String deptName; private Map empMap = new HashMap(); //Getters and Setters Employees.java private int empId; private…
user182944
  • 7,897
  • 33
  • 108
  • 174