Questions tagged [hibernate]

Hibernate is an object-relational mapping (ORM) library for the Java language enabling developers to utilize POJO-style domain models in their applications in ways extending well beyond Object/Relational Mapping.

Hibernate is the umbrella for a collection of , most notably Hibernate ORM which provides Object/Relational Mapping for domain objects.
In addition to its own "native" API, Hibernate ORM is also an implementation of the Java Persistence API () specification.

Related tags

Beginner's resources

Frequently asked questions

People often ask the following questions:

94278 questions
18
votes
2 answers

How do I dynamically resolve message parameters with Hibernate Validator?

I'm using Hibernate Validator and would like to resolve the category's name in an error message. Consider this simple scenario: public class Category { private String name; } public class Product { @HazardousCategoryConstraint(message =…
Loc Nguyen
  • 9,471
  • 5
  • 22
  • 27
18
votes
2 answers

Why doesn't Grails notify me of error at domain object saving?

I'm just starting with Grails, and here is the first issue. I spent several hours to find out that domain object cannot be inserted in DB, until all its properties are populated. class Item { String title String link } class ItemController { …
mkuzmin
  • 775
  • 2
  • 7
  • 13
18
votes
2 answers

JPA 2: multiple column usage in foreign keys

I am using Hibernate as persistence provider and modelling my entities with JPA 2. Now a question came up and i hope you can help me. In my application you can open up a Game, create groups of players in it and walk around on the map (tiles (2d)).…
mkuff
  • 1,620
  • 6
  • 27
  • 39
18
votes
7 answers

hibernate unique key validation

I have a field, say, user_name, that should be unique in a table. What is the best way for validating it using Spring/Hibernate validation?
nidhin
  • 6,661
  • 6
  • 32
  • 50
18
votes
2 answers

Is "update without select" possible with Hibernate/JPA?

So with JPA/Hibernate you can certainly load an entity "proxy" without hitting the database using something like session.load() or entityManager.getReference(). However, it seems it's impossible to set a property on these "proxies" without Hibernate…
rogiller
  • 895
  • 1
  • 9
  • 22
18
votes
1 answer

How to implement triggers in hibernate

I want to implement something similar to triggers in hibernate. What I need is when a column in a table attains a specific value, a row should be inserted in another table or some other table should be updated. How do I implement this in hibernate…
Juzer Arsiwala
  • 601
  • 2
  • 10
  • 20
18
votes
1 answer

Formula mappings are currently not supported - Hibernate ORM Envers

I use Hibernate Envers: @Entity @Table(name = "user") @Audited class User() { private String id; @Formula("(SELECT name FROM other c where c.id = id)") private Integer name; } it…
Kamil Nękanowicz
  • 6,254
  • 7
  • 34
  • 51
18
votes
4 answers

Accessing Hibernate Session from EJB using EntityManager

Is it possible to obtain the Hibernate Session object from the EntityManager? I want to access some hibernate specific API... I already tried something like: org.hibernate.Session hSession = ( (EntityManagerImpl) em.getDelegate()…
Bogdan
  • 5,368
  • 9
  • 43
  • 62
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
5 answers

JPA CriteriaQuery implements Spring Data Pageable.getSort()

I used JPA CriteriaQuery to build my dynamic Query and pass in a Spring Data Pageable object: sort=name,desc At the backend I have a method in my Repository to support dynamic query: public Page findByCriteria(String username, Pageable page)…
Javatar
  • 623
  • 3
  • 8
  • 20
18
votes
3 answers

What are the Maven dependencies to use hibernate, hibernate annotations, and ehcache?

I would like to update my Maven pom.xml with the latest hibernate, hibernate-annotations, and ehcache dependencies. I read the hibernate download page and the ehcache donwload page. All my tries at interpreting it seem to fail. Can someone write out…
Thomas
  • 435
  • 1
  • 5
  • 12
18
votes
4 answers

JPA and PostgreSQL with GenerationType.IDENTITY

I have a question about Postgres and GenerationType.Identity vs Sequence In this example... @Id @SequenceGenerator(name="mytable_id_seq", sequenceName="mytable_id_seq", allocationSize=1) @GeneratedValue(strategy…
Mike
  • 763
  • 2
  • 12
  • 25
18
votes
2 answers

How can I do paging with @OneToMany collections

Suppose I have a Post entity and a Comment entity and a one to many relationship: @Entity class Post { ... @OneToMany List comments; ... } How can I achieve paging like this: Post post = //Find the post. return…
Visus Zhao
  • 1,144
  • 2
  • 12
  • 25
18
votes
2 answers

How to change to case of a column to Upper in HQL Hibernate

I want to change a column from a table to uppercase before using like and filtering what is the keyword in HQL? here's my query SELECT abc FROM ABC abc WHERE abc.id = ? And upper(abc.description) like '%?%' Thanks
Gauls
  • 1,955
  • 6
  • 28
  • 44
18
votes
2 answers

Failed to convert request element in entity with @IdClass

I have the following setup: @Entity @IdClass(MemberAttributePk.class) public class MemberAttribute { @Id @ManyToOne @JoinColumn(name="member_id") protected Member member; @Id protected String name; private String value; …
Ionut
  • 2,788
  • 6
  • 29
  • 46