Questions tagged [hibernate-annotations]

Hibernate Annotations provide an alternative method of supplying metadata which maps Java objects to the database tables they represent.

Hibernate Annotations support the JPA specification (JSR-317) but provide more extensive functionality which is not covered by the specification. These annotations are used in conjunction with core Hibernate and hibernate entity manager and require Java 5 or above.

510 questions
253
votes
4 answers

Confusion: @NotNull vs. @Column(nullable = false) with JPA and Hibernate

When they appear on a field/getter of an @Entity, what is the difference between them? (I persist the Entity through Hibernate). What framework and/or specification each one of them belongs to? @NotNull is located within…
rapt
  • 10,528
  • 29
  • 92
  • 134
229
votes
10 answers

Hibernate throws org.hibernate.AnnotationException: No identifier specified for entity: com..domain.idea.MAE_MFEView

Why am I getting this exception? package com.domain.idea; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import…
Ramy
  • 17,760
  • 36
  • 94
  • 141
113
votes
4 answers

@UniqueConstraint and @Column(unique = true) in hibernate annotation

What is difference between @UniqueConstraint and @Column(unique = true)? For example: @Table( name = "product_serial_group_mask", uniqueConstraints = {@UniqueConstraint(columnNames = {"mask", "group"})} ) And @Column(unique =…
navid_gh
  • 1,595
  • 3
  • 13
  • 27
97
votes
3 answers

mappedBy reference an unknown target entity property

I am having an issue in setting up a one to many relationship in my annotated object. I have the following: @MappedSuperclass public abstract class MappedModel { @Id @GeneratedValue(strategy=GenerationType.AUTO) …
boyd4715
  • 2,563
  • 7
  • 46
  • 75
87
votes
5 answers

can someone please explain me @MapsId in hibernate?

Can someone please explain to me @MapsId in hibernate? I'm having a hard time understanding it. It would be great if one could explain it with an example and in what kind of use cases is it most applicable?
brainydexter
  • 17,648
  • 25
  • 70
  • 108
80
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
  • 8,822
  • 9
  • 43
  • 68
52
votes
3 answers

Hibernate recursive many-to-many association with the same entity

Another Hibernate question... :P Using Hibernate's Annotations framework, I have a User entity. Each User can have a collection of friends: a Collection of other Users. However, I have not been able to figure out how to create a Many-to-Many…
Magsol
  • 4,480
  • 11
  • 40
  • 65
46
votes
3 answers

Hibernate: Add a property in my class that is not mapped to a db-table

I have a table tbl_sky that has 2 properties name and model and I would use Hibernate annotation like; @Entity @Table(name="tbl_sky") public class Sky implements Serializable { private String name; private String model; private String…
Adnan
  • 23,948
  • 17
  • 75
  • 108
42
votes
6 answers

Hibernate Mapping Package

I'm using Hibernate Annotations. In all my model classes I annotate like this: @Entity @Table public class SomeModelClass { // } My hibernate.cfg.xml is
Daniel Moura
  • 7,472
  • 5
  • 33
  • 60
35
votes
9 answers

Hibernate/persistence without @Id

I have a database view that yields a result set that has no true primary key. I want to use Hibernate/Persistence to map this result set onto Java objects. Of course, because there is no PK, I cannot decorate any field with @Id. When deploying,…
Miguel
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.…
30
votes
3 answers

The annotation @Index is disallowed for this location

When trying to use the @Index annotation from javax.persistence, Eclipse gives me this error. I'm using it right before a java.util.Date field, inside a class annotated with @Entity. Before, I was using org.hibernate.annotations.Index in the exact…
Vituel
  • 4,708
  • 5
  • 37
  • 52
27
votes
5 answers

Hibernate: OneToMany save children by cascade

In the class Parent there is a list List. When the parent is saved the children which have been added or changed shall be save / updated by hibernate. I've found many explanations on this, however, I just don't get it to work. Parent.class try…
Steve Eastwood
  • 1,643
  • 3
  • 15
  • 21
27
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,618
  • 17
  • 43
  • 61
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
  • 3,751
  • 11
  • 29
  • 43
1
2 3
33 34